OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: U_Z on 16 Aug 2006, 19:40:09
-
I've searched the forum and google, but I haven't got any relevant hits, so I'll post it here.
I want to check if "car" is a JeepPolice. I don't know how to do that... Could someone please tell me?
-
Check the command reference here (http://www.ofpec.com/COMREF/index.html).
Specifically the typeOf command.
That should give you some good pointers.
:wave:
Planck
-
To give you a slightly bigger clue: :D
http://www.ofpec.com/COMREF/index.php?action=list&letter=t#typeOf
Place a police jeep on the map and us this command to find out what type it is.
-
Maybe I was too vague...I want to find out if _car is a JeepPolice... Not if a JeepPolice is a _car...
Or maybe I'm using it in the wrong syntax.
;If it's a police jeep, give it the siren ability
? _JeepPolice == typeof _car : addAction ["Turn siren on", "siren.sqs"]siren.sqs
_car = _this select 0
;Is the cop in the jeep?
?(cop1 in _car) : _driver = cop1; goto "start"
?(cop2 in _car) : _driver = cop2; goto "start"
?(cop3 in _car) : _driver = cop3; goto "start"
?(cop4 in _car) : _driver = cop4; goto "start"
;tell them to get in
_msg = "Get in the jeep first."
?(cop1 == player) : hint _msg
?(cop2 == player) : hint _msg
?(cop3 == player) : hint _msg
?(cop4 == player) : hint _msg
exit
#start
;get rid of Siren on
_car removeaction siren
;replace it with Turn siren off
_car addAction ["Turn siren off","sirenoff.sqs"]
sirenon = true
publicVariable "sirenon"
#loop
_car say "siren"
~3.6
? sirenon : goto loop
exitsirenoff.sqs
_car = _this select 0
;Is the cop in the jeep?
?(cop1 in _car) : _driver = cop1; goto "start"
?(cop2 in _car) : _driver = cop2; goto "start"
?(cop3 in _car) : _driver = cop3; goto "start"
?(cop4 in _car) : _driver = cop4; goto "start"
;tell them to get in
_msg = "Get in the jeep first."
?(cop1 == player) : hint _msg
?(cop2 == player) : hint _msg
?(cop3 == player) : hint _msg
?(cop4 == player) : hint _msg
exit
#start
;get rid of Siren off
_car removeaction sirenoff
;replace it with Turn siren on
_car addAction ["Turn siren on","siren.sqs"]
sirenon = false
exitMy police jeep isn't having any of these abilities.
-
Well, first off you're comparing two local variables:
? _JeepPolice == typeof _car : addAction ["Turn siren on", "siren.sqs"]
Did you assign _JeepPolice before to the string "JeepPolice"?
If not, it won't work.
? typeof _car == "JeepPolice": blablabla action
~S~ CD
-
No...I did not do that. Thanks Chris. I'll see if that works, I'm pretty new to scriptting and am still not sure of what the _ operator does. Thanks.
-
If a variable has _ before it, it means its local (only the person who ran the script/trigger that defined it knows what it is).
If you dont want it local, just remove the _
EDIT : Woot new smileys :D :afro:
-
Umm not really Jason :)
A local variable (_variable) will be only known inside the script it has been assigned.
If you for example have 20 units and each unit executes the same script you will end up in each unit
using the same _variables. But because these _variables are local within the script only, there won't
be any conflicts. ;)
~S~ CD
-
Oh. im wrong again :(
I wont question it, its not my thread :P
-
_car = _this select 0
;Is the cop in the jeep?
?(cop1 in _car) : _driver = cop1; goto "start"
?(cop2 in _car) : _driver = cop2; goto "start"
?(cop3 in _car) : _driver = cop3; goto "start"
?(cop4 in _car) : _driver = cop4; goto "start"
;tell them to get in
_msg = "Get in the jeep first."
?(cop1 == player) : hint _msg
?(cop2 == player) : hint _msg
?(cop3 == player) : hint _msg
?(cop4 == player) : hint _msg
exit
#start
;get rid of Siren on
_car removeaction siren
;replace it with Turn siren off
_car addAction ["Turn siren off","sirenoff.sqs"]
sirenon = true
#loop
_car say "siren"
~3.6
?(sirenon) : goto loop
exitArgh! This is turning into a scripting nightmare! Is there some way to make member variables? I realize there will be a major problem if sirenon is a public variable, but I can't use sirenon as a local variable because I still want some way to turn it off... Can there be an addAction on the same script that is currently running? I've noticed that my siren only sounds off once.
-
it only sounds once because your loop is missing something:
#loop
_car say "siren"
~3.6
?(sirenon) : goto "loop"
exit
note the "".
-
Thanks Bedges. The siren works now! But when I went into multiplayer
#loop
_car say "siren"
~3.6
?(sirenon) : goto "loop"
exitdoesn't work! Can vehicles not 'say' sounds?
-
Vehicles can say sounds, but there's a difference between them and their drivers.
If a unit is given several say commands in a row they will be stacked and ordered into queu, each spoken in turn. A vehicle will say them all in one breath.
But you have nice ~pause in your code here, so I suspect that the problem is something else. Most likely: the say command comes from a script that is run on only one machine. Solution: make sure that the script is run on every machine. Otherwise the sound will only play on the machine where the unit is local.
-
addActions are always local. Unfortunately, if you want the siren to be heard on all machines, you must write your own sound handler.
Add code to your siren scripts to publicVariable a flag:
play_Siren1 = TRUE; publicVariable "play_Siren1"play_Siren1 = FALSE; publicVariable "play_Siren1"Write a client script to monitor and play sound :
play_Siren1 = FALSE
#mainloop
@play_Siren
#sirenloop
car1 say "siren"
~3.6
if play_Siren1 then {goto "sirenloop"}
play_Siren1 = FALSE
goto "mainloop"
-
Not to seem heavy handed or anything, but this has gone 'off topic' (Creating vehicles -> vehicles making sounds), and is now going 'off board' (General Editing -> Multiplayer).
It makes it a lot easier for everyone if we have one thread per question and if we deal with questions in the appropriate place. :)
-
Thanks to everyone who have helped me :). I finally have working multiplayer police sirens :cop:. I will release my mission later on the week of the 27th because I am going on vacation this weekend+week... Again, I thank everyone for being so helpful.