Home   Help Search Login Register  

Author Topic: Waypoint Problem with Respawn Script  (Read 439 times)

0 Members and 1 Guest are viewing this topic.

stretch65

  • Guest
Waypoint Problem with Respawn Script
« on: 31 Jul 2003, 10:20:45 »
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.

Offline Artak

  • The old beanbag shaker
  • Former Staff
  • ****
  • You want to talk about it, yes?
    • OFP Team Finlanders
Re:Waypoint Problem with Respawn Script
« Reply #1 on: 31 Jul 2003, 23:12:23 »
I don't see anything in that script which makes the units move. Or are you referring to actual waypoints in the editor?

When the unit has reached a certain waypoint and then what happens is that he basicly gets moved to another location, the waypoint where was reaching still remains.
As I see it the only way to do it is to script the waypoints and with using variables gove the unit his move commands.
For example if a unit gets killed and respawned as the script shows a variable 'wp1' is set to true. Then you'd have anothers script running on the back and checking if wp1 is true or false. If true then a move command would be issued to the first set of coordinates, if not well, then to somewhere else.
Not all is lost.