Home   Help Search Login Register  

Author Topic: Checking what the unittype is  (Read 2610 times)

0 Members and 1 Guest are viewing this topic.

Offline U_Z

  • Members
  • *
Checking what the unittype is
« 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?

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re: Checking what the unittype is
« Reply #1 on: 16 Aug 2006, 19:51:59 »
Check the command reference here .

Specifically the typeOf command.

That should give you some good pointers.

 :wave:


Planck
I know a little about a lot, and a lot about a little.

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re: Checking what the unittype is
« Reply #2 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.

Offline U_Z

  • Members
  • *
Re: Checking what the unittype is
« Reply #3 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.
« Last Edit: 16 Aug 2006, 20:52:53 by U_Z »

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: Checking what the unittype is
« Reply #4 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
Dont argue with idiots....they will bring you down to their level and beat you there with experience.

How to use Waypoint type Scripted

Offline U_Z

  • Members
  • *
Re: Checking what the unittype is
« Reply #5 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.

Offline JasonO

  • OFPEC Patron
  • ****
  • Oh no...
    • The New Life RPG
Re: Checking what the unittype is
« Reply #6 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:

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: Checking what the unittype is
« Reply #7 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
Dont argue with idiots....they will bring you down to their level and beat you there with experience.

How to use Waypoint type Scripted

Offline JasonO

  • OFPEC Patron
  • ****
  • Oh no...
    • The New Life RPG
Re: Checking what the unittype is
« Reply #8 on: 17 Aug 2006, 22:34:50 »
Oh. im wrong again :(

I wont question it, its not my thread :P

Offline U_Z

  • Members
  • *
Scripting Nightmare
« Reply #9 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.
« Last Edit: 18 Aug 2006, 07:24:34 by U_Z »

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re: Checking what the unittype is
« Reply #10 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 "".

Offline U_Z

  • Members
  • *
Re: Checking what the unittype is
« Reply #11 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?

Offline nominesine

  • Former Staff
  • ****
  • I'm NOT back!
    • The IKB Forum
Re: Checking what the unittype is
« Reply #12 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.
OFPEC | Intel Depot
RETARDED Ooops... Retired!

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Checking what the unittype is
« Reply #13 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"
urp!

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re: Checking what the unittype is
« Reply #14 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. :)

Offline U_Z

  • Members
  • *
Re: Checking what the unittype is
« Reply #15 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.