Author Topic: Problems with creating a bot  (Read 724 times)

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?!

Code: [Select]
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.

Quote from: console
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.
« Last Edit: February 16, 2010, 09:40:00 AM by lordician »

Never mind, i found out i hadn't enabled the add-on with the model it needs.


I am trying to spawn an AIPlayer, but it doesn't work, neither does it give me conosle errors.
What to do?
function serverCmdSentryHere(%client)
{
   %pos = %client.player.gettransform()
   addSentry(%pos, %player);
}

function addSentry(%pos, %creator)
{
   %sentry = new AIPlayer()
   {
      datablock = TurretArmor;
      position = %pos;
   };
   missionCleanup.add(%sentry);
}
point of that is?

You still have errors in your code.
Your calling the addSentry function with the arguments %pos and %player while %player hasn't even been defined. It doesn't really matter since you're not using the variable in the actual function, but if you are in the future...

point of that is?
Hehe, further code is not posted yet, but i need it.
You still have errors in your code.
Your calling the addSentry function with the arguments %pos and %player while %player hasn't even been defined. It doesn't really matter since you're not using the variable in the actual function, but if you are in the future...
Hmm, you are right.
How silly of me.
Explains why the rest doesn't work.

I must haveve deleted the line. D:
lock pl0x
I am glad it isn't locked, and i can always recycle this topic to ask a new question.

Posted a fixed version, testing it now, hopefully, it fixes everything. :)

I now have melting brains as i seem to have found a bug i have every time if i work on something with bots.
But i can't find the solution.

Help please. :(
« Last Edit: February 16, 2010, 09:41:30 AM by lordician »

Quote from: MSN Chat
this day needs moar responds on my topic in coding help
I came


"Yo, a little help here?"