Warning: include(/var/www/html/forum/Sources/../../../includes/depot_files/OFPEC_get_header_image.inc.php): failed to open stream: No such file or directory in /var/www/html/forum/Sources/Load.php(2272) : eval()'d code on line 146

Warning: include(): Failed opening '/var/www/html/forum/Sources/../../../includes/depot_files/OFPEC_get_header_image.inc.php' for inclusion (include_path='.:/usr/local/lib/php') in /var/www/html/forum/Sources/Load.php(2272) : eval()'d code on line 146

Notice: Undefined index: OFPEC in /var/www/html/forum/Sources/Load.php(2272) : eval()'d code on line 152

Notice: Trying to access array offset on value of type null in /var/www/html/forum/Sources/Load.php(2272) : eval()'d code on line 152

Notice: Trying to access array offset on value of type null in /var/www/html/forum/Sources/Load.php(2272) : eval()'d code on line 152
    Home   Help Login Register  

Author Topic: Detecting unsilenced weapon  (Read 5293 times)

0 Members and 1 Guest are viewing this topic.

pazuzu

  • Guest
Detecting unsilenced weapon
« on: 02 Sep 2005, 05:56:11 »
Is it possible to detect if a unit is using a silenced or an unsilenced weapon?

I'm making a mission where silenced weapons are used(BAS weapons) and I want to be able to tell if any player is shooting an unsilenced gun he may have taken from dead enemy.

Thanks.

Offline Fragorl

  • Coding Team
  • Former Staff
  • ****
Re:Detecting unsilenced weapon
« Reply #1 on: 02 Sep 2005, 06:03:57 »
Provided you know the ammo types for the silenced weapons, and you know for sure that there is a set number of silenced weapons that could be used, you could use a fired eventhandler + a script, to check the type of ammo fired.

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:Detecting unsilenced weapon
« Reply #2 on: 02 Sep 2005, 09:09:56 »
You could also try giving them all a {fired} event handler that checks their primary weapon, or the weapon they have fired.  Something like the following in the init field of each unit.

this addEventHandler [{fired},{if ((_this select 1) in ["M16","AK74",...]) then {hint format ["%1 fired an unsilenced weapon",_this select 0]} }]

I have not tested this,  it should work but I may not have the brackets exactly right.


Note:
["M16","AK74",...] should include all the unsilenced wepaons you have in your mission.  Alternatively you could use:

if not ((_this select 1) in ["HK","GlockS",...]) ...

where you list all the silenced weapon in the mission.  Whatever is easiest.
« Last Edit: 02 Sep 2005, 09:11:01 by THobson »

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:Detecting unsilenced weapon
« Reply #3 on: 02 Sep 2005, 09:54:58 »
from sui -

Code: [Select]
player addEventHandler ["fired",{if ("_this select 1 == _x" count ["GlockS","Bizon","HK","Uzi"] == 0) then {loud = true}}]
loud being the global variable used to trigger your "aha - there he is!" repurcussions ;)

pazuzu

  • Guest
Re:Detecting unsilenced weapon
« Reply #4 on: 09 Sep 2005, 01:03:56 »
Ok, I finally got around to testing this.

I tried your code bedges & it works great. I just put a hint in to warn players not to drop their silenced weapons.

I ended up making an eventhandler for each unit in team. Is this right? Or is there an easier way to do it?

Did you intend on it being just the one eventhandler with a list of all the guns players carry?

This is what I placed in my init.sqs:

loud = false

p1 addEventHandler ["fired",{if ("_this select 1 == _x" count ["BAS_JM4ACOGS"] == 0) then {loud = true}}]
p2 addEventHandler ["fired",{if ("_this select 1 == _x" count ["BAS_JM249SPWSD"] == 0) then {loud = true}}]
p3 addEventHandler ["fired",{if ("_this select 1 == _x" count ["BAS_JM4ACOGS"] == 0) then {loud = true}}]
p4 addEventHandler ["fired",{if ("_this select 1 == _x" count ["BAS_JM249SPWSD"] == 0) then {loud = true}}]
p5 addEventHandler ["fired",{if ("_this select 1 == _x" count ["BAS_JSR25S"] == 0) then {loud = true}}]
p6 addEventHandler ["fired",{if ("_this select 1 == _x" count ["BAS_JM4ACOGS"] == 0) then {loud = true}}]
p7 addEventHandler ["fired",{if ("_this select 1 == _x" count ["BAS_JSR25S"] == 0) then {loud = true}}]
p8 addEventHandler ["fired",{if ("_this select 1 == _x" count ["BAS_JM249SPWSD"] == 0) then {loud = true}}]

This works fine so I appreciate the help.

Thanks.

pazuzu

  • Guest
Re:Detecting unsilenced weapon
« Reply #5 on: 10 Sep 2005, 21:16:41 »
I couldn't use your code bedges because just selecting a new gun in briefing would make this eventhandler activate so I needed to list east weapons instead.

I ended up using THobson's method and it works nicely but I need to know how I can create a global variable like in bedges code so I can use it for a condition to activate a trigger.

Thanks.

pazuzu

  • Guest
Re:Detecting unsilenced weapon
« Reply #6 on: 10 Sep 2005, 21:42:50 »
I just tested the eventhandler again and tried firing an rpg but it didn't detect it being fired.

Is this only good for primary weapons?

Kyle Sarnik

  • Guest
Re:Detecting unsilenced weapon
« Reply #7 on: 10 Sep 2005, 22:49:47 »
I just tested the eventhandler again and tried firing an rpg but it didn't detect it being fired.

Is this only good for primary weapons?

No, but I have a better method than the way you are doing it.

Eventhandler script:
Code: [Select]
_weapon = _this select 2

? _weapon in ["BAS_JM4ACOGS","BAS_JM249SPWSD","BAS_JSR25S"] : exit

loud = true
_unit removeeventhandler ["fired",0]

You will get better results.

pazuzu

  • Guest
Re:Detecting unsilenced weapon
« Reply #8 on: 11 Sep 2005, 00:54:01 »
Thanks for the reply but I have no idea how to call this script...

Do I need to make a new eventhandler?

And why is this a better method?


Thank you.

Offline macguba

  • Former Staff
  • ****
    • macguba's operation flashpoint page
Re:Detecting unsilenced weapon
« Reply #9 on: 11 Sep 2005, 02:36:00 »
It's called by a "fired" eventHandler.

You will need an EH for each team member.  This method is better because it uses just one script:  the same script is called whoever fires.   Consequently the whole thing is simpler and quicker.

Plenty of reviewed ArmA missions for you to play

Kyle Sarnik

  • Guest
Re:Detecting unsilenced weapon
« Reply #10 on: 11 Sep 2005, 04:46:30 »
It's called by a "fired" eventHandler.

You will need an EH for each team member.  This method is better because it uses just one script:  the same script is called whoever fires.   Consequently the whole thing is simpler and quicker.



Also, your previous method only worked if the units kept their starting weapons throughout the game, this method will work if, for example, one person takes a different supressed weapon from a dead friendly.

pazuzu

  • Guest
Re:Detecting unsilenced weapon
« Reply #11 on: 11 Sep 2005, 06:45:23 »
I cant get this to work...

The eventhandler fires when I fire the weapon I already have(Silenced).

I like the method THobson uses. It worked fine and I like the hint format ["%1 fired an unsilenced weapon" message in it.

The only thing I want to add is that global variable "loud=true".

Can I just add that to the eventhandler or is the hint format in place of that?

Can I have both?

Thanks again.

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:Detecting unsilenced weapon
« Reply #12 on: 11 Sep 2005, 09:40:04 »
the way this is done is by adding the eventhandler to the unit, but instead of having the instructions for what will happen when the unit fires within the event handler itself, you use the event handler to call a script, like this -

Code: [Select]
unit_name addEventHandler ["fired",{_this exec "silenced.sqs"}]

then, open up notepad and copy/paste the script

Code: [Select]
_weapon = _this select 2

? _weapon in ["BAS_JM4ACOGS","BAS_JM249SPWSD","BAS_JSR25S"] : exit

loud = true
_unit removeeventhandler ["fired",0]

save that as "silenced.sqs". you'll see from the script above the variable loud is set whenever a non-silenced weapon is fired by unit_name.

easy peasy. any questions?

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:Detecting unsilenced weapon
« Reply #13 on: 11 Sep 2005, 12:51:24 »
A couple of Three comments:

"BAS_JM4ACOGS","BAS_JM249SPWSD","BAS_JSR25S"

should be a complete list of all silenced weapons, so would you need to add:

"HK","Bizon","GlockS"

?

In the line:
_unit removeeventhandler ["fired",0]

_unit is not defined
it should be
_this select 0

The variable loud should be set = false at the start of the mission.

Okay so it is four:

_this select 1 is the weapon
_this select 2 is the muzzle


Well make it five then:
If you can get my code to work the way you want it but you don't want the hint just set a vaiable then use:

this addEventHandler [{fired},{if not ((_this select 1) in ["HK","Bizon",...]) then {loud = true} }]

Don't forget to set loud = true false at the start of the mission and to make sure the list of weapons contains all the silenced weapons in the mission.

« Last Edit: 11 Sep 2005, 16:13:21 by THobson »

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:Detecting unsilenced weapon
« Reply #14 on: 11 Sep 2005, 14:20:26 »
Quote
Don't forget to set loud = true at the start of the mission...

um, that should be false, no?