Jump to content
Sign in to follow this  
malkekoen

Help with some triggers

Recommended Posts

Hello.

I have 2 triggers I need help with:

-The first trigger need to fire when the player picks up a specific weapon from a weapon crate. How would it be scripted?

-The second trigger is to fire when the player takes the first shot with that weapon. I guess you need the "fired" eventhandler, but I can't really write it properly myself. Hope anyone can help with that!

-Thirdly I have a problem detecting whether several unit are within a predifined area trigger. I can do it with one by adding

this && unit1 in thisList;

in the condition field, but what if I need 2 units?

this && unit1 && unit2 in thisList;

doesn't work...

Thanks!

Share this post


Link to post
Share on other sites
-The first trigger need to fire when the player picks up a specific weapon from a weapon crate. How would it be scripted?

For this you need to use the hasWeapon command. You can use it in the condition field of a trigger or inside of an external script with a loop checking for the condition to be true every couple of seconds.

You can find the name of the weapon in the CfgWeapons list for official weapons. If it is an addon weapon you need to consult the addon readme or use

hint format["%1", weapons this]; 

in the init line of the unit with the weapon you want to check for.

The second trigger is to fire when the player takes the first shot with that weapon. I guess you need the "fired" eventhandler, but I can't really write it properly myself. Hope anyone can help with that!

Add a 'fired' eventhandler to the unit which already has the weapon in its inventory like this:

this addEventHandler ["fired",  "hint format[""%1"",_this]"]

It will display the required parameters (muzzle, magazine etc.) which you can then check for in a script called by the real eventhandler.

Share this post


Link to post
Share on other sites

Thanks zwobot!

The first worked like a charm, the second one is causing a bit of headache.

This is a sort of what I would like to do, make a condition true when player fires his weapon. The code below doesn't work, and I'm not good at scripting.

this addEventHandler ["Fired",{if (_this select 0=="M40A3") then {_this select 0 M40A3fired=true"}}]

How would you do that in a correct fashion?

Share this post


Link to post
Share on other sites

This should work (not tested)

this addEventHandler ["Fired",{if (_this select 0=="M40A3") then {M40A3fired=true;};}]

Regarding your third question

-Thirdly I have a problem detecting whether several unit are within a predifined area trigger. I can do it with one by adding
this && unit1 in thisList;

in the condition field, but what if I need 2 units?

this && unit1 && unit2 in thisList;

doesn't work...

Your code is almost correct but it should be more like that in the trigger's condition line:

this && unit1 in thislist && unit2 in thisList

Edited by zwobot
Added answer to OP's third question

Share this post


Link to post
Share on other sites

Thank you again so much zwobot!

You just relieved my headache! I have been trying to figure this out for days before I went here with it. Will test tomorrowm gotta get to work ;) Can't wait!

Share this post


Link to post
Share on other sites

I just tested all the above, and everything except this one works like a charm:

this addEventHandler ["Fired",{if (_this select 0=="M40A3") then {M40A3fired=true;};}]

It it seems there is a "generic error in expression", I have tried to look at it a bit but can't seem to correct the problem. Maybe some scripting wiz can see the error?

Share this post


Link to post
Share on other sites

Maybe like this?

his addEventHandler ["Fired",{if ((_this select 0)=="M40A3") then {M40A3fired=true;};}] 

Share this post


Link to post
Share on other sites
Maybe like this?

his addEventHandler ["Fired",{if ((_this select 0)=="M40A3") then {M40A3fired=true;};}] 

Hmm I just tried it and it still gives me an error message and doesn't trigger. This is a direct copy and paste from the editor, to make sure I have no typos:

Unit1 addEventHandler ["Fired",{if ((_this select 0)=="M40A3") then {M40A3fired=true;};}]

Edit this is the piece of code obviously causing troubles:

if ((_this select 0)=="M40A3") then {M40A3fired=true;};

That is what is diplayed in the error message as a generic error in expression when unit1 fires any weapon.

Edited by malkekoen

Share this post


Link to post
Share on other sites

Hey it works! Thank you very much SaMatra, you're help is greatly appreciated!

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  

×