On IOS Servers using timeouts is really bad, so its recommended to avoid them when possible.
Here is just a bare-bone version of something that can be turned into a baddy system. Instead of the traditional timeouts it uses scheduleEvents and is event based with using flags like players.
Both classes attached.
PHP Code:
Example: Level NPC
const INIT_STATE = "float";
const GLOBAL_STATE = "float";
function onCreated() {
this.join("ai_module");
this.join("ai_variables");
this.savelocally = true;
_set("maxhealth", 100);
temp.maxHealth = this._get("maxhealth");
this._set("health", temp.maxHealth);
// this.globalState = GLOBAL_STATE ;
// this.enterState(this.globalState);
changeState(INIT_STATE);
}
function ai_enter_float() {
this.ani = "idle";
this.aiPeriod = 1;
}
function ai_execute_float() {
//logic here move?
this.ani = "move";
}