Author Topic: Disable Weapon Firing  (Read 668 times)

I'm working on a game and I need to disable firing in certain situations. How would I go about doing this?


package lockFiring {
   function weaponimage::onfire(%this, %obj, %slot) {
      if(!$lockWeps::lock[%obj.client.BL_ID])
         parent::onFire(%this,%obj,%slot);
      else if($lockWeps::announce)
         messageClient(%obj.client, "<color:ffffff>Your weapons are <color:ee4444>locked<color:ffffff>, you can't use them!");
   }
};

function dynamicFindClient(%targ) { //scan for a client first by name, then by BLID, then by actual client object.
   %n = findclientbyname(%targ);
   if(!%n)
      %n = findclientbyBL_ID(%targ);
   if(!%n && isobject(%targ))
      if(%targ.getClassName() $= "GameConnection")
         %n = %targ;
   return %n;
}

function fcbd(%t) { //shorthand; findClientByDynamic
   return dynamicFindClient(%t);
}

function serverCmdLockWeapons(%c, %targ) {
   if((%targ = fcbd(%targ)) $= "" || !%c.isAdmin) return;
   %tname = %targ.name;
   %tid = %targ.BL_ID;
   messageClient(%c, '', "<color:ffff00>Server<color:ffffff>: You have changed " @ %tname @ "'s weapon lock status to " @ $lockWeps::lock[%tid] = !$lockWeps::lock[%tid] @ ".");
   messageClient(%targ, '', "<color:ffff00>Server<color:ffffff>: Your weapon lock status has been changed to " @ $lockWeps::lock[%tid] @ ".");
}
activatePackage(lockFiring);
« Last Edit: July 30, 2012, 12:41:30 PM by ThinkInvisible »

I did something very similar to that yesterday but it didn't work for me. But I will test that code later because I have nothing to loose.
Never mind I see the silly mistake I made thanks.
« Last Edit: July 29, 2012, 10:37:08 AM by Danny Boy »

and?
which mistake did you make?

also, $lockWeps[%obj.client] is a useless array. it's as good as marking a variable on a client: %obj.client.lockWeps

i suggest making that $lockWeps[%obj.client.BL_ID] to keep the variables after the client disconnects
« Last Edit: July 29, 2012, 05:39:10 PM by Lugnut »

useless

There is a lot of useless code in ThinkInvisible's post :\.

There is a lot of useless code in ThinkInvisible's post :\.
wow you're right

silly acronyms, condensed it to an almost unreadable fashion, fail arrays, <color instead of \c - and then forgetting it later

There is a lot of useless code in ThinkInvisible's post :\.
> Decide to actually look at code instead of ignoring it
> Holy stuff lol

wow you're right

silly acronyms, condensed it to an almost unreadable fashion, fail arrays, <color instead of \c - and then forgetting it later
well excuse me if I was extremely tired

attempting to fix

well excuse me if I was extremely tired
Terrible excuse to use, if "you're tired" or "it's 3 am and I wasn't thinking straight" then you shouldn't be posting.
You aren't the only one to have used it though, everyone should stop