OFPEC Forum

Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: U_Z on 16 Aug 2006, 19:40:09

Title: Checking what the unittype is
Post 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?
Title: Re: Checking what the unittype is
Post by: Planck on 16 Aug 2006, 19:51:59
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
Title: Re: Checking what the unittype is
Post by: THobson on 16 Aug 2006, 20:14:03
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.
Title: Re: Checking what the unittype is
Post by: U_Z on 16 Aug 2006, 20:50:24
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.

Code: [Select]
;If it's a police jeep, give it the siren ability
? _JeepPolice == typeof _car : addAction ["Turn siren on", "siren.sqs"]
siren.sqs
Code: [Select]
_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
exit
sirenoff.sqs
Code: [Select]
_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
exit
My police jeep isn't having any of these abilities.
Title: Re: Checking what the unittype is
Post by: Chris Death on 16 Aug 2006, 22:57:04
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
Title: Re: Checking what the unittype is
Post by: U_Z on 16 Aug 2006, 23:02:27
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.
Title: Re: Checking what the unittype is
Post by: JasonO on 17 Aug 2006, 14:22:51
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:
Title: Re: Checking what the unittype is
Post by: Chris Death on 17 Aug 2006, 22:29:22
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
Title: Re: Checking what the unittype is
Post by: JasonO on 17 Aug 2006, 22:34:50
Oh. im wrong again :(

I wont question it, its not my thread :P
Title: Scripting Nightmare
Post by: U_Z on 18 Aug 2006, 07:17:39
Code: [Select]
_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
exit
Argh! 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.
Title: Re: Checking what the unittype is
Post by: bedges on 18 Aug 2006, 08:38:17
it only sounds once because your loop is missing something:

Code: [Select]
#loop
_car say "siren"
~3.6
?(sirenon) : goto "loop"
exit

note the "".
Title: Re: Checking what the unittype is
Post by: U_Z on 18 Aug 2006, 16:35:36
Thanks Bedges. The siren works now! But when I went into multiplayer
Code: [Select]
#loop
_car say "siren"
~3.6
?(sirenon) : goto "loop"
exit
doesn't work! Can vehicles not 'say' sounds?
Title: Re: Checking what the unittype is
Post by: nominesine on 18 Aug 2006, 16:44:08
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.
Title: Re: Checking what the unittype is
Post by: Mr.Peanut on 18 Aug 2006, 17:05:30
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:
Code: [Select]
play_Siren1 = TRUE; publicVariable "play_Siren1"
Code: [Select]
play_Siren1 = FALSE; publicVariable "play_Siren1"Write a client script to monitor and play sound :
Code: [Select]
play_Siren1 = FALSE
#mainloop
@play_Siren
#sirenloop
car1 say "siren"
~3.6
if play_Siren1 then {goto "sirenloop"}
play_Siren1 = FALSE
goto "mainloop"
Title: Re: Checking what the unittype is
Post by: THobson on 18 Aug 2006, 17:17:03
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. :)
Title: Re: Checking what the unittype is
Post by: U_Z on 18 Aug 2006, 21:51:53
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.