OFPEC Forum

Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: pazuzu on 02 Sep 2005, 05:56:11

Title: Detecting unsilenced weapon
Post by: pazuzu 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.
Title: Re:Detecting unsilenced weapon
Post by: Fragorl 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.
Title: Re:Detecting unsilenced weapon
Post by: THobson 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.
Title: Re:Detecting unsilenced weapon
Post by: bedges 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 ;)
Title: Re:Detecting unsilenced weapon
Post by: pazuzu 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.
Title: Re:Detecting unsilenced weapon
Post by: pazuzu 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.
Title: Re:Detecting unsilenced weapon
Post by: pazuzu 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?
Title: Re:Detecting unsilenced weapon
Post by: Kyle Sarnik 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.
Title: Re:Detecting unsilenced weapon
Post by: pazuzu 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.
Title: Re:Detecting unsilenced weapon
Post by: macguba 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.

Title: Re:Detecting unsilenced weapon
Post by: Kyle Sarnik 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.
Title: Re:Detecting unsilenced weapon
Post by: pazuzu 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.
Title: Re:Detecting unsilenced weapon
Post by: bedges 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?
Title: Re:Detecting unsilenced weapon
Post by: THobson 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.

Title: Re:Detecting unsilenced weapon
Post by: bedges 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?
Title: Re:Detecting unsilenced weapon
Post by: THobson on 11 Sep 2005, 16:12:45
Most certainly. :-[
Title: Re:Detecting unsilenced weapon
Post by: pazuzu on 11 Sep 2005, 20:32:15
I don't know what I'm doing wrong but I cant get this to work right.

I created a test trigger using the variable "loud" as the condition & a Hint to tell me the trigger fired.

For some reason It keeps firing if I have AI drop a BAS_JM249SPWSD & I fire it so I went back to check the name in the bas delta readme & it is right. If I play in any spot that is not leader & just kill the AI to get his BAS_JM249SPWSD the trigger does not fire. This is a mystery to me.

Using THobson's eventhandler I listed all the east weapons & it worked perfectly. The only thing missing was the creation of a global variable (loud).

I like the idea of using a script. Could I maybe list east weapons to be detected when fired by players?

I also like the hint format ["%1 fired an unsilenced weapon" message.

Could I add that to the script?

Also the script fired my test trigger only once. I wanted a warning message to appear every time any player tried to fire an enemy unsilenced weapon.

BTW the enemy only has unsilenced weapons.

Thanks again.
Title: Re:Detecting unsilenced weapon
Post by: Kyle Sarnik on 11 Sep 2005, 23:16:31
Code: [Select]
_unit = _this select 0
_weapon = _this select 1

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

hint format ["%1 has fired an unsuppressed weapon.",name _unit]

exit

So all you want is a warning? If you want something to happen you might want to add a variable but if all you want is a hint then this script will work.
Title: Re:Detecting unsilenced weapon
Post by: pazuzu on 11 Sep 2005, 23:55:18
No thats the thing...

I want both a message and a variable and as far as my testing goes having a list of enemy weapons to detect as being fired by player seems to work the best.

Such as THobson's code:

this addEventHandler [{fired},{if ((_this select 1) in ["JAM_AKM","JAM_Vz58","JAM_AK74","JAM_AKS74U","JAM_PKM","JAM_PKMFS","JAM_AKMGL","JAM_AK74GL","JAM_SVD","JAM_RPG7Launcher","JAM_SKS","JAM_RPD","JAM_CAVS_RPG7Launcher","JAM_RPDFS","JAM_PKMFS"]) then {hint format ["%1 fired an unsilenced weapon",_this select 0]} }]

The only thing missing is the variable.
Title: Re:Detecting unsilenced weapon
Post by: THobson on 12 Sep 2005, 00:38:48
So why don't you use:

this addEventHandler [{fired},{if ((_this select 1) in ["JAM_AKM","JAM_Vz58","JAM_AK74","JAM_AKS74U","JAM_PKM","JAM_PKMFS","JAM_AKMGL","JAM_AK74GL","JAM_SVD","JAM_RPG7Launcher","JAM_SKS","JAM_RPD","JAM_CAVS_RPG7Launcher","JAM_RPDFS","JAM_PKMFS"]) then {loud = true} }]


and in the init.sqs file put

loud = false

?

If you want the variable and the message then use:

this addEventHandler [{fired},{if ((_this select 1) in ["JAM_AKM","JAM_Vz58","JAM_AK74","JAM_AKS74U","JAM_PKM","JAM_PKMFS","JAM_AKMGL","JAM_AK74GL","JAM_SVD","JAM_RPG7Launcher","JAM_SKS","JAM_RPD","JAM_CAVS_RPG7Launcher","JAM_RPDFS","JAM_PKMFS"]) then {hint format ["%1 fired an unsilenced weapon",_this select 0];loud = true} }]
Title: Re:Detecting unsilenced weapon
Post by: pazuzu on 12 Sep 2005, 00:46:11
Thank you THobson.

That looks like exactly what I wanted.

Going to test it now...
Title: Re:Detecting unsilenced weapon
Post by: Kyle Sarnik on 12 Sep 2005, 01:37:29
Its better to detect if the unit is using silenced weapons rather then looking for all of te unsilenced ones. Also your hint won't show just their name, but their ID (side, group, group unit #, then name). So that means:

Code: [Select]
_unit = _this select 0
_weapon = _this select 1

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

hint format ["%1 has fired an unsuppressed weapon.",name _unit]
loud = true

exit

Its better to use a script, because you can make changes more easily and it saves a lot of repetative typing.

Also, you don't have to set loud to false at the begining, since by default its neither true or false so it won't set anything off.
Title: Re:Detecting unsilenced weapon
Post by: Fragorl on 12 Sep 2005, 02:31:56
What exactly do you plan on doing with the variable 'loud = true' once the insilenced weapon script has been called?
Title: Re:Detecting unsilenced weapon
Post by: THobson on 12 Sep 2005, 09:00:10
Quote
Also, you don't have to set loud to false at the begining
Wrong - well not always correct.  A local variable that is created within {} will not exist outside that set of instructions.  Also it is good practice to initialise all your variables first.  For example - I have no idea what pazuzu plans to do with the variable loud, but let's say he wants something to happen providing only silenced weapons have been fired he would use somethign like:

if ((some condition) and not loud) then {}

If loud has not been initiailised the if condition will resolve to a false even if a loud weapon has not been fired.

I agree it would be better to check to see if the fired event was triggered by a silenced weapon, and it would be better to use a script.  But for some reason pazuzu seems unable to make any of that work.

Now you are defining _unit and _weapon correctly I can see no reason why your script would not work.
Title: Re:Detecting unsilenced weapon
Post by: pazuzu on 12 Sep 2005, 09:52:50
I got the script to work now.

But at the end of the mission I want to be able to use some east weapons to ambush a boat convoy. I'm not sure which weapons yet but I guess I could just add them to list in script so they can be used.

Might look kinda strange if only some east weapons can be used....I'm gonna have to think about it...

I appreciate all your help.

Edit: Is there a way to make the use of unsilenced weapons ok at last objective?