Home   Help Search Login Register  

Author Topic: detecting if unit has weapon  (Read 1656 times)

0 Members and 1 Guest are viewing this topic.

Nobby

  • Guest
detecting if unit has weapon
« on: 09 Jul 2003, 01:38:23 »
What is the syntax for detecting whether or not a unit is carrying a gun?

e.g:

? player has "M21"

police dofire player

OR...

? player has "Glock" and player behaviour "safe"

metal detectors doGo bezerk.

What are the correct syntax's for these?

Cheers

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:detecting if unit has weapon
« Reply #1 on: 09 Jul 2003, 04:48:44 »
You are looking for the "hasweapon" command. It returns a boolean. For example:
?bob hasweapon "m21" : bob fire bill

Simple enough, right? :P
HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!

Nobby

  • Guest
Re:detecting if unit has weapon
« Reply #2 on: 09 Jul 2003, 15:55:23 »
cheers mate, works a treat.

Now what I was wondering was if there was a universal code for a primary weapon? So that if the player is seen with any primary weapon then the above syntax's apply.

Also, how do you determine the behaviour of a character?

This is what I'm trying to do:

? player hasweapon "Glock" and Player behaviour = "AWARE" or "COMBAT": police fire player


But this don't work.

BronzeEagle

  • Guest
Re:detecting if unit has weapon
« Reply #3 on: 10 Jul 2003, 03:43:30 »
You're trying to do what i am.  having a guy walk up to a group of enemies as a captive.   normal guy.  nothings wrong.  then boom he pulls out a gun.  the enemy pulls out thier guns because he's pulled out his now.  then you have a gunfight.  I want to recreate that myself.  now i think you can use the code addeventhandler.  you can say player addeventhandler ("M16 in hand", exec "scriptname.sqs") and then in the script you put:    player setcaptive false.  Now this guy who has the gun walks up to the enemy as just a guy going about his business.  now he pulls out the gun and they're all "oh crap he's going to kill us pull your guns out" and you waste them all before they get a shot off.  you walk off a legend.  i think that might do it.  

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:detecting if unit has weapon
« Reply #4 on: 10 Jul 2003, 05:16:45 »
It looks like we are all trying to do the same thing :P. I'm trying to make a mission where guns are illegal in town, and the police will fire at you if you have one out.

Nobby: Unfortunately, there is no way for the player to change his "behaviour". It will always by default be "aware", no matter what the player is doing. It will only change if the player's AI leader says something ("at ease"), or if the mission designer types something like: player setbehaviour "safe". But if you want to see for yourself, the command you need is:

behaviour unit

This returns a string, such as "AWARE","SAFE","COMBAT", etc.

BronzeEagle: I'm sorry, but there is not "M16 in hand" eventhandler, so you can't do that. The closest thing to that is "fired", which detects when a unit has fired a weapon (but I know that's not what we want).

A sort of 'workaround' for this problem could be to have the player be unarmed, and give him an action that says "pull gun", or sumthin like that. Using the action would add a weapon to the player's inventory, and also make him no longer a captive. Of course, there are problems with this way (the player can't use whatever gun he wants; the gun would start with an empty clip; etc), but until something better is devised, it might be the only way to do it.

I'll let you know if I find a better way around this problem.
HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!

Nobby

  • Guest
Re:detecting if unit has weapon
« Reply #5 on: 10 Jul 2003, 14:48:55 »
How about the universal code for a primary weapon?

BronzeEagle

  • Guest
Re:detecting if unit has weapon
« Reply #6 on: 10 Jul 2003, 21:42:46 »
you'd need a list of condition and detecting scripts to properly know what you can use to trigger things.

deaddog

  • Guest
Re:detecting if unit has weapon
« Reply #7 on: 10 Jul 2003, 23:05:45 »
How about the universal code for a primary weapon?

Try this:

primaryWeapon vehicle
Operand types:
    vehicle: Object
Compatibility:
    Version 1.75 required.
Type of returned value:
    String
Description:
    Returns name of vehicle's primary weapon (empty string if none).

Example:
    primaryWeapon player

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:detecting if unit has weapon
« Reply #8 on: 11 Jul 2003, 00:59:36 »
Wow, didn't even know that command existed. I guess I should check my reference a little closer. That makes things easier :)
HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!

deaddog

  • Guest
Re:detecting if unit has weapon
« Reply #9 on: 11 Jul 2003, 03:25:30 »
Quote
Wow, didn't even know that command existed. I guess I should check my reference a little closer.


I've learned more by reading other peoples questions (and answers) than any other way.  :)  That, and hours of staring at the screen in total frustration.  :P

basil_rs2

  • Guest
Re:detecting if unit has weapon
« Reply #10 on: 14 Jul 2003, 20:00:17 »
Code: [Select]
_unit = _this select 0

?(count (weapons _unit) < 1): goto "noarms"

; // primary weapon

_weapon = (weapons _unit) select 0

; // last weapon
; // _weapon = (weapons _unit) select (count (weapons _unit) - 1)

_unit selectWeapon _weapon

_unit dowatch _unit
~1
_unit fire _weapon

#noarms

exit

you have to check the weapons anyway.
fire "Binocular", or fire "NVGoggles" is not very effective ;)