Jump to content
Sign in to follow this  
Rommel

Check Units Weapon

Recommended Posts

Problem: I wanted a script to check that the player had a M4. How do I do this?

Share this post


Link to post
Share on other sites

Oh... thats not wright...

He can also work with pirmaryWeapon and secondaryWeapon.

wink_o.gif

Share this post


Link to post
Share on other sites

Um anyone got some code for PW and SW (primary weapon and secondary weapon) wow_o.gif

All I want to know is how can I check if a guy has this weapon: M4. wink_o.gif

Share this post


Link to post
Share on other sites

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_unit hasWeapon "M4"

From comref:

Quote[/b] ]unit hasWeapon weaponName

Operand types:

   unit: Object

   weaponName: String

Type of returned value:

   Boolean

Description:

   Check if unit has given weapon.

Example:

   player hasWeapon "M16"

Share this post


Link to post
Share on other sites

Didnt work, or maybe I didnt use it right, anyone able to show me? rock.gif

wink_o.gif

Share this post


Link to post
Share on other sites

You must use that syntax within a condition statement. Can you supply your script/trigger settings/ etc.. where you are intending to use this? It would be easier if we knew what you were doing.... wink_o.gif

EDIT:Also, the "M4" refers to the standard BIS M4... you are not using any add-on M4's are you?

Share this post


Link to post
Share on other sites

Could this work?

rock.gif

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_weapon = weapons Rommel

?( _weapon == "M4"): exit

EDIT: This is the error message: "error ==: Type Array, expected Number,String,Object,Side,Group"

For your Info:

Rommel = Me

M4 = STANDARD BIS M4

Just Random Code - How to find out your weapon name and magazine. Quite handy if your OFP cant alt tab or the addon that your using doesnt tell you what the weapon names are in the readme or something (and or your to lazy to un-pbo the addon and read the config or you can but have no idea how to read a config).

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

hint format["weapons: %1, magazines: %2",weapons this,magazines this]

exit

This displays your weapon and what magazines you have.

Its quite handy wink_o.gif

@Crashdome

I used this:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

?(player hasWeapon "M16"): hint "You have an M16"; exit

Share this post


Link to post
Share on other sites

Nevermind I got the hasweapon thing to work. wink_o.gif

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

?(_this hasweapon "M4"): hint "You have a M4! How interesting!"; exit

exit

Share this post


Link to post
Share on other sites

the command //Weapons// returns an array, so you must do something like this:

? "M4" In Weapons Rommel : exit

Share this post


Link to post
Share on other sites
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

?(_this hasweapon "M4"): hint "You have a M4! How interesting!"; exit

exit

Rommel, I'm just confirming, is this the correct syntax for what you want?

Share this post


Link to post
Share on other sites

No, tounge_o.gif

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

#Wait

?(_this hasweapon "M4"): goto "Loop"

#Loop

?!(_this hasweapon "M4"): goto "Turn Off"

goto "Loop"

#Turn Off

_this action ["light off"]

goto "Wait"

I havent decided whether to use @ or or loops.

EDIT: @ didnt work, loops do work. wink_o.gif

tounge_o.gif

I guess you might be able to tell what this is for. wink_o.gif

Share this post


Link to post
Share on other sites
If you are talking about the weapon in hand... you can't   sad_o.gif

in fact you can check if a unit has a weapon in his hand ... but only with a workaround

if a unit pulls a gun his behaviour is changed from safe to

not safe (!=safe) immediately

however if he holsters the weapon again, it takes some time for the engine to change the unit back to safe

how could you forget, blanco, I showed you my example mission more than one year ago biggrin_o.gif

Share this post


Link to post
Share on other sites

what redface wrote should work, but let me add - it will work only for AI

for the Player (no matter if he's even got any gun) the Behaviour returns allways "AWARE", except when he is prone - then it will return "COMBAT"

Share this post


Link to post
Share on other sites

Correction of script:

When using a config this is how to make it work on init with a eventhandler:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_man = _this select 0

#Wait

?(_man hasweapon "Ak74Su"): goto "Loop"

_man action ["light off"]

goto "Wait"

#Loop

?!(_man hasweapon "Ak74Su"): goto "Turn Off"

goto "Loop"

#Turn Off

_man action ["light off"]

goto "Wait"

Is there anyway to check if its Multiplayer at the time? I am updating the script so it stops when he dies, if I can find out if its multiplayer at the time I can make it keeps on going until 5 minutes after he is dead, most respawns usually are not over 5 minutes wink_o.gif . If he is alive within those 5 minutes it continues. smile_o.gif

Though I dont think this will work? rock.gif z

I can only hope I guess....

Share this post


Link to post
Share on other sites
Quote[/b] ]how could you forget, blanco, I showed you my example mission more than one year ago

Yes, I remember now. smile_o.gif It took 20 seconds or so before the behavior returned to safe again.

But i'm pretty sure you did the test on the player and not on a AI unit  rock.gif I tried it myself but it doesn't work, so I suppose you did something different than me.

I don't think I have that test anymore, do you have the name of zip? Maybe I can find it back on my HD.

Share this post


Link to post
Share on other sites
Is there anyway to check if its Multiplayer at the time?

This expression will evaluate to true if there's a MP game playing:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">{playersNumber _x>0}count[east,west,resistance,civilian]>0

Example usage:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

@(time>0)

?{playersNumber _x>0}count[east,west,resistance,civilian]>0:goto "mpgame"

hint "This is a SP game"

exit

#mpgame

hint "This is a MP game"

exit

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×