Home   Help Search Login Register  

Author Topic: Lock/Unlock vehicle action to keep out unwanted crew  (Read 1166 times)

0 Members and 1 Guest are viewing this topic.

SSG Plazmoid

  • Guest
I thought it might be nice to be able to lock your vehicle to keep out unwanted crew members. Most of the time chopper pilots prefer to not have a gunner and tank crews prefer to not have a commander.

I started out by using getin/getout events attached to the vehicle. When a getin event ocurred I added a lock action to the first unit in the vehicle and removed the action upon exiting the vehicle. This worked 1 out of 10 times. It took me a while to figure out why and the answer was it shouldn't have ever worked. I believe actions attached to a player aren't supposed to be available inside a vehicle which is what I was trying to do. So, had to go another route.

I addaction the lock command to the vehicle. When the action is used the lock.sqs script looks if the unit that used the action is inside the vehicle and if they aren't the script exits with a hint message stating why the vehicle didn't lock. If the unit that used the action was inside of the vehicle then the lock action is removed from the vehicle, an unlock action is added, and the vehicle is locked.

For unlocking the process is similar except I also wanted to test if the vehicle was empty and locked. How could this happen if the vehicle could be locked only from the inside? It's possible to be killed inside the vehicle but not have the vehicle destroyed. In this case it would remain locked with no one inside. So, I loop through the crew members testing if each one is alive. You would think it would be enough to just test ?(count crew _vehicle == 0):then... but sadly in my test a dead crew member still counted as part of the crew.

What's needed:
add action to each vehicle which will call a lock.sqs script. To better identify the lock action for the vehicle you want it might be a good idea to customize the action text for each vehicle otherwise if 2 vehicles are right next to each other you won't know which is which if you see "Lock Vehicle" 2x.

in init of vehicle:
Code: [Select]
actionID = this addAction ["Lock Vehicle","lock.sqs"] where I defined actionID = 0 in init.sqs.

lock.sqs:
Code: [Select]
_object = _this select 0
_unit = _this select 1
?(_object == _unit)||(vehicle _unit == _unit):hint "You must lock from inside";exit

_object lock true
_object removeaction actionID
actionID = _object addaction ["Unlock Vehicle","unlock.sqs"]
hint "Vehicle is now LOCKED"
exit

unlock.sqs:
Code: [Select]
_object = _this select 0
_unit = _this select 1
_crew = crew _object
_crewcount = count _crew
_counter = 0
_alive = 0
#loop
_crewmember = _crew select _counter
?(alive _crewmember):_alive = 1;goto "end"
_counter = _counter + 1
?(_counter > _crewcount):goto "end"
goto "loop"

#end
?!(_unit in _crew)&&(_alive == 1):hint "Hmm. It didn't work";exit

_object lock false
_object removeaction actionID
actionID = _object addaction ["Lock Vehicle","lock.sqs"]
hint "Vehicle is now UNLOCKED"
exit

SSG Plazmoid
« Last Edit: 20 Dec 2002, 21:39:51 by SSG Plazmoid »