Skip to content

Instantly share code, notes, and snippets.

@Azaezel
Created February 11, 2019 00:34
Show Gist options
  • Save Azaezel/a8c9c4464e6faae2b5b810c6efaf090c to your computer and use it in GitHub Desktop.
Save Azaezel/a8c9c4464e6faae2b5b810c6efaf090c to your computer and use it in GitHub Desktop.
aiplayerspawning
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