revv 15 Posted April 19, 2016 Hello I am using the Enemy Occupation System by BangaBob so my enemy units are spawned dynamically and was wondering how I can detect each time a player has killed an opfor. Kill counter doesn't do the job as it seems it doesn't always detect a kill. Tested this all morning with a friend and after getting many kills it only showed about 4. Double checked each time and it was not detecting each kill. Anyway back on to topic so I have a currency system in place and I want players to get paid for each enemy kill but I can't work out the detection method.Any help appreciated.So I was advised to changed the topic title instead of making a new one, I worked out how to detect if player killed an enemy but I am still having trouble attaching the script to a dynamically spawned unit from EOS. JShock suggested using addMissionEventHandler but I could not work it out. Any help appreciated.In the EOS folder I found a script where apparently you can add custom code to units it spawns:setSkill.sqf _grp=(_this select 0); _skillArray=(_this select 1); _skillset = server getvariable _skillArray; { _unit = _x; { _skillvalue = (_skillset select _forEachIndex) + (random 0.2) - (random 0.2); _unit setSkill [_x,_skillvalue]; } forEach ['aimingAccuracy','aimingShake','aimingSpeed','spotDistance','spotTime','courage','reloadSpeed','commanding','general']; if (EOS_DAMAGE_MULTIPLIER != 1) then {_unit removeAllEventHandlers "HandleDamage";_unit addEventHandler ["HandleDamage",{_damage = (_this select 2)*EOS_DAMAGE_MULTIPLIER;_damage}];}; if (EOS_KILLCOUNTER) then {_unit addEventHandler ["killed", "null=[] execVM ""eos\functions\EOS_KillCounter.sqf"""]}; // ADD CUSTOM SCRIPTS TO UNIT HERE _unit addEventHandler ["killed", null=[_this select 0, _this select 1] execVM "scripts\killed.sqf"]; } forEach (units _grp); Line 15 is my custom bit but I can't get it to do anything, no errors come up it just does nothing.The other file:killed.sqf _unit = _this select 0; _killer = _this select 1; /* ----- Payout for killing enemy ----- */ if ((isPlayer _killer) && (side _unit == EAST)) then { [1200,0] call HG_fnc_addOrSubCash; player sideChat format ["Paydirt +1200 %1",(name player)]; }; Someone mentioned I'm not passing some needed info to the script, I think they mean maybe the [_this select 0,_this select 1]I just put it in and am testing now, will report back with findings but in the meantime if anyone can help me work it out I would appreciate it. Share this post Link to post Share on other sites
MKD3 27 Posted April 19, 2016 { if (side _x == "EAST") then { _x addEventHandler ["Killed", { [_this select 0, _this select 1] execVM "killed.sqf"; }]; }; } foreach allunits; 5th edit: Suppose I should add an explanation. All that code does is get every unit, check its side and then apply the event handler. Foreach wont execute the code to find the units like you have tried, so you have to either get an array of every unit, or just use allUnits and filter them. Also, code in killed.sqf is wrong. Try this: *Note the use of brackets, that is necessary. Not tested Hope it helps. if ((isPlayer _killer) && (side _unit == "EAST")) then {CODE}; 1 Share this post Link to post Share on other sites
revv 15 Posted April 19, 2016 Using the side command wrong. Try this: if ((isPlayer _killer) && (side _unit == EAST)) then {CODE}; Ok will do, however the error is in the init.sqf, last line Share this post Link to post Share on other sites
MKD3 27 Posted April 19, 2016 I have edited it because I totally glazed over what you asked because I saw a few errors in many places sorry lol. Share this post Link to post Share on other sites
jshock 513 Posted April 19, 2016 I'm going to put this here: https://community.bistudio.com/wiki/Arma_3:_Event_Handlers/addMissionEventHandler#EntityKilled 1 Share this post Link to post Share on other sites
revv 15 Posted April 19, 2016 I'm going to put this here: https://community.bistudio.com/wiki/Arma_3:_Event_Handlers/addMissionEventHandler#EntityKilled That is interesting and I'm sure I will make use of it in the future however I just got it working and was coming back to label the thread solved lol. Thanks JS anyway your input is always welcome!! Share this post Link to post Share on other sites
MKD3 27 Posted April 19, 2016 Mind posting how you solved it for others @revv? Share this post Link to post Share on other sites
revv 15 Posted April 19, 2016 Mind posting how you solved it for others @revv? Yeah its in the OP however it isn't quite fixed as I thought it was, after testing some more it has an undesired result. Still working on it and going to look into the link JShock posted Share this post Link to post Share on other sites
revv 15 Posted April 19, 2016 The topic itself was solved however I am going to start a new thread because the issue I am having now isn't exactly the topic question Share this post Link to post Share on other sites
sarogahtyp 1109 Posted April 19, 2016 Sorry but I think nothing is solved here. the fired EH fires if the unit it is added to is killed. u added the EH to players only. it will fire if player is killed and if it was a suicide it will count a team kill and a suicide and then substract the related money for both. but it should never count a kill... Correct me if I m wrong but I guess u should rename the topic as its not solved. @jshock what is the advantage of that mission EH u posted? Share this post Link to post Share on other sites
revv 15 Posted April 19, 2016 Sorry but I think nothing is solved here. the fired EH fires if the unit it is added to is killed. u added the EH to players only. it will fire if player is killed and if it was a suicide it will count a team kill and a suicide and then substract the related money for both. but it should never count a kill... Correct me if I m wrong but I guess u should rename the topic as its not solved. @jshock what is the advantage of that mission EH u posted? Well technically the question in the title was answered but I still have to figure out how to attach it to a dynamically spawned unit, if you know how to do this then please share :) Share this post Link to post Share on other sites
jshock 513 Posted April 19, 2016 @jshock what is the advantage of that mission EH u posted? It's a mission event handler. doesn't rely on attachment to any particular unit, so you can check to see if the unit is from side EAST and if it was killed by a player, or any other combo, but you don't have to add an EH to every unit, dynamically spawned or not. how to attach it to a dynamically spawned unit, if you know how to do this then please share :) I would assume somewhere in EOS you could find where that information could be placed, but I'm not too familiar with the system. 1 Share this post Link to post Share on other sites
revv 15 Posted April 19, 2016 It's a mission event handler. doesn't rely on attachment to any particular unit, so you can check to see if the unit is from side EAST and if it was killed by a player, or any other combo, but you don't have to add an EH to every unit, dynamically spawned or not. I would assume somewhere in EOS you could find where that information could be placed, but I'm not too familiar with the system. EOS is quite complex and I think I have found where to place custom code for spawned units, will post back if it's correct Share this post Link to post Share on other sites
sarogahtyp 1109 Posted April 19, 2016 What about that mission EH jshock posted? For me it looks like the best solution. And again, what u posted as a solution in ur first post is NOT a solution for the topic. it detects only if a player was killed and NOT if player killed anyone but himself... Share this post Link to post Share on other sites
revv 15 Posted April 19, 2016 What about that mission EH jshock posted? For me it looks like the best solution. And again, what u posted as a solution in ur first post is NOT a solution for the topic. it detects only if a player was killed and NOT if player killed anyone but himself... Topic title: How to detect if player has killed enemy In my first post I added and someone else posted: if ((isPlayer _killer) && (side _unit == EAST)) then That was the code I was looking for because all I found in older threads were not working for me, I kept getting an error. The NEXT part I need but was not asked in the title is how to add this to a dynamically spawned unit. JShock I have looked at that page and can't figure out what exactly I do with it I have tried this: init.sqf addMissionEventHandler ["EntityKilled", {nul = [_this select 0, _this select 1] execVM "scripts\killed.sqf"}]; and I keep getting the reward when an enemy kills me lol I checked the code and I have in one of the EOS scripts called setSkill.sqf if (EOS_DAMAGE_MULTIPLIER != 1) then {_unit removeAllEventHandlers "HandleDamage";_unit addEventHandler ["HandleDamage",{_damage = (_this select 2)*EOS_DAMAGE_MULTIPLIER;_damage}];}; if (EOS_KILLCOUNTER) then {_unit addEventHandler ["killed", "null=[] execVM ""eos\functions\EOS_KillCounter.sqf"""]}; // ADD CUSTOM SCRIPTS TO UNIT HERE if (EOS_KILLCOUNTER) then {_unit addEventHandler ["killed", "null=[] execVM ""scripts\killed.sqf"""]}; } forEach (units _grp); It's just the part of the script that refers to adding custom script and the only line I added was line 15 Share this post Link to post Share on other sites
revv 15 Posted April 19, 2016 Oh and my killed.sqf _unit = _this select 0; _killer = _this select 1; /* ----- Payout for killing enemy ----- */ if ((isPlayer _killer) && (side _unit == EAST)) then { [1200,0] call HG_fnc_addOrSubCash; player sideChat format ["Paydirt +1000 %1",(name player)]; }; Share this post Link to post Share on other sites
MKD3 27 Posted April 19, 2016 Are you using one or both of those above solutions? Cos the 2nd one is missing the parameters to send to killed.sqf Share this post Link to post Share on other sites
revv 15 Posted April 19, 2016 Are you using one or both of those above solutions? Cos the 2nd one is missing the parameters to send to killed.sqf Could you elaborate please? Share this post Link to post Share on other sites
MKD3 27 Posted April 19, 2016 _unit addEventHandler ["killed", "null=[] execVM ""scripts\killed.sqf"""] Is used in the EOS instead of _unit addEventHandler ["killed", {nul = [_this select 0, _this select 1] execVM "scripts\killed.sqf"}] Share this post Link to post Share on other sites
revv 15 Posted April 19, 2016 _unit addEventHandler ["killed", "null=[] execVM ""scripts\killed.sqf"""] Is used in the EOS instead of _unit addEventHandler ["killed", {nul = [_this select 0, _this select 1] execVM "scripts\killed.sqf"}] Ah thanks, I forgot the curly bracers lol Share this post Link to post Share on other sites
sarogahtyp 1109 Posted April 19, 2016 correct me if Im wrong but this EOS script which u use is executed on server only, isnt it? If i ve understood ur rewarding system correct then ur rewarding works client side. that means u will have the EHs for detect the killing at server but the reward system does not know about the kills because it is at client. If u go that fired EH way (I think to follow jshocks would be better) then u ve to use remoteExec to call ur killed.sqf client side... But idk much about EOS so I could be wrong. Share this post Link to post Share on other sites
revv 15 Posted April 19, 2016 correct me if Im wrong but this EOS script which u use is executed on server only, isnt it? If i ve understood ur rewarding system correct then ur rewarding works client side. that means u will have the EHs for detect the killing at server but the reward system does not know about the kills because it is at client. If u go that fired EH way (I think to follow jshocks would be better) then u ve to use remoteExec to call ur killed.sqf client side... But idk much about EOS so I could be wrong. Ok so should I use remoteExec or remoteExecCall? I was also thinking addMPeventHandler? Share this post Link to post Share on other sites
revv 15 Posted April 19, 2016 Ok so I have tried remoteExec, remoteExecCall and addMPEventHandler. None worked so I am stumped on this.This is the last one I tried:setSkill.sqf _unit addEventHandler ["killed", {null=[_this select 0, _this select 1] remoteExec ["scripts\killed.sqf", player, false]}]; Any help would be great! Share this post Link to post Share on other sites
revv 15 Posted April 19, 2016 After further investigation I found in the server log:A Nil object passed as a target to RemoteExec (Call) 'scripts\killed.sqf' Share this post Link to post Share on other sites
sarogahtyp 1109 Posted April 19, 2016 I m the last person one should ask for remoteExec cuz I was always wrong with it upto now. But try this: _unit addEventHandler ["killed", { [[_this select 0, _this select 1], "scripts\killed.sqf"] remoteExec ["execVM", (owner (_this select 1)) ]; }]; Share this post Link to post Share on other sites