Hi,
I have a problem with a vehicle respawn script which I've modified from a downloaded script (it was originally created by an author named "doolittle"). I doubt if there's a solution to it, but I thought I'd give all the script gurus out there the benefit of the doubt.
It's designed to run on a vehicle, and it respawns the vehicle when it's destroyed (eg. [this] exec "vehicle.sqs"). The new vehicle is then put back where it began, at its first waypoint. It is then supposed to repeat the same set of waypoints. This is the code:
;----------------------------------------------------
requiredVersion "1.91"
? not local Server : exit
_obj = _this select 0
_pos = getPos _obj
_dir = getDir _obj
_type = typeOf _obj
_group = group _obj
_crew = []
"_crew = _crew + [typeOf _x]" forEach crew _obj
"_x addEventHandler [""Killed"", {(_this select 0) removeAllEventHandlers ""Killed""; deleteVehicle (_this select 0)}]" forEach crew _obj
#clear
_t = 0
#alive
~3
? not alive _obj : _delay = 5; goto "notalive"
? fuel _obj == 1 : goto "clear"
? count crew _obj != 0 : goto "clear"
? _t == 0 : _t = _time + 110
? _t > _time : goto "alive"
"_obj removeMagazine _x" forEach magazines _obj
_obj setFuel 0
_obj setDamage 1
_delay = 10
#notalive
~_delay
deleteVehicle _obj
~1
_obj = _type createVehicle _pos
_obj setDir _dir
? count _crew < 1 : goto "clear"
Soldier = []
_crew select 0 createUnit [_pos, _group, "Soldier = this"]
Soldier moveInDriver _obj
Soldier addEventHandler ["Killed", {(_this select 0) removeAllEventHandlers "Killed"; deleteVehicle (_this select 0)}]
? count _crew < 2 : goto "clear"
Soldier = []
_crew select 1 createUnit [_pos, _group, "Soldier = this"]
Soldier moveInGunner _obj
Soldier addEventHandler ["Killed", {(_this select 0) removeAllEventHandlers "Killed"; deleteVehicle (_this select 0)}]
? count _crew < 3 : goto "clear"
Soldier = []
_crew select 2 createUnit [_pos, _group, "Soldier = this"]
Soldier moveInCommander _obj
Soldier addEventHandler ["Killed", {(_this select 0) removeAllEventHandlers "Killed"; deleteVehicle (_this select 0)}]
goto "clear"
;----------------------------------------------------
The above script respawns a vehicle as I've described, but the problem is with the waypoints. For example, say the vehicle has 5 waypoints. If the vehicle is destroyed before it reaches its first waypoint, the vehicle is re-created and it repeats each waypoint in the correct order as expected.
But if it's destroyed between waypoints 1 and 2, the re-created vehicle heads directly to waypoint 2 and ignores waypoint 1. Similarly, if it's destroyed between waypoints 2 and 3, the re-created vehicle ignores waypoints 1 and 2, and heads straight for waypoint 3. So how do I ensure that it repeats all the waypoints, and in the correct order?
I have tried a few things to correct this. For example, I could somehow keep track of what waypoint the vehicle has visited so far, and the next time it's destroyed I could make it visit the earlier waypoints using the 'doMove' command. This is actually what the author of the original
script tried to do. But this command does not trigger any scripting associated with the waypoint. It simply makes the vehicle move to the waypoint's position.
Obviously, the vehicle object uses an internal index that indicates which waypoint it should go to next. But is there any way of accessing or changing this index?
My thanks to anyone willing to help.