Jump to content
Sign in to follow this  
Rexxenexx

Need help with addEventHandler for barrel "killed"

Recommended Posts

I'm using

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

barrel_1 addEventHandler ["killed", { barrels = barrels - 1; hint format["A Barrel was Destroyed by %2",_this select 0, name (_this select 1)]; if (GetDammage barrel_1 == 1) then {barrel_handler = execVM "barrel_hint.sqf"}; } ];

To each barrel (12 total) to detect if they are destroyed. It works perfect in testing but I just found out on a dedicated server it does nothing. What's another way I can do this? Thx.

Share this post


Link to post
Share on other sites

That won't work.

The killed eventhandler gets only fired where the object is local. In case of the barrels and MP this is the server.

And commands like hint, sidechat, etc., don't get transferred over the network.

A solution would be to use triggers or send a publicVariable when a barrel gets gestroyed and let the clients react on that.

Xeno

Share this post


Link to post
Share on other sites

I have to go back a version of the mission where I was using triggers to just hint it was destroyed, that worked but I thought it was kinda lame lookin'. confused_o.gif I wanted to pass the killer of the barrel so the players would be interested more in finding them. I tried a string variable instead of a hint for the "A Barrel was Destroyed by %2" but like you said in MP it doesn't pass/return. I shouldn't try to use an EH to do a trig's job I guess.

Share this post


Link to post
Share on other sites

This is still doable with EH's and public variables. This require v1.09 or later since it uses addPublicVariableEventHandler. This is untested but should work and please excuse any typos:

Put the following code in your init.sqf

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">"killer" addPublicVariableEventHandler {hint format ["A Barrel was Destroyed by %1", killer];};

Next replace your barrel_1 EH code with this (I removed some of the other code you had in there for simplicity sake so re-add it or move it as necessary):

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">barrel_1 addEventHandler ["killed", {_this execVM "barrelkilled.sqf"}];

Put all the code you want to run when a barrel is destroyed in this script:

barrelkilled.sqf

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">barrel = _this select 0;

killer = _this select 1;

publicVariable "barrel";

publicVariable "killer";

Here's the flow:

The init.sqf adds a public variable event handler to the server and every client that fires whenever the designated public variable changes via the publicVariable command.

A barrel is destroyed which triggers the killed EH which executes barrelkilled.sqf and passes the object killed and the unit that killed it.

barrelkilled.sqf receives the the object killed and the unit that killed it and stores them as global variables. It then broadcasts them as public variables to all clients.

The public variable event handler fires on all clients when a new value for "killer" is broadcast which then displays a hint on all clients that a barrel was killed and by whom. A variable with the barrel itself is also available if needed (barrel).

Each time a different barrel is destroyed the sequence repeats and "barrel" and "killer" are changed.

I hope this helps!

Share this post


Link to post
Share on other sites

Thanks guys I'm actually getting somewhere on this with your help! wink_o.gif

addPublicVariableEventHandler didn't work on local testing. It wouldn't error but it just wouldn't do anything. The addEventHandler works on local testing. but doesn't do anything in DedServer testing.

I've tried a bunch of ways but this is the only one that is working so far:

-adding to init.sqf

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

"killer" addPublicVariableEventHandler {_this execVM "MPbarrelkilled.sqf";};

barrel_1 addEventHandler ["killed", {_this execVM "barrelkilled.sqf"}];

-barrelkilled.sqf

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

barrels = barrels - 1;

barrel = _this select 0;

killer = _this select 1;

publicVariable "barrel";

publicVariable "killer";

killername = name killer;

sleep 1.0;

_string = format ["A Barrel was Destroyed by %1",killername];

hint _string;

sleep 3.0;

_string = format ["%1 Barrels Remaining",barrels];

hint _string;

if (true) exitWith {};

-MPbarrelkilled.sqf

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

barrels = barrels - 1;

barrel = _this select 0;

killer = _this select 1;

killername = name killer;

sleep 1.0;

_string = format ["A Barrel was Destroyed by %1",killername];

hint _string;

sleep 3.0;

_string = format ["%1 Barrels Remaining",barrels];

hint _string;

if (true) exitWith {};

Share this post


Link to post
Share on other sites

The "addPublicVariableEventHandler" ONLY works remotely; it will not fire locally. What you need to do is both,

--Ben

Share this post


Link to post
Share on other sites

I finished this mission a while back but do you mean:

-init.sqf

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

"killer" addPublicVariableEventHandler {_this execVM "barrelkilled.sqf";};

"killer" addEventHandler {_this execVM "barrelkilled.sqf";};

-barrelkilled.sqf

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

barrels = barrels - 1;

barrel = _this select 0;

killer = _this select 1;

publicVariable "barrel";

publicVariable "killer";

killername = name killer;

sleep 1.0;

_string = format ["A Barrel was Destroyed by %1",killername];

hint _string;

sleep 3.0;

_string = format ["%1 Barrels Remaining",barrels];

hint _string;

if (true) exitWith {};

will work?

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  

×