Home   Help Search Login Register  

Author Topic: Vehicle Protection in Respawn  (Read 2510 times)

0 Members and 1 Guest are viewing this topic.

Offline philabowl1

  • Members
  • *
Vehicle Protection in Respawn
« on: 11 May 2007, 21:59:27 »
Hey, I've searched the forums and there is only one dead thread on this. Does anyone have a script that will either delete an empty vehicle and replace it if it is within a marked zone, or repair that vehicle? I'm looking to prevent base rape in CTF maps. I think I can add a punishment to any script someone comes up with, but if you have a script that does that as well, that would be great.

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Vehicle Protection in Respawn
« Reply #1 on: 18 May 2007, 18:43:11 »
Code is untested but should work.  :whistle:
In the init for each protected vehicle put:
Code: [Select]
nul = this execVM "protect_vehicle.sqf" ; this addEventHandler ["KILLED",{_this execVM "broadcast_noob.sqf"}] ; this addEventHandler ["HIT",{_this execVM "broadcast_noob.sqf"}]
protect_vehicle.sqf
Code: [Select]
if (not local _this) then {exit};
_unit = _this;
_type = typeOf _unit;
_pos = getPos _unit;
_dir = getDir _unit;

while {count crew _unit < 1} do
{       
   if (not alive _unit) then
   {
      _unit removeAllEventHandlers "KILLED";
      _unit removeAllEventHandlers "HIT";
      deleteVehicle _unit;
      _unit = nil;
      _unit = _type createVehicle _pos;
      _unit setPos _pos;
      _unit setDir _dir;
      _unit addEventHandler ["KILLED",{_this execVM "broadcast_noob.sqf"}];
      _unit addEventHandler ["HIT",{_this execVM "broadcast_noob.sqf"}];
      _unit execVM "protect_vehicle.sqf";
      exit;
   }
   else
   {
       if (damage _unit > 0) then
       {
           _unit setDamage 0;
           _unit setVelocity [0,0,0];
           _unit setPos _pos;
           _unit setDir _dir;
        };
   };
   sleep 1.0;
};
_unit removeAllEventHandlers "KILLED";
_unit removeAllEventHandlers "HIT";
exit;


broadcast_noob.sqf
Code: [Select]
noob_killer = _this select 1;
publicVariable "noob_killer";
exit;


Add a trigger (repeatedly) with Condition:
Code: [Select]
not (isNull noob_killer)On Activation
Code: [Select]
noob_killer globalChat "I am a dirty, rotten, cheating,  poo-eating noob!" ; vehicle noob_killer setDamage 1 ; noob_killer setDamage 1 ; noob_killer = nilOn Deactivation
Code: [Select]
hint "Noob terminated!"
« Last Edit: 22 May 2007, 01:22:17 by Mr.Peanut »
urp!

Offline philabowl1

  • Members
  • *
Re: Vehicle Protection in Respawn
« Reply #2 on: 20 May 2007, 19:58:36 »
sorry Mr. Peanut, No go. first off, I get a "type script:expected nothing error" when entering the line in the unit init field. So I took out execVM and just went back to old exec and that seemed to work. However, when I try to test it in game I get an "error missing "{"" message and the game just crashes. I can't figure out where it is missing either! I'll keep tinkering, but any advice would be greatly appreciated. Thanks again though for your response.

Offline rhysduk

  • Former Staff
  • ****
Re: Vehicle Protection in Respawn
« Reply #3 on: 21 May 2007, 00:57:43 »
Phil,

To save on reading time, and to help keep the forums tidy, we try to encourage members to avoid the "Double Post" approach.
To add information to a recent post, click the MODIFY button in the top right of the post.

Helps keep OFPEC easily readable, and keeps the house work up.  :good:

Rhys
Reviewed Missions Board: Please Read the User's Guide before posting!

Pride and Joy 1 (HW100-T)

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Vehicle Protection in Respawn
« Reply #4 on: 21 May 2007, 21:14:12 »
Edit: Okay I've debugged the code and tested it in SP and it works. I edited the code in my first post. Try it again and please let me know how it works in MP. I have also attached a demo missionette.

« Last Edit: 22 May 2007, 01:26:04 by Mr.Peanut »
urp!

Offline philabowl1

  • Members
  • *
Re: Vehicle Protection in Respawn
« Reply #5 on: 24 May 2007, 04:54:25 »
Works great so far Mr. Peanut. Thanks for all your help. You are an asset to the community.  :good:

P.S. I think this one should go in the depot. It's been needed forever.
« Last Edit: 24 May 2007, 05:51:36 by philabowl1 »