Home   Help Search Login Register  

Author Topic: "DeleteVehicle" and Driver with a Script in a Trigger  (Read 2030 times)

0 Members and 1 Guest are viewing this topic.

Offline Mock360

  • Members
  • *
Here I am once again seeking the advice of the masters  :D

I am trying to create a random vehicle (and personnel) traffic generation system. So far I have been able to spawn random vehicles and drivers, get drivers into the vehicles, get the vehicles to move to some random selected checkpoints and then to move to a "delete point" (a trigger that runs script). And that is where I run into problems. I can't seem to crack the code on deleting the vehicles AND the drivers. The vehicles will make it all the way to the delete points (rdp) but only the first vehicle into the trigger is deleted, but not the driver. And then, any subsequent vehicles into the delete point trigger are not deleted at all. Here are the scripts and settings I'm using. Any help and hints would be greatly appreciated.

Lines from the init.sqs

;-------------------------
traf1 = False
publicVariable "traf1"
;max vehicles to create
rtrafmax = 10
;available vehicle array
rtrafv = ["Mini","Trabant","Skoda","SkodaRed","Bus","Jawa","TruckV3SCivil","SkodaBlue","SkodaGreen","JeepPolice"]
;available driver array
rtrafd = ["Civilian5","Civilian2","Civilian3","Civilian4","Civilian6"]
;random start point array
rtrafsp = [rsp1,rsp2,rsp3,rsp4]
;random checkpoint array
rtrafcp = [rcp1,rcp2,rcp3,rcp4,rcp5]
;random delete point array
rtrafdp = [rdp1,rdp2,rdp3,rdp4,rdp5]
;maximum number of checkpoint before delete point is determined
rtrafcpmax = 2
;-------------------------


Script that creates vehicle and drivers
create_rtraf.sqs
^^^^^^^^^^^^^^^^
; *****************************************************
; ** Operation Flashpoint Script File
; *****************************************************
?! (local server): exit
_rtraf = 0
_rtrafm = rtrafmax

;-------------------------
traf1 = True
publicVariable "traf1"
;-------------------------

#start
? _rtraf >= _rtrafm : goto "exit"

;get_rspos
_pos = rtrafsp select(random 3)
_rspos = getpos _pos
_dir = getdir _pos

;create_vehicle
_rv = rtrafv select (random 9)
rv = _rv CreateVehicle _rspos
rv setdir _dir

;create_driver
_rdvr = rtrafd select (random 4)
_d1 = _rdvr createunit [_rspos, dvrs, "this moveindriver rv; dv = driver rv; [this] exec {rtraf\move_to_rcp.sqs}", 1.0, "Sergeant"]
;[this] join grpnull
dv = null
rv = null

;count loop
~2
_rtraf = _rtraf + 1
goto "start"

#exit
exit
^^^^^^^^^^^^^^^^

Script that moves vehicles to random checkpoints (rcp) and then on to delete point (rdp)
move_to_rcp.sqs
^^^^^^^^^^^^^^^^
; ********************************************************
; ** Operation Flashpoint Script File
; ++ Based on the "dynwp_object.sqs" by Kane and SnYpir ++
; ** called from "create_traf.sqs"
; ********************************************************

?! (local server): exit

;move_to_waypoint - get_rcpos
_trv = _this select 0
_cp = 0
_cpmax = rtrafcpmax

#rcp_loop
_cpos = rtrafcp select(random 4)
_rcpos = getpos _cpos
_trv domove _rcpos
@ unitready _trv
~0.1
_cp = _cp + 1
? _cp >= _cpmax : goto "to_rdp"
goto "rcp_loop"

#to_rdp
_crdp = rtrafdp select (random 4)
_rdpos = getpos _crdp
_trv domove _rdpos
~0.1

exit
^^^^^^^^^^^^^^^^

Script that is supposed to delete vehicle and driver in delete point trigger
trig_delete.sqs
^^^^^^^^^^^^^^^^

; *****************************************************
; ** Operation Flashpoint Script File
; ** usage [trigname] exec "trig_delete.sqs"
; *****************************************************

?! (local server): exit

_trigger = _this Select 0
_delist = list _trigger
_i = 0

#loop
_unit = (_delist select _i)
{deletevehicle _x} foreach _units
_i = _i +1
?!(_i==count _delist):goto "loop"

exit
^^^^^^^^^^^^^^^^

Trigger settings
^^^^^^^^^^^^^^^^

Civilian     repeatedly
present

Type: none
Name: deltrig4
condition: this
on activation: [deltrig4] exec "rtraf\trig_delete.sqs"

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: "DeleteVehicle" and Driver with a Script in a Trigger
« Reply #1 on: 08 Dec 2007, 10:04:11 »
Triggers only detect vehicles and people on foot. People inside vehicles will not be part of thisList (or list _trigger). You need to delete the crew first, then delete the vehicle itself.
In trigDelete.sqs:
Code: [Select]
{{ deleteVehicle _x } forEach (crew _x); deleteVehicle _x} forEach _units

The trigger will only be fired when it transitions from having no civilians in it to having civilians in it. When you delete the vehicles without deleting the crews, then the trigger still has civilians in it, even if they are different civilians than it originally detected, so it doesn't fire again.

Incidentally, in the trigger activation, you should be able to use thisList to find out the list of units within the trigger. Saves you having to name the trigger, pass that name to the script and then use list to find the same thing out. You could even just put it all in the trigger, since it isn't too complex:
Code: (trigger activation) [Select]
{{ deleteVehicle _x } forEach (crew _x); deleteVehicle _x} forEach thisList;
« Last Edit: 08 Dec 2007, 10:10:16 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Mock360

  • Members
  • *
Re: "DeleteVehicle" and Driver with a Script in a Trigger
« Reply #2 on: 08 Dec 2007, 17:18:01 »
Worked like a charm Spooner!  :cool2:

Thanks!