Jump to content
Sign in to follow this  
Funkman

FiredNear Event Handler

Recommended Posts

Hi, sorry to post so many threads, but I keep running into issues I cant solve by myself...

I have a fired event handler which looks like this:

{_x addEventHandler ["fired", {playMusic "track1"}]} forEach [M1, M2, M3, M4, M5, M6, M7, M8, M9, M10, M11, M12, M13];

It works fine, as soon as anyone in the player's unit fires, the exciting action music starts.

The problem is that for every shot it starts again, so I need it to only go off once.

"Ah" I thought, Ill just add another fired event handler that removes the original fired event handler, but I cant have two at once.

Ok, well if I add a firedNear event handler it basically does the same thing, so I am trying to add this:

{_x addEventHandler ["firedNear", {removeEventHandler "fired"}]} forEach [M1, M2, M3, M4, M5, M6, M7, M8, M9, M10, M11, M12, M13];

But I keep getting the error

error missing ;

Am I not using the eventHandler correctly?

---------- Post added at 05:56 AM ---------- Previous post was at 05:45 AM ----------

Could I do something like this:

#loop

if (EventHandler "fired") == true then goTo #remove

else goTo #loop;

#remove

removeEventHandler "fired";

exit;

Am I way off with that?

Share this post


Link to post
Share on other sites

try :

{_x addEventHandler ["fired", {playMusic "track1";(_this select 0) removeEventHandler ["fired", 0]}]} forEach [M1, M2, M3, M4, M5, M6, M7, M8, M9, M10, M11, M12, M13];

Share this post


Link to post
Share on other sites

Great thanks...Works perfectly.

Can I trouble you for one more question?

I have an OPFOR trigger that looks like this

{alive _X && !fleeing _X} count thislist < 8
so it checks if there are any operational OPFOR within the radius.

Is it possible for the condition to also check if player is within the radius?

Thanks.

---------- Post added at 07:11 AM ---------- Previous post was at 07:07 AM ----------

----In testing the track played twice...Not straight away, but it got to the end and then started playing again...

---------- Post added at 08:00 AM ---------- Previous post was at 07:11 AM ----------

Im afraid the eventHandler does not work perfectly, sometimes it stops and starts the track again..

Share this post


Link to post
Share on other sites

You know that the FiredNear-EventHandler works only to maximum distance of ~69 meters?!

FiredNear

:rolleyes:

Share this post


Link to post
Share on other sites

Yeah thats not a problem, as the solution offered by ProfTournesol only uses the fired event handler...Only its seems to be stopping and starting for some reason...

---------- Post added at 09:19 AM ---------- Previous post was at 09:18 AM ----------

Maybe I should just try kylania's solution and use a detected by OPFOR trigger....Hmm..

---------- Post added at 09:25 AM ---------- Previous post was at 09:19 AM ----------

Ok, I am now trying a BLUFOR detected by OPFOR trigger. In the condition field, I have this:

(vehicle _x) in thisList forEach [M1, M2, M3, M4, M5, M6, M7, M8, M9, M10, M11, M12, M13];

But I dont understand the syntax correctly, it keeps telling me local variable in global space....

On activation I have

playMusic "track1"

This is probably a better way to do it after all...I just need to know how to code that first line correctly.

Share this post


Link to post
Share on other sites

Simply have BLUFOR detected by OPFOR selected. Have this as the condition. Then click on the Effects button in the bottom left corner of the trigger dialog and select Track1 or whichever track you want to play. When the trigger goes off all connected clients will play the song.

Share this post


Link to post
Share on other sites

Ah, but there are more units than just the player's group in this mission. I only want the song to play when the player's group is detected....

---------- Post added at 09:45 AM ---------- Previous post was at 09:44 AM ----------

Oh its a SP mission with custom music btw...

Share this post


Link to post
Share on other sites
Ah, but there are more units than just the player's group in this mission. I only want the song to play when the player's group is detected....

---------- Post added at 09:45 AM ---------- Previous post was at 09:44 AM ----------

Oh its a SP mission with custom music btw...

Then group (F2) the player's group with the trigger, and choose : "each member of the group" (or whatever it is in english, i got the French version).

Share this post


Link to post
Share on other sites

Thanks, but I dont understand that last bit "each member of the group", there is no option for that in a trigger that I can see..

Share this post


Link to post
Share on other sites
Thanks, but I dont understand that last bit "each member of the group", there is no option for that in a trigger that I can see..

Select the leader of the group, then select F2, then drag a line between him and the trigger, and you'll see that the "activation" part of the trigger will change.

Share this post


Link to post
Share on other sites

it should be all group members or something like that, the name should be descriptive enough... btw its top left a drop down menu in place trigger window.

Share this post


Link to post
Share on other sites

Ah, I never knew you could do that. Very helpful, thanks both of you!

-------

Can I ask something else if you dont mind looking at it?

I am trying to make sure that if a player completes the objectives in an unusual order, that I dont set an objective that has already been completed.

So in a trigger when Obj 3 is completed, I wrote in the on activation line

Obj3 = 'complete'

Now when objective two is completed, I call a script, Obj2.sqf:

If (Obj3 == 'complete') then exit else (player setCurrentTask tskWestObj3);

exit;

Problem is, it is telling me "undefined variable (Obj3)" How can I fix this?

Share this post


Link to post
Share on other sites

because you use ' not qoutes ", it should be like this:

Obj3 = "complete";

and the if then exit lulz combination is way off, and its a mix of sqf, sqs and .... ? sorry :D

should be like this:

If (Obj3 != "complete") then {player setCurrentTask tskWestObj3};

all sqf scripts exit on their own at the end of the script.

also remember to declare variables before they are use, you can also use isNil for that.

Share this post


Link to post
Share on other sites

Oh, oops, thanks for that.

Oh, I see, you have reversed the order of things. Interesting, Ill try that.

---------- Post added at 02:07 PM ---------- Previous post was at 02:06 PM ----------

Oh, but in the trigger when I set Obj3 to complete. Do I have to put

'complete'

Or

"complete"

Share this post


Link to post
Share on other sites

direct translation of your line, wich i simplified above:

If (Obj3 == "complete") then {hint "nothing happens here, script will just exit below"} else {player setCurrentTask tskWestObj3};

notice that paranteces () are only used in the condition, not the parts after where {} is used.

you only use ' or "" inside "", for example in a script created trigger.

"something, ""someString"", 'someotherstring', something_else"

otherwise you use "something".

so for you, regular "around"

Share this post


Link to post
Share on other sites

Oh thanks, thats very helpful. I was wondering about the diffrent types of brackets... :)

Share this post


Link to post
Share on other sites

For some reason I am still getting an error, but I thought this will work:

If ((taskState tskWestObj3) != "SUCEEDED") then {player setCurrentTask tskWestObj3};

We will see....

Share this post


Link to post
Share on other sites

In English that would work, but not sure it's right for what you're trying to do. Where are you putting that code?

Share this post


Link to post
Share on other sites

Ok it is telling me "undefined variable in expression - tskWestObj3"....Gargh confusing!

---------- Post added at 02:48 AM ---------- Previous post was at 02:48 AM ----------

Oh kylania, that is executing in a file called Obj2.sqf. WHen Obj2 is completed, it gets executed....

Share this post


Link to post
Share on other sites

I have the following event Handler but its not working.

It keeps telling me "missing ]"

I cant work it out:

{Tun1 addEventHandler [{"fired", [nul = execVM "IntroCam2.sqf"];Tun1 removeEventHandler {"fired", 0}]}]};

Share this post


Link to post
Share on other sites

Tun1 addEventHandler ["fired", {execVM "IntroCam2.sqf"}];

Move the removeEventHandler stuff to IntroCam2.sqf.

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  

×