Author Topic: Admin only...  (Read 1211 times)

Im trying to make a Bulldozer vehicle that spawns a kill brick projectile but Im having trouble with the admin only part. I think Im putting the return; in the wrong place. Can anyone help? thanks


Code: [Select]
package ShootOnClicks_Pack
{
function armor::onTrigger(%db,%obj,%slot,%val)
{
%mount = %obj.getObjectMount();
if(isObject(%mount))
{

if(%slot==0)
{   
 
if(%mount.getDataBlock() == Bulldozervehicle.getId())
{
%client = %obj.client;
if(%client.isAdmin == 1 || %client.isSuperAdmin == 1)
{
if(%val)
{
if($Sim::Time<%obj.client.SOC_LastFireTime)
{
return;
}
}
%obj.SOC_Shoot(%slot,%val);

}
else
    {
centerprint(%client,"You need to be an admin to clear bricks.","1","3");
//return;
}
//return;
}
}
 
}
return Parent::onTrigger(%db,%obj,%slot,%val);
}
};
ActivatePackage(ShootOnClicks_Pack);

Just take out return, everything looks fine for the most part.

Code: [Select]
return Parent::onTrigger(%db,%obj,%slot,%val);
Shouldn't that just be this?

Code: [Select]
Parent::onTrigger(%db,%obj,%slot,%val);

Code: [Select]
return Parent::onTrigger(%db,%obj,%slot,%val);
Shouldn't that just be this?

Code: [Select]
Parent::onTrigger(%db,%obj,%slot,%val);
Doesn't really matter.
But the one without return breaks the return value of the specific function.

Doesn't really matter.
But the one without return breaks the return value of the specific function.

So what does the parent of it, being onTrigger, return?

So what does the parent of it, being onTrigger, return?

Torque FPS Example code:
Code: [Select]
function Armor::onTrigger(%this, %obj, %triggerNum, %val)
{
   // This method is invoked when the player receives a trigger
   // move event.  The player automatically triggers slot 0 and
   // slot one off of triggers # 0 & 1.  Trigger # 2 is also used
   // as the jump key.
}

Unless Badspot has edited it, absolutely nothing.

Also, I posted an answer on your identical topic on the RTB forums.

full script

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

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

package ShootOnClicks_Pack
{
   function armor::onTrigger(%db, %obj, %slot, %val)
   {
      %mount = %obj.getObjectMount();
      if(isObject(%mount))
      {
         if(%slot == 0)
            {
            if(%mount.getDataBlock() == Bulldozervehicle.getId())
            {
               %client = %obj.client;
               if(%client.isAdmin == 1 || %client.isSuperAdmin == 1)
               {
                  if(%val)
                  {
                     if($Sim::Time > %obj.client.SOC_LastFireTime + 5000) // Replace 5,000 with the desired wait time in MS.
                     {
                        %obj.SOC_Shoot(%slot,%val);
                     }
                  }
               }
               else
               {
                  centerprint(%client,"You need to be an admin to clear bricks.","1","3");
               }
            }         
         }
      }
      Parent::onTrigger(%db,%obj,%slot,%val);
   }
};
activatePackage(ShootOnClicks_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();
         %client = %obj.client;
%mountObj= %mnt.getMountNodeObject(%data.shootOnClick_RequiredSlot);
if(%mountObj!$=%Obj)
{
return;
}

if(%data.shootOnClick() && %client.isAdmin == 1 || %client.isSuperAdmin == 1)
{
//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);
}

//If hold, schedule.
if(%data.ShootOnClick_Hold() && %client.isAdmin == 1 || %client.isSuperAdmin == 1)
{
//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;
}
}

Code: [Select]
%client = %obj.client;
               if(%client.isAdmin == 1 || %client.isSuperAdmin == 1)
Did you see that?

Quote from: Space Guy (RTB Forum)
Code: [Select]
if(%data.shootOnClick() && %client.isAdmin == 1 || %client.isSuperAdmin == 1)
That will break NiXiLL's code and any other vehicles that attempt to use the script.

What I want is a code that makes a job on city RP a admin only job so only admins can sign up for the job... PM me if anyone knows how!


shoo!
QFT

Sorry, I don't know. Look at Spaceguy's on the RTB forums i guess...