Jump to content
Sign in to follow this  
clydefrog

addAction removeEventHandler problem on server

Recommended Posts

I've added a HandleDamage eventhandler to an ammo box using:


cargoBox1 addEventHandler ["HandleDamage", {false}];

Now I've added an addAction to that box, and when the addAction is executed the script it runs has this in it:


cargoBox1 removeEventHandler ["HandleDamage",0];

In the editor this works and you can damage the box after running the script. On a server it does not remove the eventhandler and the box stays invulnerable. I have also tried using a function created for BIS_fnc_MP so I can remove the EH for all clients which also doesn't work (and I've tried using the same type of thing to add the eventhandler as well):

Function in script run from the init.sqf (script is run on all machines):

CF_remHandlerMP =

           		{

          		 private["_object","_type","_id"];
           		_object = _this select 0;
		_type = _this select 1;
		_id = _this select 2;

           		if(isNull _object) exitWith {};

       	_object removeEventHandler [_type,_id];

       	}; 

and then this is the code executing it in the addAction script:


[[cargoBox1,"HandleDamage",0],"CF_remHandlerMP",true,true] call BIS_fnc_MP;

Any ideas?

Share this post


Link to post
Share on other sites

Seeing as you are using the EH just to negate damage why not just use allowDamage command instead?

I know this works as i have recently been using it.

//Make object invunerable
[[cargoBox1, false],"fnc_MPallowDamage",true,true] call BIS_fnc_MP;
//Make Object vunerable
[[cargoBox1, true],"fnc_MPallowDamage",true,true] call BIS_fnc_MP;

fnc_MPallowDamage = {
(_this select 0) allowDamage (_this select 1);
};

Share this post


Link to post
Share on other sites
Seeing as you are using the EH just to negate damage why not just use allowDamage command instead?

I know this works as i have recently been using it.

//Make object invunerable
[[cargoBox1, false],"fnc_MPallowDamage",true,true] call BIS_fnc_MP;
//Make Object vunerable
[[cargoBox1, true],"fnc_MPallowDamage",true,true] call BIS_fnc_MP;

fnc_MPallowDamage = {
(_this select 0) allowDamage (_this select 1);
};

because unfortunately allowdamage false is absolutely useless against big explosions :/

Share this post


Link to post
Share on other sites
because unfortunately allowdamage false is absolutely useless against big explosions :/

OK thanks ill have to check that out and rewrite some code.

You have to remove the event handler where ever the unit is local. If the crate is placed in the editor and those addEvents are in its init box then you need to run the removeEvent on the server.

[[cargoBox1,"HandleDamage",0],"CF_remHandlerMP",false,true] call BIS_fnc_MP;

Share this post


Link to post
Share on other sites
OK thanks ill have to check that out and rewrite some code.

You have to remove the event handler where ever the unit is local. If the crate is placed in the editor and those addEvents are in its init box then you need to run the removeEvent on the server.

[[cargoBox1,"HandleDamage",0],"CF_remHandlerMP",false,true] call BIS_fnc_MP;

The crate is created on the server through a script, so would I need to remove it on the server too? The problem with that is that it really needs to be removed in the addaction script.

Share this post


Link to post
Share on other sites

Ok heres a little example mission download here

Ive commented the code to explain whats going on rather than writing pages of explanation here:-

init.sqf

//This Function is initialised by both server and clients
CF_remHandlerMP = {

private["_object","_event","_type"];
_object = objectFromNetId (_this select 0);
_event = _this select 1;
_type = _this select 2;
_code = _this select 3;

//object, EH type, add/remove, code/ID
call compile format ["_object %1EventHandler [_event, _code];", _type];
};

//This Function is initialised by both server and clients
fnc_addActionMP = {
_object = objectFromNetId (_this select 0 );
_object addAction (_this select 1);
};

if (isServer) then {

//spawn crate
_crate = "B_supplyCrate_F" createVehicle getMarkerPos "mrk1";

//pause till after breifing to add actions to clients
sleep 1;

//add EH, on server via crates netId
[[netId _crate,"HandleDamage","add",{0}],"CF_remHandlerMP",false,true] call BIS_fnc_MP;

//add action to crate, on clients machine by crates netId
[[netId _crate, ["removeEH","actionRemoveEH.sqf"]],"fnc_addActionMP",true,true] call BIS_fnc_MP;


//For monitoring only
while {true} do {
	//set a variable on the crate with its damage and PV
	_crate setVariable ["damage",(damage _crate), true];
	sleep 2;
};
};


waitUntil {!(isNull player)};
//Monitor crate damage with a hint
_crate = nearestObject [player, "B_supplyCrate_F"];
player sideChat format ["crate = %1", _crate];
player sideChat format ["crateID = %1", netId _crate];
while {true} do {
hintSilent format ["Crate Damage\n%1", (_crate getVariable "damage")];
sleep 2;
};

actionRemoveEH.sqf

//get netId of object action was attached to
_crateID = netId (_this select 0);


systemChat format["Removing EH from : %1", _crateID];

//Remove EH on server (crate is local to the server) via crates netId
[[_crateID,"HandleDamage","remove",0],"CF_remHandlerMP",false,true] call BIS_fnc_MP;

Edited by Larrow

Share this post


Link to post
Share on other sites

Thanks very much for doing that for me, but that ammo box doesn't have an action on it nor does it have a handledamage eventhandler on it as i blew it up with a mine.

Share this post


Link to post
Share on other sites

How were you testing it? Ive tested this rigorously in Dedicated and Hosted and its worked flawlessly. It will NOT work properly under editor preview.

Share this post


Link to post
Share on other sites
How were you testing it? Ive tested this rigorously in Dedicated and Hosted and its worked flawlessly. It will NOT work properly under editor preview.

Well that explains that one then, heh.

Can I ask if you did it that way how would you also remove the action in the addaction script? Would I need to make another function to removeaction?

Edited by clydefrog

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  

×