fowlplay4 |
03-13-2018 04:07 PM |
there's nothing wrong with using a regular timeout.
polling (timeout, scheduleevent) is what's to be avoided if there's an applicable event (onplayerenters, onplayerhit, etc.) that can eliminate the need for a constantly running script.
the code would work exactly the same with a regular timeout!!!! unless u want to make inefficient baddies that tick every <0.05 sec.
PHP Code:
function onPlayerEnters() { setTimer(2 * this.aiPeriod); }
function onTimeout() { if (players.size() <= 0) return; ai_execute();
setTimer(this.aiPeriod); }
function enterState(temp.state) { if (this.("ai_enter_"@ temp.state) != nil) this.("ai_enter_"@ temp.state)(); }
function executeState(temp.state) { if (this.("ai_execute_"@ temp.state) != nil) this.("ai_execute_"@ temp.state)(); }
function exitState(temp.state) { if (this.("ai_exit_"@ temp.state) != nil) this.("ai_exit_"@ temp.state)(); }
function changeState(temp.state) { if (this.currentState == temp.state) return;
this.exitState(this.currentState);
this.previousState = this.currentState; this.currentState = temp.state;
this.enterState(this.currentState);
setTimer(this.aiPeriod); }
function ai_execute() { this.executeState(this.globalState); this.executeState(this.currentState); }
|