Was told the idea of adding a flag to a vehicle if a friendly unit has stolen an enemy vehicle. This is actually really easy using events. I did it another way and sort of got it working but after fighting the remaining problems for a few weeks I came to my senses and simplified using events (this is what led me to the chopper resource I mention in my other post). The beauty of events is the reduction in overhead. There are no scripts running waiting for the event, loops or wait events. OFP keeps track of the events and we start a script only after the event has occured.
A couple of things:
First, I haven't worked on making this work for respawned vehicles yet. I think there's a way but I've never had good luck attaching events or scripts to respawned vehicles. We do vehicle respawn by deleting the vehicle and recreating it at the appropriate spawn area using the appropriate vehicle class (which we know from where/what the vehicle was at mission start). When a unit dies the script(s) associated with it stop. When the vehicle is respawned it gets a new name generated by OFP.
Second, I haven't yet ensured that only friendly units can see the flag. It will be most useful if the enemy can't see the flag. Also, since I use the same flag for both sides it would be confusing to some people if they had to think about seeing that flag on their side's vehicles (hint it's enemy).
So, here's a pic of the flag:
You'll need to add a Flag object/unit for each vehicle. So you'll need 1 pole per vehicle. Each one needs a name. I named each pole similar to the vehicle it's associated with adding an f. So for vehicle w1 the associated flag is w1f.
Next, add GetIn and GetOut events to your vehicle in it's init field. To simplify the script it's helpful to separate east and west vehicles into their own events/scripts.
this addEventHandler ["GetIn",{_this exec "west_vehicleIn.sqs"}]
this addEventHandler ["GetOut",{_this exec "west_vehicleOut.sqs"}]
For east vehicles, just call the east in/out scripts.
this addEventHandler ["GetIn",{_this exec "east_vehicleIn.sqs"}]
this addEventHandler ["GetOut",{_this exec "east_vehicleOut.sqs"}]
In the "west_vehiclein" code (blocks of code at bottom) we exit if a west unit has entered the vehicle since the vehicle hasn't been stolen in this case. If it's an east unit then we look at which vehicle it was and look how many units are now in the vehicle. If the crew count is 1 then we know it was just stolen and the unit that triggered the event is made the flagowner for the flag associated with that vehicle. A "don't shoot" flag will now be flown on that vehicle. In order for only friendly units to see the flag I need to check the side of the player (and exit if side player != side _unit) in addition to the number of crew. I haven't added that yet but just realized it should be that easy.
We have to have a way to get rid of the flag also otherwise the unit will be carrying a big yellow flag upon exit. (note: big flags attached to each unit might help train people which team someone is on for new players hehe - could attach US flags to US units and Russian flags to EAST units).
In the "west_vehicleout" code we look at two things once we know the vehicle. Is the vehicle empty? If it is we know the unit that got out was the last unit to be in the vehicle so we know they had the flag. In that case we set flagowner of the flag associated with the vehicle to objnull (no one). If the vehicle is not empty we know the unit that got out wasn't the only unit in the vehicle. In this case we reset the owner of the flag to the next crew member in the vehicle. Regardless of the position the unit is in the vehicle, the first crew member can be found using: _unit = crew _vehicle select 0.
If someone makes this work on respawned vehicles let me know how you did it.
Plaz
west_vehiclein.sqs
_unit = _this select 2
?(side _unit == WEST):exit
?(side _unit == EAST):goto "east"
exit
#east
_vehicle = _this select 0
?(_vehicle == w1): goto "w1"
?(_vehicle == w2): goto "w2"
?(_vehicle == w3): goto "w3"
?(_vehicle == w4): goto "w4"
?(_vehicle == w5): goto "w5"
exit
#w1
?(count crew w1 == 1):w1f setflagowner _unit;exit
#w2
?(count crew w2 == 1):w2f setflagowner _unit;exit
#w3
?(count crew w3 == 1):w3f setflagowner _unit;exit
#w4
?(count crew w4 == 1):w4f setflagowner _unit;exit
#w5
?(count crew w5 == 1):w5f setflagowner _unit;exit
west_vehicleout
_unit = _this select 2
?(side _unit == WEST):exit
?(side _unit == EAST):goto "east"
exit
#east
_vehicle = _this select 0
?(_vehicle == w1): goto "w1"
?(_vehicle == w2): goto "w2"
?(_vehicle == w3): goto "w3"
?(_vehicle == w4): goto "w4"
?(_vehicle == w5): goto "w5"
exit
#w1
?(count crew w1 == 0):w1f setflagowner objnull;exit
_unit = crew w1 select 0
w1f setflagowner _unit;exit
#w2
?(count crew w2 == 0):w2f setflagowner objnull;exit
_unit = crew w2 select 0
w2f setflagowner _unit;exit
#w3
?(count crew w3 == 0):w3f setflagowner objnull;exit
_unit = crew w3 select 0
w3f setflagowner _unit;exit
#w4
?(count crew w4 == 0):w4f setflagowner objnull;exit
_unit = crew w4 select 0
w4f setflagowner _unit;exit
#w5
?(count crew w5 == 0):w5f setflagowner objnull;exit
_unit = crew w5 select 0
w5f setflagowner _unit;exit