Author Topic: Help needed with modifying shootonclick script.  (Read 373 times)

So, I am using the script from Heedicalking's AA turret and i want to change the projectile spawning point to "eye" instead of the current position variable that just offsets the spawning point from the turret's root.

Code: [Select]
package ShootOnClick_Pack
{
function armor::onTrigger(%db,%obj,%slot,%val)
{
if(%obj.getClassName()$="Player")
{
if(%slot==0)
{
if(%val)
{
if($Sim::Time<%obj.client.SOC_LastFireTime)
{
return;
}
}
%obj.SOC_Shoot(%slot,%val);
}
}
return Parent::onTrigger(%db,%obj,%slot,%val);
}
};
ActivatePackage(ShootOnClick_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::SOC_Shoot(%obj,%slot,%val)
{
if(!%val) {cancel(%obj.SOC_reshoot);return;}

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

%data= %mnt.getDatablock();

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

if(%data.shootOnClick)
{
//Checks OK, shoot it all.
%cnt=%data.shootOnClick_ProjectileCount;
for(%i=0;%i<%cnt;%i++)
{
%pos= %mnt.getPosition();
%PVec= %data.ShootOnClick_Position[%i];
%VVec= %data.ShootOnClick_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.ShootOnClick_Scale[%i];
if(%scale$="") {%scale="1 1 1";}
%p= new Projectile()
{
dataBlock= %data.ShootOnClick_Projectile[%i];
initialPosition= vectorAdd(%pos,%iPos);
initialVelocity= %iVel;
sourceObject= %obj;
client= %obj.client;
sourceSlot= %slot;
scale= %scale;
};missionCleanup.add(%p);
}
serverPlay3d(%data.ShootOnClick_Sound,%pos);

//If hold, schedule.
if(%data.ShootOnClick_Hold)
{
//Delay according to datablocks.
%obj.SOC_reshoot= %obj.schedule(%data.ShootOnClick_ReshootDelay,SOC_Shoot,%slot,%val);
}
%obj.client.SOC_LastFireTime=$Sim::Time+%data.ShootOnClick_ShootDelay/1000;
}
}

What im thinking is that instead of
Code: [Select]
%pos= %mnt.getPosition();there would be something like
Code: [Select]
%pos= %mnt.getEyeVector[or transform]();
But i have no idea how it works so i need some help with this.
« Last Edit: March 09, 2014, 10:59:17 AM by The 1 »