I am trying to spawn an AIPlayer, but it doesn't work, neither does it give me conosle errors.
What to do?Needed add-on for model not enabled. D:
NEWNEW Stuff.
I seem to have melting brains.
I always seem to crash on the same damn problem, but i can't seem to get a solution for it.
So i would like to know:
What am i doing wrong?!
function serverCmdSentryHere(%client)
{
%pos = %client.player.gettransform();
addSentry(%pos, %client.player, %client);
}
function addSentry(%pos, %creator, %client)
{
%sentry = new AIPlayer()
{
datablock = TurretArmor;
position = %pos;
};
missionCleanup.add(%sentry);
%sentry.setnodeColor("ALL", "1 1 1 1");
%sentry.mountimage(MCTimage, 0);
%sentry.tdmteam = %creator.tdmteam;
%sentry.minigame = %creator.minigame;
schedule(0,0,targetsearchloop, %sentry, %creator);
}
function targetsearchloop(%sentry, %creator)
{
if(%creator.getstate() $= "Dead")
{
%sentry.kill();
}
else
{
if(%sentry.getstate() !$= "Dead")
{
%targetfound = searchfortargets(%sentry, %creator);
if(%targetfound == 1)
{
%sentry.schedule(200,SentryShoot);
}
if(%targetfound == 0)
{
%sentry.randomsentryaim(%sentry);
%sentry.playaudio(0,errorsound);
}
%sentry.searchsched = schedule(3000,0,targetsearchloop,%sentry, %creator);
}
}
}
function AiPlayer::SentryShoot(%this,%onshot)
{
if(getsimtime() >= %this.lastspecial+3000 && %this.getstate() !$= "Dead")
{
schedule(0,0,BotShootMode,%this);
schedule(500,0,BotShootMode,%this);
schedule(1000,0,BotShootMode,%this);
schedule(1500,0,BotShootMode,%this);
%this.lastspecial = getsimtime();
}
}
function searchfortargets(%sentry, %creator)
{
%searchMasks = $TypeMasks::PlayerObjectType;
%radius = 100;
%pos = %sentry.getPosition();
InitContainerRadiusSearch(%pos, %radius, %searchMasks);
while ((%targetid = containerSearchNext()) != 0 )
{
%id = %targetid.getId();
if(IsInMinigame(%sentry) && IsInSameMinigame(%id,%sentry) && %id != %sentry && %id != %creator)
{
%exc = 0;
if(%id.isCloaked)%exc = 1;
if(%id.getclassname() $= "Player")
{
if(%sentry.tdmTeam == %id.client.tdmTeam)%exc = 1;
}
if(%id.getclassname() $= "AiPlayer")
{
if(%id.isgoodguy)%exc = 1;
if(%sentry.tdmTeam == %id.spawnbrick.getgroup().client.tdmTeam)%exc = 1;
}
if(%exc != 1)
{
if(SentryLOSCheck(%id,%sentry))
{
%sentry.tracktarget(%id);
return 1;
}
}
}
}
}
function AiPlayer::tracktarget(%sentry,%id)
{
%sentry.setaimobject(%id);
}
function AiPlayer::randomsentryaim(%sentry)
{
if(%sentry.getstate() !$= "Dead")
{
%ranpos = vectoradd(%pos,getrandom(-20,20) SPC getrandom(-20,20) SPC getword(%pos,2));
%sentry.setAimLocation(%ranpos);
%sentry.schedule(1000,randomsentryaim);
}
}
Everytime, the code can't seem to fnd the right object it needs.
dd-Ons/Bot_Sentry/Bot_Sentry.cs (25): Unable to find object: '8331' attempting to call function 'getState'
BackTrace: ->targetsearchloop
Add-Ons/Bot_Sentry/Bot_Sentry.cs (31): Unable to find object: '8460' attempting to call function 'getState'
BackTrace: ->targetsearchloop
Add-Ons/Bot_Sentry/Bot_Sentry.cs (65): Unable to find object: '8460' attempting to call function 'getPosition'
BackTrace: ->targetsearchloop->searchfortargets
Add-Ons/Bot_Sentry/Bot_Sentry.cs (40): Unable to find object: '8460' attempting to call function 'randomsentryaim'
BackTrace: ->targetsearchloop
Add-Ons/Bot_Sentry/Bot_Sentry.cs (41): Unable to find object: '8460' attempting to call function 'playAudio'
BackTrace: ->targetsearchloop
Add-Ons/Bot_Sentry/Bot_Sentry.cs (25): Unable to find object: '8331' attempting to call function 'getState'
BackTrace: ->targetsearchloop
Add-Ons/Bot_Sentry/Bot_Sentry.cs (31): Unable to find object: '8460' attempting to call function 'getState'
BackTrace: ->targetsearchloop
Add-Ons/Bot_Sentry/Bot_Sentry.cs (65): Unable to find object: '8460' attempting to call function 'getPosition'
BackTrace: ->targetsearchloop->searchfortargets
Add-Ons/Bot_Sentry/Bot_Sentry.cs (40): Unable to find object: '8460' attempting to call function 'randomsentryaim'
BackTrace: ->targetsearchloop
Add-Ons/Bot_Sentry/Bot_Sentry.cs (41): Unable to find object: '8460' attempting to call function 'playAudio'
BackTrace: ->targetsearchloop
It really frustrates me, as i seem to make this istake/error/whatever everytime in something that includes actions like this.