Jump to content
Sign in to follow this  
bronson

check if player has weapon

Recommended Posts

hey guys ive used the search function and i couldnt find anything on this,im trying to have trigger that will only activate after the player picks up a gun.

ive tried using this command in a trigger condition which is a switch and activates constantly.

(count weapons s8 > 0) or ("30Rnd_556x45_Stanag" in magazines s8) or ("HandGrenade_west" in magazines s8) or ("200Rnd_556x45_M249" in magazines s8) or ("1Rnd_HE_M203" in magazines s8)

but it keeps activating straight away.

cheers if anyone can help

Share this post


Link to post
Share on other sites

You know... there's a handy little command called hasWeapon. Maybe you should check it out. ;)

Edit:

Oh wait. You want to know if he picks up ANY weapon? I see. Your code is probably failing because your supposedly unarmed guy is carrying something else in his inventory (map, GPS, watch, radio - these will all be returned with the weapons command). You could try subtracting those items from the returned array.

Edited by Big Dawg KS

Share this post


Link to post
Share on other sites

LOL! just had a try then and figured it out. sorry the s8 stood for the name of my unit.many thanks to the replys.

Share this post


Link to post
Share on other sites

Oh wait. You want to know if he picks up ANY weapon? I see. Your code is probably failing because your supposedly unarmed guy is carrying something else in his inventory (map, GPS, watch, radio - these will all be returned with the weapons command). You could try subtracting those items from the returned array.

That´s exactly what I need, but I don´t know how to.

I intend to make a player on a MPmission, to become "setcaptive false" if he holds (or at least has) a weapon, if possible specifically Pistols, rifles or launchers.

Than i intend to create a trigger attached to that unit which turns on or off dependind on player having a gun or not.

(the player will act as an infiltrated informant)

Help please, I´m stuck in this MP design problem!!!

Thanx!

Share this post


Link to post
Share on other sites

if you have no items then maybe just count the weapons count weapons player >0

You can add a few other checks to take into account any items you may be carrying or pick up

player init

removeallweapons player;removeallitems player

condition

count weapons player > count items player or (someammo player)

someammo is for grenades.

there maybe some items that still show as weapons though binoculars and NVgoggles I think count as weapons so you may have to filter them out as well.

Edited by F2k Sel

Share this post


Link to post
Share on other sites

You'd want to use primaryWeapon, secondaryWeapon and currentWeapon.

Here's some code you can use in your init string to test:

nul = [] spawn {   
while {true} do {    
hintsilent format["Has weapons: %1 - %2 - %3",primaryWeapon player, secondaryWeapon player, currentWeapon player];
sleep 0.2;
};
};

It'll be an empty string if nothing, or class name if he's holding a weapon. Doesn't count items (radio, watch whatever) or grenades. Pistol will be detected by currentWeapon.

Share this post


Link to post
Share on other sites

Does secondaryweapon work I could never get it to work in a trigger

primaryweapon player != "" worked fine but nothing for secondary.

I've missed currentweapon, that should work quite well, as whatever you pick up if you have no weapons will be the current weapon except for grenades so you still need an ammo check.

currentWeapon player != "" or (someammo player)

that avoids checking for items or binoculars .

Edited by F2k Sel

Share this post


Link to post
Share on other sites

Using just currentWeapon can trick the test actually. If you pick up an RPG or other secondary weapon, you'll be given the Option to "Hide" it (putting it on your back). Doing so can leave you with satchel charges, grenades and an RPG on your back while currentWeapon returns "" however secondaryWeapon does report the weapon. I suppose you could look for ammo types, but that seems messy to me, might be needed for grenades though.

Grenades return "Throw" and Satchel Charges return "Put" btw. :)

Share this post


Link to post
Share on other sites

All right guys, thanks a lot!! It works very good!

@Kylania

Your init lines worked perfectly! excepts in on situation, when I pick up first, a satchel or a grenade, it won´t show any place, except if I took any other weapon, and then change to nade/Charge. I do understand how this "mechanic" works in the game/engine, but once, I took 5 satchels, placed 4 of them close to enemy soldiers and exploded right in front of them. After this I hide myself, pickup a rifle, dropped it, and another enemy killed me carryng the last charge. Anyway, nothing that will bring problem to my mission.

@F2k sel

Also everything worked just as you said.

I´ll describe what I did bellow, for the use of others (with less than the basic of scripting)

-Created my unit, OPFOR named "me", in it init Field: this setcaptive true; removeallweapons this;

-Created 4 Blufor soldiers pointing at me

-created some ammoboxes

-Created a trigger type "none", condition: (currentweapon me != "") or (primaryweapon me != "") or (secondaryWeapon me != "");

On act.: me setCaptive false;

On Deac.: me setCaptive true;

I just added the "or (primaryweapon me != "") or (secondaryWeapon me != "")" part because in the specific case, hidden weapons (like a RPG on the back) uncover the unit in my mission.

When previewing it, as soon as you get a weapon, you read it´s respective hint and the enemy AIs starts to shoot. If you drop the weapon, they cease fire.

Thanks very much!!!

Now I just have to solve this other issue regarding knowing specific cargo positions to continue with my "undercover operations" take a look and help if ypou can once more ;) !!!!

Thank you all, hope this is usefull for others, these little details can add lots of possibilities!

Edited by Charlis

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  

×