I can't make my tank fire using the space bar. Problem solved, but another problem popped up.
See the code, again:
package ShootOnClick_Pack2
{
function armor::onTrigger(%db,%obj,%slot,%val)
{
if(%obj.getClassName()$="AIPlayer")
{
if(%slot==2)
{
if(%val)
{
if($Sim::Time<%obj.SOC_LastFireTime2)
{
return;
}
}
%obj.SOC_Shoot2(%slot,%val);
}
}
return Parent::onTrigger(%db,%obj,%slot,%val);
}
};
EDIT: Problem solved, I can now shoot with space bar. When I press space, I am recognized as an AI Player, and the SOC_Shoot2 function is in the Player so I renamed it to be used on AIPlayer. Ive made some changes, then it worked.
But...
There's one problem: It can't kill vehicles nor damage them. It can kill bricks, but not vehicles.
Here's the AIPlayer code I'm talking about:
function AIPlayer::SOC_Shoot2(%obj,%slot,%val)
{
if(!%val) {cancel(%obj.SOC_reshoot2);return;}
%data= %obj.getDatablock();
%mountObj= %obj.getMountNodeObject(%data.shootOnClick_RequiredSlot2);
//if(%mountObj!$=%Obj) {return;}
if(%data.shootOnClick2)
{
//Checks OK, shoot it all.
%cnt=%data.shootOnClick_ProjectileCount2;
for(%i=0;%i<%cnt;%i++)
{
%pos= %obj.getPosition();
%PVec= %data.ShootOnClick_Position2[%i];
%VVec= %data.ShootOnClick_Velocity2[%i];
%iPos= repeatedVectorAddwithScale(
%obj.getEyeVector() SPC getWord(%PVec,0) TAB
%obj.getLeftVector() SPC getWord(%PVec,1) TAB
%obj.getUpVector() SPC getWord(%PVec,2)
);
%iVel= repeatedVectorAddwithScale(
%obj.getEyeVector() SPC getWord(%VVec,0) TAB
%obj.getLeftVector() SPC getWord(%VVec,1) TAB
%obj.getUpVector() SPC getWord(%VVec,2)
);
%scale=%data.ShootOnClick_Scale2[%i];
if(%scale$="") {%scale="1 1 1";}
%p= new Projectile()
{
dataBlock= %data.ShootOnClick_Projectile2[%i];
initialPosition= vectorAdd(%pos,%iPos);
initialVelocity= %iVel;
sourceObject= %obj;
client= %obj;
sourceSlot= %slot;
scale= %scale;
};missionCleanup.add(%p);
}
serverPlay3d(%data.ShootOnClick_Sound2,%pos);
//If hold, schedule.
if(%data.ShootOnClick_Hold2)
{
//Delay according to datablocks.
%obj.SOC_reshoot2= %obj.schedule(%data.ShootOnClick_ReshootDelay2,SOC_Shoot2,%slot,%val);
}
%obj.SOC_LastFireTime2=$Sim::Time+%data.ShootOnClick_ShootDelay2/1000;
}
}
Take note: %obj is the AIPlayer
Problem Solved.