Jump to content
revv

[SOLVED] How to detect if player has killed enemy

Recommended Posts

If you are doing this in MP, the thing probably is here:

 

[1200,0] call HG_fnc_addOrSubCash;

 

Post the function here.

 

Because if the fucntion is using local variables for the client, then those variables will be only changed in the server, as the EOS unit is managed by server.

 

Additionally, Mr jshock solution will best suit your needs, as EOS is constantly spawning and despawning units, so you will have to care about adding the event handler to each unit instead of one, clean, and cpu saving, line of code.

 

As allways, thanks jshock, never knew about that EH

Share this post


Link to post
Share on other sites

As allways, thanks jshock, never knew about that EH

Bran-spankin new as of 1.55, I just happened to stumble on it one day when answering another thread, now I've been posting the hell out of it, probably posted it in a handful of threads by now :p. Really does allow for a "one and done" EH in the scope of dynamic missions and scripts.

Share this post


Link to post
Share on other sites

So.. this is solved? cuz I'm confused.

 

I too need to execute a script after a player kills an enemy AI (any spawned ai). I have the script i want to execute but am not sure how to execute it. In an example outside of the EOS, how would you do this? Like a vanilla mission with zeus spawnig ai. If a player kills one, then (execute my script).

Share this post


Link to post
Share on other sites

I think u could adapt the script provided by KK in this post

 

I modified it to ur needs:

if (isServer) then
{
 addMissionEventHandler ["EntityKilled", 
 {
  params ["_killed", "_killer"]

  if (side _killed == east) then
  {
   yourServerParamsArray execVM "yourServerSideScript.sqf";

  [yourClientParamsArray, "yourClientSideScript.sqf"] remoteExec ["execVM", (owner _killer)]; 
  };
 }];
};

yourServerSideScript.sqf - this is a script which u could execute on server (if needed)

yourServerParamsArray - this is the array of parameters which u wanna past to the server side script.

yourClientSideScript.sqf - this script is executed on the client who killed an east side entity

yourClientParamsArray - this is the array of parameters which u wanna past to the server side script.

Share this post


Link to post
Share on other sites

Thanks sarogahtyp

 

However, I do not need to pass params to my script. I only need to execute it when "a west player kills an east unit" 

 

I cannot make this work.

Share this post


Link to post
Share on other sites

Hey peoples really sorry for the late reply but was offline for a while and just started to get back into this again!
So after playing around for the last few days I got it all working perfect!
If you are using EOS to spawn enemies like I am then look in the EOS folders you will see the structure like this: eos\functions
In the functions folder there is a file called setSkill.sqf and right down on line 13 it adds an event handler to spawned units for his kill counter script, I hooked into this and changed some code.
The EOS_KILLCOUNTER.sqf is in the same folder (functions) I changed the code in there to this:

private ["_eosKills"];
_eosKills=server getvariable "EOSkillCounter";

	if (isnil "_eosKills") then {_eosKills=0;}else{
		_eosKills=server getvariable "EOSkillCounter";
				};		
				
_eosKills=_eosKills + 1;
server setvariable ["EOSkillCounter",_eosKills,true];

			[250,0] remoteExecCall ["HG_fnc_addOrSubCash",player,false];
		    hint format["%1 Paydirt! +$1000",profileName];

I changed the code from line 11 and down so instead of it adding and displaying a kill counter it pays out for kills using the currency system I am using.

Again sorry for the late reply and I hope this helps someone!

Share this post


Link to post
Share on other sites
On 19.07.2016 at 11:57 AM, revv said:

In the functions folder there is a file called setSkill.sqf and right down on line 13 it adds an event handler to spawned units for his kill counter script, I hooked into this and changed some code.

 

Have you had to provide any additional parameter to the addHandler in the setSkill.sqf for the script to know which player shot the bad guy (which player add the 250 cash to)?

I'm trying to hook up Arma's rank system and somehow count numbers of kills for each player and use setRank at different number of kills to promote players.

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

×