Home   Help Search Login Register  

Author Topic: Addactions and respawning vehicles  (Read 1215 times)

0 Members and 1 Guest are viewing this topic.

Offline U_Z

  • Members
  • *
Addactions and respawning vehicles
« on: 29 Aug 2006, 05:10:52 »
I have a problem with this script. res.sqs, (this) is run on all vehicles that I want respawned. The police jeeps have sirens, and they work great, but when I blow the jeeps up, they respawn and they no longer have the action of turning the siren on and off. Can someone help me fix this script? I put [this] exec "res.sqs" in the vehicles I want respawned. When I host my own server, other people can't use the siren but I can (being the local server).
Code: [Select]
;Vehicle respawn script
_car = _this select 0
_type = typeof _car
_carpos = getpos _car
_cardir = getdir _car
_crew = []
_crew =  crew _car
_count = 50
_once = false
;If it's a police jeep, give it the siren ability
testjeep = "JeepPolice"
? testjeep == typeof _car : siren = _car addAction ["Turn siren on", "siren.sqs"]

;If no one is in the car, respawn it after a while
#loop
_crew =  crew _car
?((count _crew) != 0) : _once = true
?((count _crew) == 0) and (_once) : goto "nodriver"
#2
?((fuel _car) < 0.05) : goto "ofuel"
?((getdammage _car) > .33) : goto "do"
?((getdammage _car) <= .33) : goto "repair"
~10
goto "loop"

#do
~2
_car setfuel ((fuel _car) - 0.08)
~0.5
_car setfuel ((fuel _car) - 0.08)
~0.5
_car setfuel ((fuel _car) - 0.08)
~0.5
_car setfuel ((fuel _car) - 0.08)
~0.5
_car setfuel ((fuel _car) - 0.08)
~0.5
_car setfuel ((fuel _car) - 0.08)
~0.5
_car setfuel ((fuel _car) - 0.08)
~0.5
_car setfuel ((fuel _car) - 0.08)
~0.5
~10
_car setfuel ((fuel _car) - 0.08)
~0.5
_car setfuel ((fuel _car) - 0.08)
~0.5
_car setfuel ((fuel _car) - 0.08)
~0.5
_car setfuel ((fuel _car) - 0.08)
~0.5
_car setfuel ((fuel _car) - 0.08)
~0.5
_car setfuel ((fuel _car) - 0.08)
~0.5
_car setfuel ((fuel _car) - 0.08)
~0.5
_car setfuel ((fuel _car) - 0.08)
~0.5
_car setpos getmarkerpos "hospital"
~0.1
#direct
deletevehicle _car
~30.0
?!(local Server) : goto "eheh"
_car =  _type createVehicle _carpos
_car setdir _cardir
_car setpos _carpos

#eheh
ClearWeaponCargo _car; clearMagazineCargo _car
testjeep = "JeepPolice"
? testjeep == typeof _car : siren = _car addAction ["Turn siren on", "siren.sqs"]
_car addAction ["Lock vehicle", "lockListener.sqs"]
goto "loop"

#repair
~8
?((getdammage _car) > .3) : goto "do"
_dammage = getdammage _car
_car setdammage _dammage
goto "loop"

#ofuel
~20
?((fuel _car) < 0.05) : goto "do"
goto "loop"

#nodriver
~1
_count = _count - 1
? (_count == 0) : _count = 15; goto "sure"
goto "2"

#sure
?((count _crew) != 0) : goto "2"
_once = false
goto "direct"

I would also like to know if it is even possible to respawn a crate and all of it's contents.

Offline Garcia

  • Members
  • *
  • Leeds United is the best football team...EVER!
Re: Addactions and respawning vehicles
« Reply #1 on: 29 Aug 2006, 19:27:56 »
You should createvehicle new vehicles, not setdammage them to 0. Setting a vehicles damage from 1 to 0 usually just gives  you problems.

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Addactions and respawning vehicles
« Reply #2 on: 29 Aug 2006, 20:01:05 »
One problem you have occurs at the vehicle respawn.  You respawn the vehicle on the server only, but the clients must wait before they addaction to the jeep etc.  Adding the following code will make the clients wait until the car is respawned before acting on them.  One other problem is that setDir is local. You need to do it on each client.  Each client might have slightly different values of _cardir but it should all work out. Test the following code and see what happens.

Code: [Select]
carSpawnLock = TRUE
?!(local Server) : goto "eheh"
_car =  _type createVehicle _carpos
carSpawnLock = FALSE
publicVariable "carSpawnLock"
~0.5

#eheh
@(not carSpawnLock)
_car setdir _cardir

urp!