Author Topic: Space Bar not recognized?  (Read 1022 times)

Code: [Select]
package ShootonclickC_Pack
{
function armor::onTrigger(%db,%obj,%slot,%val)
{
if(%obj.getClassName()$="Player")
{
if(%slot != 0)
{
if(%val)
{
if($Sim::Time<%obj.client.SOCC_LastFireTime)
{
return;
}
}
%obj.SOCC_Shoot(%slot,%val);
}
}
return Parent::onTrigger(%db,%obj,%slot,%val);
}
};
ActivatePackage(ShootonclickC_Pack);
It works when I press the jet key, but not when I hit space. I also tried this
Code: [Select]
if(%slot $= 2)for the space bar and it does not work, and then I tried
Code: [Select]
if(%slot $= 4)for the jet key and it does work. Here is the whole code. I want it so when I press the space bar, it shoots, instead of pressing the jet key or mouse button.
Code: [Select]
$Support::ShootonclickC=$TP::Version;

package ShootonclickC_Pack
{
function armor::onTrigger(%db,%obj,%slot,%val)
{
if(%obj.getClassName()$="Player")
{
if(%slot != 0)
{
if(%val)
{
if($Sim::Time<%obj.client.SOCC_LastFireTime)
{
return;
}
}
%obj.SOCC_Shoot(%slot,%val);
}
}
return Parent::onTrigger(%db,%obj,%slot,%val);
}
};
ActivatePackage(ShootonclickC_Pack);

function repeatedVectorAddwithScale(%vecs)
{
%vec="0 0 0";
%cnt=getFieldCount(%vecs);
for(%i=0;%i<%cnt;%i++)
{
%fld=getField(%vecs,%i);
%tvec=getWords(%fld,0,3);
%scale=getWord(%fld,3);
%svec=vectorScale(%tvec,%scale);
%vec=vectorAdd(%vec,%svec);
}
return %vec;
}

function SimObject::getLeftVector(%obj)
{
return vectorCross(%obj.getEyeVector(),%obj.getUpVector());
}

function SimObject::getRightVector(%obj)
{
return vectorScale(%obj.getLeftVector(%obj),-1);
}

function Player::SOCC_Shoot(%obj,%slot,%val)
{
if(!%val) {cancel(%obj.SOCC_reshoot);return;}

%mnt= %obj.getObjectMount();
if(!isObject(%mnt))
{
return;
}

%data= %mnt.getDatablock();

%mountObj= %mnt.getMountNodeObject(%data.ShootonclickC_RequiredSlot);
if(%mountObj!$=%Obj) {return;}

if(%data.ShootonclickC)
{
//Checks OK, shoot it all.
%cnt=%data.ShootonclickC_ProjectileCount;
for(%i=0;%i<%cnt;%i++)
{
%pos= %mnt.getPosition();
%PVec= %data.ShootonclickC_Position[%i];
%VVec= %data.ShootonclickC_Velocity[%i];
%iPos= repeatedVectorAddwithScale(
%mnt.getEyeVector() SPC getWord(%PVec,0) TAB
%mnt.getLeftVector() SPC getWord(%PVec,1) TAB
%mnt.getUpVector() SPC getWord(%PVec,2)
);
%iVel= repeatedVectorAddwithScale(
%mnt.getEyeVector() SPC getWord(%VVec,0) TAB
%mnt.getLeftVector() SPC getWord(%VVec,1) TAB
%mnt.getUpVector() SPC getWord(%VVec,2)
);
%scale=%data.ShootonclickC_Scale[%i];
if(%scale$="") {%scale="1 1 1";}
%p= new Projectile()
{
dataBlock= %data.ShootonclickC_Projectile[%i];
initialPosition= vectorAdd(%pos,%iPos);
initialVelocity= %iVel;
sourceObject= %obj;
client= %obj.client;
sourceSlot= %slot;
scale= %scale;
};missionCleanup.add(%p);
}
serverPlay3d(%data.ShootonclickC_Sound,%pos);

//If hold, schedule.
if(%data.ShootonclickC_Hold)
{
//Delay according to datablocks.
%obj.SOCC_reshoot= %obj.schedule(%data.ShootonclickC_ReshootDelay,SOCC_Shoot,%slot,%val);
}
%obj.client.SOCC_LastFireTime=$Sim::Time+%data.ShootonclickC_ShootDelay/1000;
}
}

Try using == instead of $=.