Author Topic: Schedules  (Read 679 times)

How would I get a schedule to work? I am making a vehicle play and animation before launching a projectile.
Code: [Select]
package RamonClick_Pack
{
function armor::onTrigger(%db,%obj,%slot,%val)
{
if(%obj.getClassName()$="Player")
{
if(%slot==0)
{
if(%val)
{
if($Sim::Time<%obj.client.ROC_LastFireTime)
{
return;
}
}

%mnt= %obj.getObjectMount();
if(!isObject(%mnt))
{
return;
}
%mnt.playThread(0,Ram);
//Below is the schedule I need help on.
%obj.schedule(1000, "ROC_Shoot(%slot,%val)");
//%obj.ROC_Shoot(%slot,%val);
}
}
return Parent::onTrigger(%db,%obj,%slot,%val);
}
};
ActivatePackage(RamonClick_Pack);
I want the schedule to call this function.
Code: [Select]
function Player::ROC_Shoot(%obj,%slot,%val)It also seems that it plays the animation when I click the mouse, then plays it again when I release it, can this be fixed as well.

Code: [Select]
%obj.schedule(1000, "ROC_Shoot(%slot,%val)");
Code: [Select]
%obj.schedule(1000, 0, %obj.ROC_Shoot, %slot, %val);

Code: [Select]
%obj.schedule(1000, 0, %obj.ROC_Shoot, %slot, %val);

Code: [Select]
%obj.schedule(1000,ROC_Shoot,%slot,%val);

Code: [Select]
$TP::Version=1.1; //Version number, do NOT change this unless you know what you are doing.

if($Support::RamonClick<$Prop::Version) {return;} //Newer version already loaded.
$Support::RamonClick=$TP::Version;

package RamonClick_Pack
{
function armor::onTrigger(%db,%obj,%slot,%val)
{
if(%obj.getClassName()$="Player")
{
if(%slot==0)
{
//if(%val)
//{
if($Sim::Time<%obj.client.ROC_LastFireTime)
{
return;
}
//}

%mnt= %obj.getObjectMount();
if(!isObject(%mnt))
{
return;
}
%mnt.playThread(0,Ram);
%obj.schedule(1000,ROC_Shoot,%slot,%val);
echo("Scehduling...");
//%obj.ROC_Shoot(%slot,%val);
}
}
return Parent::onTrigger(%db,%obj,%slot,%val);
}
};
ActivatePackage(RamonClick_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::ROC_Shoot(%obj,%slot,%val)
{
if(!%val) {cancel(%obj.ROC_reshoot);return;}

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

%data= %mnt.getDatablock();

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

if(%data.RamonClick)
{
//Checks OK, shoot it all.
%cnt=%data.RamonClick_ProjectileCount;
for(%i=0;%i<%cnt;%i++)
{
%pos= %mnt.getPosition();
%PVec= %data.RamonClick_Position[%i];
%VVec= %data.RamonClick_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.RamonClick_Scale[%i];
%p= new Projectile()
{
dataBlock= %data.RamonClick_Projectile[%i];
initialPosition= vectorAdd(%pos,%iPos);
initialVelocity= %iVel;
sourceObject= %obj;
client= %obj.client;
sourceSlot= %slot;
scale= %scale;
};
missionCleanup.add(%p);
echo("Good");

}
serverPlay3d(%data.RamonClick_Sound,%pos);

//If hold, schedule.
if(%data.RamonClick_Hold)
{
//Delay according to datablocks.
%obj.ROC_reshoot= %obj.schedule(%data.RamonClick_ReshootDelay,ROC_Shoot,%slot,%val);
}
%obj.client.ROC_LastFireTime=$Sim::Time+%data.RamonClick_ShootDelay/1000;
}
}
It seems to detect it whenever I raise the mouse. I want it to have a delay before you can click again.

%val is whether the key is being pressed or released. It returns 1 if pressed, 0 if released.

So do I un comment that and it will fix?

Code: [Select]
if(%slot==0)
{
if(%val)
{
if($Sim::Time<%obj.client.ROC_LastFireTime)
{
return Parent::onTrigger(%this,%obj,%slot,%val);
}
}
else
{
return Parent::onTrigger(%this,%obj,%slot,%val);
}
That will only continue with the function if they pressed the key after %client.lastfiretime or whatever you named that variable. Otherwise it will just return the original onTrigger
« Last Edit: March 22, 2010, 10:38:13 PM by lilboarder32 »