RandomBattles.attach("Player");
RandomBattles.setEnemies('lumisquirrel', 'ghostThing' /*[...]*/)And from then on have it continue to work no matter what other maps the player moves to.
var RandomBattles = (function() { var player = "", enemies = []; function Attach() { /* ... */ } /* ... */ return { setEnemies: SetEnemies, attach: Attach }})();
{ enter: function() { RandomBattles.setEnemies(/* ... */); }}
CreatePerson("Player", "hero.rss", false); // persistent entity representing player's spriteRandomBattles.initialize();RandomBattles.attach("Player");
RandomBattles.setEnemies( /*...*/ );RandomBattles.setEncounterRate(whatever);
var z = GetNumZones();for (var i = 0; i < z; ++i) { SetZoneScript(i, 'RandomBattles.execute()');}
function Update() { if (GetTileName(GetTileAtPlayer()) == 'battle') { RandomBattles.execute(); }}
function Update() { if (!IsCommandQueueEmpty(player) && GetTileName(GetTileAtPlayer()) == 'battle') { RandomBattles.execute(); }}
Code: (javascript) [Select]function Update() { if (!IsCommandQueueEmpty(player) && GetTileName(GetTileAtPlayer()) == 'battle') { RandomBattles.execute(); }}
Scrambler.prototype.update = function(){ var x = GetPersonX(this.personID); var y = GetPersonY(this.personID); if ((x != this.lastX || y != this.lastY) && IsCommandQueueEmpty(this.personID) && RNG.chance(this.encounterRate)) { var battleID = RNG.fromArray(this.battleIDs); new Scenario() .battle(battleID) .run(true); } this.lastX = GetPersonX(this.personID); this.lastY = GetPersonY(this.personID);};
But wouldn't that check for a battle every single frame as long the PC is standing still?
I tried to implement the movement detection using GetPersonX/Y like this:Code: (javascript) [Select]Scrambler.prototype.update = function(){ var x = GetPersonX(this.personID); var y = GetPersonY(this.personID); if ((x != this.lastX || y != this.lastY) && IsCommandQueueEmpty(this.personID) && RNG.chance(this.encounterRate)) { var battleID = RNG.fromArray(this.battleIDs); new Scenario() .battle(battleID) .run(true); } this.lastX = GetPersonX(this.personID); this.lastY = GetPersonY(this.personID);};...but for some reason, (x != this.lastX || y != this.lastY) is always evaluating to false, even when moving the PC around, so no battle is ever triggered, and I'm hard-pressed to understand why.
Scrambler.prototype.update = function(){ var x = GetPersonX(this.personID); var y = GetPersonY(this.personID); if (x != this.lastX || y != this.lastY) { this.lastX = GetPersonX(this.personID); this.lastY = GetPersonY(this.personID); if (IsCommandQueueEmpty(this.personID) && RNG.chance(this.encounterRate)) { var battleID = RNG.fromArray(this.battleIDs); (new Scenario()).battle(battleID).run(true); } }};
Oh! You want to automatically fill certain zones and triggers with random battle code to cut down on coding.I see it now.Code: (javascript) [Select]var z = GetNumZones();for (var i = 0; i < z; ++i) { SetZoneScript(i, 'RandomBattles.execute()');}