Home » Renegade Discussions » Mod Forum » Turret and GT not shooting
Turret and GT not shooting [message #469012] |
Sun, 10 June 2012 19:58 |
robbyke
Messages: 348 Registered: September 2010 Location: Belgium
Karma: 0
|
Recruit |
|
|
the turret and GT models wont fire
theyll only fire when someone is nearly in it
i thought it was my scripts first but then every defence should have the problem or am i wrong?
header file
class KB_Base_Defence : public ScriptImpClass {
unsigned int id1;
unsigned int id2;
unsigned int id3;
unsigned int objtype;
int CurrentTarget;
bool Firing;
void Created(GameObject *obj);
void Enemy_Seen(GameObject *obj,GameObject *enemy);
bool IsValidEnemy(GameObject* WeaponObj, GameObject* EnemyObj);
void Action_Complete(GameObject *obj,int action_id,ActionCompleteReason complete_reason);
void Timer_Expired(GameObject *obj,int number);
public: void Register_Auto_Save_Variables();
};
cpp file
void KB_Base_Defence::Created(GameObject *obj)
{
Vector3 pos,pos1,pos2,pos3;
GameObject *object;
objtype = Commands->Get_Player_Type(obj);
Commands->Enable_Hibernation(obj,false);
Commands->Innate_Enable(obj);
Commands->Enable_Enemy_Seen(obj,true);
pos = Commands->Get_Position(obj);
CurrentTarget = NULL;
pos1.X = pos.X - 10;
pos1.Y = pos.Y - 10;
pos1.Z = pos.Z + 2;
pos2.X = pos.X + 10;
pos2.Y = pos.Y;
pos2.Z = pos.Z + 2;
pos3.X = pos.X + 10;
pos3.Y = pos.Y - 10;
pos3.Z = pos.Z + 2;
Firing = false;
object = Commands->Create_Object("Invisible_Object",pos1);
if (object)
{
id1 = Commands->Get_ID(object);
}
object = Commands->Create_Object("Invisible_Object",pos2);
if (object)
{
id2 = Commands->Get_ID(object);
}
object = Commands->Create_Object("Invisible_Object",pos3);
if (object)
{
id3 = Commands->Get_ID(object);
}
Commands->Start_Timer(obj,this,10,1);
}
void KB_Base_Defence::Enemy_Seen(GameObject *obj,GameObject *enemy)
{
GameObject *o = Get_Vehicle(enemy);
if (o)
{
enemy = o;
}
ActionParamsStruct params;
Vector3 pos,pos2;
float maxattack;
float attacktimer;
pos = Commands->Get_Position(obj);
pos2 = Commands->Get_Position(enemy);
if (IsValidEnemy(obj,enemy) && !Firing)
{
maxattack = Get_Float_Parameter("MaxAttackDistance");
params.Set_Basic(this,100,2);
if(Get_Int_Parameter("AdjustAim") != 0 && enemy->As_SoldierGameObj())
{
params.Set_Attack(Commands->Get_Position(enemy),maxattack,0.0,true);
}
else
{
params.Set_Attack(enemy,maxattack,0.0,true);
}
params.AttackCheckBlocked = false;
params.AttackForceFire = true;
Commands->Action_Attack(obj,params);
CurrentTarget = Commands->Get_ID(enemy);
attacktimer = Get_Float_Parameter("AttackTimer");
Commands->Start_Timer(obj,this,attacktimer,2);
}
}
bool KB_Base_Defence::IsValidEnemy(GameObject* WeaponObj, GameObject* EnemyObj) {
if (!EnemyObj) return false;
if (Commands->Get_Player_Type(EnemyObj) == Commands->Get_Player_Type(WeaponObj)) return false;
if (Commands->Get_Health(EnemyObj) <= 0) return false;
if (!Commands->Is_Object_Visible(WeaponObj, EnemyObj)) return false;
if (Is_Script_Attached(EnemyObj,"KB_Friendly_Zone_Generated")) return false;
if (EnemyObj->As_VehicleGameObj() && Get_Vehicle_Driver(EnemyObj))
{
if (Is_Script_Attached(Get_Vehicle_Driver(EnemyObj),"KB_Friendly_Zone_Generated")) return false;
}
float minattack = Get_Float_Parameter("MinAttackDistance");
float maxattack = Get_Float_Parameter("MaxAttackDistance");
Vector3 WeaponObjPos = Commands->Get_Position(WeaponObj);
Vector3 WeaponObjPosXY = WeaponObjPos;
WeaponObjPosXY.Z = 0;
Vector3 EnemyObjPos = Commands->Get_Position(EnemyObj);
Vector3 EnemyObjPosXY = EnemyObjPos;
EnemyObjPosXY.Z = 0;
float DistanceXY = Commands->Get_Distance(WeaponObjPosXY, EnemyObjPosXY);
return DistanceXY > minattack && DistanceXY < maxattack;
}
void KB_Base_Defence::Action_Complete(GameObject *obj,int action_id,ActionCompleteReason complete_reason)
{
if (action_id == 2)
{
Commands->Action_Reset(obj,100);
}
}
void KB_Base_Defence::Timer_Expired(GameObject *obj,int number)
{
ActionParamsStruct var;
GameObject *object;
float f;
if(number == 1 && !Firing)
{
f = Commands->Get_Random(0.0f,2.9999f);
switch (__min(int(f),2))
{
case 0:
object = Commands->Find_Object(id1);
if (object)
{
var.Set_Basic(this,70,1);
var.Set_Attack(object,0.0,0.0,true);
Commands->Action_Attack(obj,var);
}
break;
case 1:
object = Commands->Find_Object(id2);
if (object)
{
var.Set_Basic(this,70,1);
var.Set_Attack(object,0.0,0.0,true);
Commands->Action_Attack(obj,var);
}
break;
default:
object = Commands->Find_Object(id3);
if (object)
{
var.Set_Basic(this,70,1);
var.Set_Attack(object,0.0,0.0,true);
Commands->Action_Attack(obj,var);
}
}
Commands->Start_Timer(obj,this,10,1);
}
if(number == 2)
{
if(!IsValidEnemy(obj,Commands->Find_Object(CurrentTarget)))
{
Commands->Action_Reset(obj,100);
Firing = false;
}
}
}
void KB_Base_Defence::Register_Auto_Save_Variables()
{
Auto_Save_Variable(&id1,4,1);
Auto_Save_Variable(&id2,4,2);
Auto_Save_Variable(&id3,4,3);
Auto_Save_Variable(&objtype,4,4);
}
ScriptRegistrant<KB_Base_Defence> KB_Base_Defence_Registrant("KB_Base_Defence","MinAttackDistance=0.0:float,MaxAttackDistance=300.0:float,AttackTimer=10.0:float,AdjustAim=0:int");
this is my defence AI
it targets both vtol and ground
and is power independant
ive made it using several ai scripts from TT
edit : fixed the spoiler things
Owner of kambot TT server
kambot.freeforums.org
[Updated on: Wed, 13 June 2012 15:04] Report message to a moderator
|
|
|
|
Re: Turret and GT not shooting [message #469039 is a reply to message #469012] |
Mon, 11 June 2012 05:49 |
robbyke
Messages: 348 Registered: September 2010 Location: Belgium
Karma: 0
|
Recruit |
|
|
yea it hought that to at first but i already doubled it
and it was set at 100 first
the strange thing is that its only those 2 :s
the agt and obelisk work just fine
even the tailgun does (wich makes it even worse as gt is a tailgun)
Owner of kambot TT server
kambot.freeforums.org
|
|
|
|
Re: Turret and GT not shooting [message #469048 is a reply to message #469012] |
Mon, 11 June 2012 08:39 |
robbyke
Messages: 348 Registered: September 2010 Location: Belgium
Karma: 0
|
Recruit |
|
|
no difference
i tried another script
i tired to use m00_base_Defence and that one worked
but jfw_base_defence didnt :s
edit :
Found it
if (!Commands->Is_Object_Visible(WeaponObj, EnemyObj)) return false;
apparantly turret and gt cant really "see"
EDIT 2 :
my guns wont stop shooting anymore :s
they just keep firing against the wall until the target is totally out of range
WeaponObj->As_SmartGameObj()->Is_Obj_Visible(EnemyObj->As_PhysicalGameObj())
thats the check i use now (it works for the turret and gt)
Owner of kambot TT server
kambot.freeforums.org
[Updated on: Wed, 13 June 2012 09:41] Report message to a moderator
|
|
|
Re: Turret and GT not shooting [message #469244 is a reply to message #469030] |
Wed, 13 June 2012 14:57 |
|
reborn
Messages: 3231 Registered: September 2004 Location: uk - london
Karma: 0
|
General (3 Stars) |
|
|
danpaul88 wrote on Mon, 11 June 2012 03:49 | For reference, dp88_AI_Turret also supports targeting VTOL and ground and is optionally power independent (it also supports target priorities, such that you can instruct it to prefer shooting infantry instead of vehicles if there are any nearby, or to try and finish off badly damaged targets before healthy ones).
For reference;
Anyway, it sounds to me like your sight range might be too small in your LE preset. The sight range variable determines how far away the defence can 'see' enemies and thus shoot at them.
|
Very nice documentation, DP. As a community, we tend to lack proper documentation, good job!
|
|
|
Re: Turret and GT not shooting [message #469267 is a reply to message #469244] |
Thu, 14 June 2012 01:06 |
|
danpaul88
Messages: 5795 Registered: June 2004 Location: England
Karma: 0
|
General (5 Stars) |
|
|
I have found the best way to handle 'stop shooting at stuff you can no longer see' is to record the last time you 'saw' the enemy (via the Enemy_Seen) event and have a timer that fires regularly to check that against the current time. If you have not 'seen' the enemy you are trying to shoot at for more than 2 or 3 seconds you should probably stop shooting at them.
Alternatively if you change;
params.AttackCheckBlocked = false;
to
params.AttackCheckBlocked = true;
I believe you will get an ActionComplete and it will stop firing if it can no longer shoot at the target, but I am not 100% sure what AttackCheckBlocked does so you will have to experiment (this is the sort of thing I would like to document so let me know your results if you do try this)
reborn wrote on Wed, 13 June 2012 22:57 |
Very nice documentation, DP. As a community, we tend to lack proper documentation, good job!
|
I am actually working on documenting all of the TT stuff in that fashion but there's an awful lot of it so it's slow going. Jonwil has done a bit too.
Another example;
[Updated on: Thu, 14 June 2012 01:14] Report message to a moderator
|
|
|
Re: Turret and GT not shooting [message #469270 is a reply to message #469267] |
Thu, 14 June 2012 02:25 |
robbyke
Messages: 348 Registered: September 2010 Location: Belgium
Karma: 0
|
Recruit |
|
|
danpaul88 wrote on Thu, 14 June 2012 10:06 | Alternatively if you change;
params.AttackCheckBlocked = false;
to
params.AttackCheckBlocked = true;
|
i tried that:
my gun would stop shooting BUT it would still follow the target
so it wont give an action complete it just wont fire
as soon as target pops up again it will fire again
however this is what happened in my case could be this is not for all cases
if you want i can try it out to full extend
i think its just that it wont attack if it cant hit a target but it wont lose track of it (you need to do action reset for it)
Owner of kambot TT server
kambot.freeforums.org
[Updated on: Thu, 14 June 2012 02:27] Report message to a moderator
|
|
|
|
Re: Turret and GT not shooting [message #469277 is a reply to message #469012] |
Thu, 14 June 2012 05:20 |
robbyke
Messages: 348 Registered: September 2010 Location: Belgium
Karma: 0
|
Recruit |
|
|
it indeed was ive changed the check
but i used it for continuous fire
else full automatic guns keep pausing there fire
ive now changed that to 10 seconds
and removed the check for a valid target
PS: even with that check if i had check attack blocked and it would do action complete (becuase it cant hit his target) it would reset
so the checkblocked will only stop its fire when he cant hit you
Owner of kambot TT server
kambot.freeforums.org
[Updated on: Thu, 14 June 2012 05:27] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Mon Feb 03 15:03:49 MST 2025
Total time taken to generate the page: 0.01621 seconds
|