Jump to content
Sign in to follow this  
andylee054

Problem of init in addon's eventhandlers

Recommended Posts

I found a problem on my addon's Eventhandlers.

If I added a eventhandler in my soldier's config like that:

class Eventhandlers

{

init = "[_this select 0] exec ""test.sqs""";

};

The sqs will be triggered when we load this soldier in game.

After I loaded the soldier, I order him to get in a car, then I found it will be triggered again when the soldier get out from a car.

No matter how many times I do this way, the test.sqs will be triggered again and again.

How can we stop it?

I found "removeEventhandler" won't work in config's Eventhandlers.

Any idea? Thanks.

Share this post


Link to post
Share on other sites

put this in ur script:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">if (format ["%1", soldierInit] == "scalar bool array string 0xfcffffef") then {soldierInit = []}

? (_this) in soldierInit: exit

soldierInit = soldierInit + [_this]

Share this post


Link to post
Share on other sites

Make sure to start using a tag (like 'ALE') for that global variable soldierInit or your soldier addon may be useless to others in the future.

Share this post


Link to post
Share on other sites

I'm curious as to why the init eventhandler is being called over and over? I have never experienced this.

Share this post


Link to post
Share on other sites

Not sure why, but I ran into this problem too. In 1.92

The solution provided however did work

Share this post


Link to post
Share on other sites
Quote[/b] ]I'm curious as to why the init eventhandler is being called over and over? I have never experienced this.

If I remember correctly, it only fires everytime a unit gets out of a vehicle. Probably because they loose some of there individual identity (cant think of a better way of describing this) when they board a vehicle. I think it only applies to addon init events and soldiers.

Try using SwitchCamera "EXTERNAL" on a AI unit that has just entered a vehicle as a passanger and moved off. To see what I mean.

Quote[/b] ]What is this?

"scalar bool array string 0xfcffffef"

Thats what an un-initialised variable returns, when used with the format command. So you can check to make sure a script called from the init event only runs once per mission.

Share this post


Link to post
Share on other sites

Oh by the way, that kind of comparison of an array to string will crash OFP after there are enough elements in the array.

Use count array==count array instead:

call{private{_t};_t=true;if(count ARR==count ARR)then{arr=arr+[_this];t=false;};if _t then{Arr=[_this];};}

Cheers

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  

×