Jump to content
Sign in to follow this  
pogoman979

Adding fired eventhandler to another player's unit

Recommended Posts

Adding a fired eventhandler to another player's unit works until they respawn, after which you can add all the fired eventhandlers you want but none of them will work.

For clarification, i wish to add a fired eventhandler to another players avatar, i.e. player1 and player2 are in game, player1 would like to know whenever player2 fires their weapon. Adding a fired eventhandler to player2 from player1's game works until player2 respawns, in which case adding fired eventhandlers to player2 from player1's game does nothing.

The reason i am trying to do the above is to change the effects that come out of a gun when it is fired (for a mission i'm working on), for example making your gun shoot lightning and lasers beams etc. I have already successfully implemented these effects locally for the player, and have them appear for other players when that player triggers a fired eventhandler, but i can't get them to show up for other players when that player respawns, for the aforementioned reason.

i hope i've made myself clear, its a bit of a tricky issue to explain, was just wondering if anyone else has experienced this issue or knows a workaround. i assume BIS implemented muzzle flashes via fired eventhandlers for each player? or is that handled internally? Basically all i am trying to achieve here is to add particle effects to the weapon muzzle everytime it is fired, on each machine (as particle effects are always local).

perhaps a MPFired eventhandler is needed?

oh and btw, i am aware that i could broadcast to other clients whenever the player unit fires, but i think broadcasting a fired event over the network everytime the player fires a shot would create some bandwidth issues :p

Share this post


Link to post
Share on other sites

Well, if it works until respawn, then maybe the problem isn't what the EH does, but is it run at all?

How/where do you readd the EH and have you tried with a simple hint or diag_log that it's actually firing?

Share this post


Link to post
Share on other sites

adding it via:

onKeyPress = { 
_key     = _this select 1; 
_handled = false;
switch _key do { 		
	//T
	case 20: {
		if (!alive cursorTarget) exitWith { deleteVehicle cursorTarget };
		player groupchat str cursorTarget;
		cursorTarget addEventHandler ["fired", {
			_unit = _this select 0;
			player groupchat format["%1 fired", _unit];	
		}];						
	};
};	
_handled; 	
};

waitUntil { !(isNull (findDisplay 46)) }; 
(findDisplay 46) displaySetEventHandler ["KeyDown", "_this call onKeyPress"];

So basically i can add it to any unit i want, whenever, as long as that unit is revealed and in my crosshairs. i also tried adding it to the units via triggers and via respawn eventhandlers for the unit that then broadcast the code to all other players etc, theres a million ways to do it and none of them have worked.

Share this post


Link to post
Share on other sites

What about somthing like this maybe link it to a functions that will run EH script im not sure im a newbie:butbut:?

resync.sqf

// this addEventHandler ["killed", {null0 = [] execVM "resync.sqf"}];<-----each unit init

//wait for player respawn

waitUntil {alive player};

EH_1 synchronizeObjectsAdd [player1];

EH_1 synchronizeObjectsAdd [player2];

EH_1 synchronizeObjectsAdd [player3];

EH_1 synchronizeObjectsAdd [player4];

EH_1 synchronizeObjectsAdd [player5];

EH_1 synchronizeObjectsAdd [playeretc];

Share this post


Link to post
Share on other sites

Just tested like this, seemed to work:

fncAddEH = { _this addeventhandler ["fired",{(_this select 0) call fncDoEH}]; };
fncDoEH = { player sidechat format["%1 fired",_this] };
"addEH" addpublicvariableeventhandler { (_this select 1) call fncAddEH; };
{
 _x call fncAddEH;
 _x addeventhandler ["respawn",{addEH = (_this select 0); publicvariable "addEH"}];
} foreach playableunits;

_ehFired.utes.rar

You could also use the MPRespawn I guess.

Share this post


Link to post
Share on other sites

Just tested and that does not work either. I assume you tried it with a playable ai unit? it works fine with ai but not with actual human players. In case you're wondering i run two instances of arma on the same machine and have them both join a local game (one of the copies needs to have an invalid cdkey to avoid "cd key in use" error), in order to test with "multiple" players.

Share this post


Link to post
Share on other sites

Tested on dedi with a friend. I got sidechat message about remote unit firing, even after we both had died few times.

Share this post


Link to post
Share on other sites

damnit, i can't get it to work. Just tried on a dedi too :/. Maybe trying it with two instances of arma on the one machine is the problem.

Cheers for going out of your way to help shk, it is greatly appreciated. I will have to test this at some stage with an actual other player.

btw sorry about the late reply i went out.

Share this post


Link to post
Share on other sites

just tested it and I get the chat message that I have fired while in MP. If you are testing in SP editor maybe thats why you dont see the message?

How would I go about using this in perhaps only a certain area? Would it work in a trigger and change "} foreach playableunits in thislist;" ?(I have no scripting knowledge other than the search button). Also I would like to trigger a script that we be a simple waypoint to search and destroy the unit that fired

_unit = _this select 0;
_group = group _unit;

_waypoint0 = _group addwaypoint[ARMY,0];
_waypoint0 setwaypointtype"SAD"; 
_waypoint0 setWaypointCombatMode "RED";
_waypoint0 setWaypointBehaviour "COMBAT";

or the building patrol script.

Share this post


Link to post
Share on other sites
_EHfirednear1 = this addEventHandler ["firednear", {_this exec "firednear.sqs"}]

This seems to work in the init of a unit.

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  

×