Created
February 11, 2019 00:34
-
-
Save Azaezel/a8c9c4464e6faae2b5b810c6efaf090c to your computer and use it in GitHub Desktop.
aiplayerspawning
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function AIPlayer::customAiSpawn(%spawnPos, %datablock) | |
{ | |
if (!isObject(%datablock)) %datablock = DemoPlayer; | |
// Create the demo player object | |
%player = new AiPlayer() | |
{ ... | |
//pause a moment to let behind the scene stuff work out | |
%player.schedule(1000, "aiStartUp"); | |
... | |
} | |
function AIPlayer::aiStartUp(%this) | |
{ | |
if(!isObject(%this)||(%this.getState() $="Dead")) return; | |
//here the Ai is going to decide what to do when it spawns | |
//tool up with some bullets | |
%this.setInventory("aiAmmo", 65535); | |
%this.setInventory("aiAmmoClip", 65535); | |
%this.manager = $SAI; | |
%this.manager.addBot(%this); | |
%this.enemy = -1; | |
%this.canfire = true; | |
%this.randomPath(); | |
} | |
function AIPlayer::randomPath(%this) | |
{ | |
if(!isObject(%this)||(%this.getState() $="Dead")) return; | |
%this.currentNode = 0; | |
%this.targetNode = 0; | |
%start = %this.getPosition(); | |
//get a random goal, count available up | |
%count = %this.manager.targetList.count(); | |
%index = getRandom(0, %count-1); | |
%enemy = %this.manager.targetList.getKey(%index); | |
%this.stop(); | |
%this.enemy = %enemy; | |
%this.followObject(%this.enemy, %this.repathTolerance); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment