Working with AIPatrol and AIGuard.
by Logan Strunk · in Torque Game Engine · 12/18/2006 (10:54 am) · 5 replies
I need to make my AIPatrol guys use swords. I have a sword.cs file, and my AIGuard guys use it just fine.
This is in my AIPatrol file:
function AIPatrol::EquipBot(%this, %obj)
{
%obj.incinventory("sword",1);
%obj.mountImage("sword",0);
%obj.setInventory("swordammo",1000);
}
The AIGuard is setup slightly differently because they it uses variables declared at the top of the file to get its information throughout the script, but this is also how I have it in the player.cs and it works fine. Any clue why my AIPatrol guys don't spawn with swords just empty hands?
The one other thing I was hoping someone could help me get started on my next project. I want to make the AIPatrol deter from their patrol if they see someone.
Just for reference, here is my AIPatrol file, just so we are all on the same page:
http://rafb.net/paste/results/yHgJD361.html
Basically, in the GetClosestHumaninsightandrange function, I think what I want to do is, IF it see's someone, make their location the location of the next node that the followpath function uses, bump the old one to a stack, and then when either the human is gone or dead, pop the stack and return to traveling to the old node. I also want to randomize the node travel, so that he's not always going in a loop, but rather just kind of wanders between nodes aimlessly.
Could someone start me on the right track to doing this?
This is in my AIPatrol file:
function AIPatrol::EquipBot(%this, %obj)
{
%obj.incinventory("sword",1);
%obj.mountImage("sword",0);
%obj.setInventory("swordammo",1000);
}
The AIGuard is setup slightly differently because they it uses variables declared at the top of the file to get its information throughout the script, but this is also how I have it in the player.cs and it works fine. Any clue why my AIPatrol guys don't spawn with swords just empty hands?
The one other thing I was hoping someone could help me get started on my next project. I want to make the AIPatrol deter from their patrol if they see someone.
Just for reference, here is my AIPatrol file, just so we are all on the same page:
http://rafb.net/paste/results/yHgJD361.html
Basically, in the GetClosestHumaninsightandrange function, I think what I want to do is, IF it see's someone, make their location the location of the next node that the followpath function uses, bump the old one to a stack, and then when either the human is gone or dead, pop the stack and return to traveling to the old node. I also want to randomize the node travel, so that he's not always going in a loop, but rather just kind of wanders between nodes aimlessly.
Could someone start me on the right track to doing this?
#2
12/18/2006 (12:15 pm)
You sir are a god. Thank you.
#3
12/18/2006 (12:17 pm)
You are very welcome.
#4
function AIPatrol::GetClosestHumanInSightandRange(%this, %obj)
{
%dist=0;
%index = -1;
%botpos = %this.getposition();
%count = ClientGroup.getCount();
for(%i=0; %i < %count; %i++)
{
%client = ClientGroup.getobject(%i);
if (%client.player !$= "" || %client.player >0)
{
%tgt = %client;
%playpos = %client.player.getposition();
%tempdist = vectorDist(%playpos, %botpos);
//Is target in range? If not bail out of checking to see if its in view.
if (%tempdist <= $AI_PATROL_DETECT_DISTANCE)
{
//Lower attentionlevel to increase response time...
%this.attentionlevel--;
if(%this.attentionlevel < 1) %this.attentionlevel=1;
//Is the target within the fov field of vision of the bot?
if(%this.Istargetinview(%obj, %tgt, %obj.fov))
{
//This change by LS to make the bots follow you!
%this.setMoveDestination(%playpos);
//Lower attentionlevel to increase response time...
%this.attentionlevel--;
if(%this.attentionlevel < 1) %this.attentionlevel=1;
if(%this.CheckLOS(%obj, %tgt))
{
%this.attentionlevel--;
if(%this.attentionlevel < 1) %this.attentionlevel=1;
if(%tempdist < %dist || %dist== 0)
{
%dist = %tempdist;
%index = %i;
}
}
}
}
}
else
{
%this.attentionlevel = %this.attentionlevel + 0.5;
if(%this.attentionlevel > $AI_PATROL_MAX_ATTENTION) %this.attentionlevel=$AI_PATROL_MAX_ATTENTION;
}
}
return %index;
}
12/18/2006 (3:23 pm)
Ok, I figured out how to make the aiPatrols follow you if they see you.function AIPatrol::GetClosestHumanInSightandRange(%this, %obj)
{
%dist=0;
%index = -1;
%botpos = %this.getposition();
%count = ClientGroup.getCount();
for(%i=0; %i < %count; %i++)
{
%client = ClientGroup.getobject(%i);
if (%client.player !$= "" || %client.player >0)
{
%tgt = %client;
%playpos = %client.player.getposition();
%tempdist = vectorDist(%playpos, %botpos);
//Is target in range? If not bail out of checking to see if its in view.
if (%tempdist <= $AI_PATROL_DETECT_DISTANCE)
{
//Lower attentionlevel to increase response time...
%this.attentionlevel--;
if(%this.attentionlevel < 1) %this.attentionlevel=1;
//Is the target within the fov field of vision of the bot?
if(%this.Istargetinview(%obj, %tgt, %obj.fov))
{
//This change by LS to make the bots follow you!
%this.setMoveDestination(%playpos);
//Lower attentionlevel to increase response time...
%this.attentionlevel--;
if(%this.attentionlevel < 1) %this.attentionlevel=1;
if(%this.CheckLOS(%obj, %tgt))
{
%this.attentionlevel--;
if(%this.attentionlevel < 1) %this.attentionlevel=1;
if(%tempdist < %dist || %dist== 0)
{
%dist = %tempdist;
%index = %i;
}
}
}
}
}
else
{
%this.attentionlevel = %this.attentionlevel + 0.5;
if(%this.attentionlevel > $AI_PATROL_MAX_ATTENTION) %this.attentionlevel=$AI_PATROL_MAX_ATTENTION;
}
}
return %index;
}
#5
12/18/2006 (4:28 pm)
Thanks for update. I see you are becoming a god.
Torque Owner Fucifer
%obj.mountImage("sword",0);it should be
%obj.mountImage("swordImage",0);I am assuming your dts path and weapon cs file is correct.