Jump to content
Sign in to follow this  
nebulazerz

Need Help With A Killed Killer Event Handler

Recommended Posts

I have a working shop script for a multiplayer mission I am making that uses 'set' and 'get' variables to have money for each player and spend it at a shop. I am trying to make it so that when a player kills an enemy player they get money but I cant get this to work no matter how i change it. its telling me its missing a "[" but i dont think i am.

 

Edit: Arma is telling me line 11 in killed_killer. Error missing [

 

 

cashKillFunc.sqf is being run from the init and killed_killer.sqf is being run from the initServer

//cashKillfunc.sqf
cashonKillerFunction =
{
		_killer = (_this select 0);
		_cash = _killer getVariable["cash", 0];;
        _balance=_cash+500;
        hint "$+100";
		_killer setVariable["cash", _balance, true];
        
(uiNameSpace getVariable "myUI_DollarTitle") ctrlSetText format ["Money: $%1",_balance];
};
//killed_killer.sqf
//Get Cash when you kill
if (!isDedicated)then{
_unit=(_this select 0);

_unit addEventHandler ["killed", {
 _killer=    (_this select 1); 
 

if (isPlayer _killer)then{ 
		
       null =[_unit,],"cashonKillerFunction",_killer,false,true] call BIS_fnc_MP; 

     };
    
 _unit removeAllEventHandlers "killed"; 
        }];
    };

Share this post


Link to post
Share on other sites

You are actually missing a bracket.

The error is in line 12 of your posted snippet, look at the parameters.

 

Cheers

  • Like 1

Share this post


Link to post
Share on other sites

In killed_killer.sqf line 12

>null =[_unit,],"cashonKillerFunction",_killer,false,true] call BIS_fnc_MP;

Comma after _unit may destroy your script.

Share this post


Link to post
Share on other sites

In killed_killer.sqf line 12

>null =[_unit,],"cashonKillerFunction",_killer,false,true] call BIS_fnc_MP;

Comma after _unit may destroy your script.

It's not the comma. ;)

 

Cheers

  • Like 1

Share this post


Link to post
Share on other sites

Oh haha, I fixed that but now its telling me I have an undefined variable in expression line 5 _unit. But im defining the unit above. do i need to define it again?

//Get Cash when you kill
if (!isDedicated)then{
_unit=(_this select 0);

_unit addEventHandler ["killed", {
 _killer=    (_this select 1); 
 

if (isPlayer _killer)then{ 
		
       null =[_unit],["cashonKillerFunction",_killer,false,true] call BIS_fnc_MP; 

     };
    
 _unit removeAllEventHandlers "killed"; 
        }];
    };

Share this post


Link to post
Share on other sites

if i do it like this it still tells me im missing the "[" can someone help me out here and point out to me where the bracket is wrong?

//Get Cash when you kill
if (!isDedicated)then{
_unit=(_this select 0);

_unit addEventHandler ["killed", {
 _unit=(_this select 0);
 _killer=    (_this select 1); 
 

if (isPlayer _killer)then{ 
		
       null =[_unit,],"cashonKillerFunction",[_killer,false,true] call BIS_fnc_MP; 

     };
    
 _unit removeAllEventHandlers "killed"; 
        }];
    };

Share this post


Link to post
Share on other sites

_unit isn't defined within the eventHandler which is a different scope than the script itself, so you need to define it again.

Share this post


Link to post
Share on other sites

It's your BIS_fnc_MP line, that looks wrong.

 

What input is your function expecting and why aren't you using remoteExec? :)

Share this post


Link to post
Share on other sites

How would I use remoteExec instead? wouldnt that be global? I kind of reverse engineered other peoples issues and code to come up with what I have now for this, thats why it looks right but isnt working -_-. The input my function would be expecting is the killed event handler isnt it? selecting who killed and who got killed.?

Share this post


Link to post
Share on other sites

fyi the 'killed' eventhandler only fires if the unit is local. I recommend using MP eventhandler instead:

 

Put the following in init.sqf

player addMPEventHandler ["MPKilled",
	{
		private ["_killed","_killer"];
		
		_killed = param [0,objNull];
		_killer = param [1,objNull];
		
		if (player == _killer) then
		{
			[] call cashonKillerFunction;
		};
	}
];

and

cashonKillerFunction =
{
	private ["_balance"];
	
	_balance = (player getVariable ["cash", 0]) + 500;
	player setVariable ["cash", _balance, true];
        
	(uiNameSpace getVariable "myUI_DollarTitle") ctrlSetText format ["Money: $%1",_balance];
};

-Kane

www.arma3projectlife.com

  • Like 1

Share this post


Link to post
Share on other sites

Thanks Daphne, that is not giving me any errors back at startup but when i kill an enemy AI I placed, it doesnt give me money. Would I have to put the event handler in the init of all the AI also?

 

Edit: I tried putting the event handler in the AI, that also didnt work. I am trying to make it so you can kill enemies no matter if they are AI or Player. will the MPKilled still work for that?

 

Edit2: I figured it out I put this in the init of the AI and it worked.

 

Edit3: one problem I have run into now though is that money is still gained with friendly kills. I would add the if statement for that right into the event handler correct?

 

Edit4: I think this should work im trying it 

player addEventHandler ["Killed",
	{
		private ["_killed","_killer"];
		
		_killed = param [0,objNull];
		_killer = param [1,objNull];
		
		if (player == _killer) && !(side _killer isEqualTo side _killed) then
		{
			[] call cashonKillerFunction;
		};
	}
];

Share this post


Link to post
Share on other sites

 

Thanks Daphne, that is not giving me any errors back at startup but when i kill an enemy AI I placed, it doesnt give me money. Would I have to put the event handler in the init of all the AI also?

 

Edit: I tried putting the event handler in the AI, that also didnt work. I am trying to make it so you can kill enemies no matter if they are AI or Player. will the MPKilled still work for that?

 

Edit2: I figured it out I put this in the init of the AI and it worked.

 

Edit3: one problem I have run into now though is that money is still gained with friendly kills. I would add the if statement for that right into the event handler correct?

this addEventHandler ["Killed",
	{
		private ["_killed","_killer"];
		
		_killed = param [0,objNull];
		_killer = param [1,objNull];
		
		if (player == _killer) then
		{
			[] call cashonKillerFunction;
		};
	}
];

 

The code I gave you only works when killing other players, for AI you need to add that eventhandler to the invidual AI's. But be carefull with the normal 'killed' eventhandler, those will only fire where the unit is local which for mission placed objects is usually only the server and thus will only work in the editor   :)

 

edit: oh and for friendly kills just check the side

player addMPEventHandler ["MPKilled",
	{
		private ["_killed","_killer"];
		
		_killed = param [0,objNull];
		_killer = param [1,objNull];
		
		if (player == _killer) then
		{
                        if (side _killer == side _killed) exitwith {hint "You killed a friendly player! bad boy!";};
			[] call cashonKillerFunction;
		};
	}
];
  • Like 1

Share this post


Link to post
Share on other sites

This is giving me a bool error and not working when i shoot things, but its giving me no errors on start up. Do i need to use brackets here somewhere?

this addEventHandler ["Killed", 
 { 
  private ["_killed","_killer"]; 
   
  _killed = param [0,objNull]; 
  _killer = param [1,objNull]; 
   
  if (player == _killer) && !(side player isEqualTo side _killed) then 
  { 
   [] call cashonKillerFunction; 
  }; 
 } 
];

Share this post


Link to post
Share on other sites


this addEventHandler ["Killed",

{

private ["_killed","_killer"];

_killed = param [0,objNull];

_killer = param [1,objNull];

if ((player == _killer) && (side player != side _killed)) then

{

[] call cashonKillerFunction;

};

}

];

Share this post


Link to post
Share on other sites

The side check is throwing back no errors but its still giving me the money oddly for team kills and there is no hint popping up.

Share this post


Link to post
Share on other sites
this addEventHandler ["Killed", 
 { 
  private ["_killed","_killer"]; 
   
  _killed = param [0,objNull]; 
  _killer = param [1,objNull]; 
   
  if ((player == _killer) && (side player != side _killed)) then 
  { 
   [] call cashonKillerFunction; 
  }; 
 } 
];

Tried it like this also just gives me the money. Why is it skipping the side check no matter where we put it? does it need to go in the function instead since its server side? Does it not think the AI is on my "side" once i start  shooting at it? lol. I thought side was checking for east west ect..

this addEventHandler ["Killed",
	{
		private ["_killed","_killer"];
		
		_killed = param [0,objNull];
		_killer = param [1,objNull];
				
		if (player == _killer) then
				{
					[] call cashonKillerFunction;
                        if (side _killer == side _killed) exitwith {hint "You killed a friendly player! bad boy!";};
			
		};
	}
];

Share this post


Link to post
Share on other sites

As mentioned above, the eventhandler is local to the AI, so local to the server.  Hint is a command that has local only effects.  Meaning if the server runs hint, only the server sees it.  You'd need to change that hint to something like this:

if (side _killer == side _killed) exitWith {"You killed a friendly player! bad boy!" remoteExec["hint", _killer];};

That will run hint only where _killer is local.

Share this post


Link to post
Share on other sites

As mentioned above, the eventhandler is local to the AI, so local to the server.  Hint is a command that has local only effects.  Meaning if the server runs hint, only the server sees it.  You'd need to change that hint to something like this:

if (side _killer == side _killed) exitWith {"You killed a friendly player! bad boy!" remoteExec["hint", _killer];};

That will run hint only where _killer is local.

Its for some reason skipping this line all together in the script. No matter if I kill teamate or enemy it gives me the $500. There is never any message either

These all do the same thing 

this addEventHandler ["Killed",
	{
		private ["_killed","_killer"];
		
		_killed = param [0,objNull];
		_killer = param [1,objNull];
				
		if (player == _killer) then
				{
					
                        if (side _killer == side _killed) exitWith {"You killed a friendly player! bad boy!" remoteExec["hint", _killer];};
					 [] call cashonKillerFunction;
		};
	}
];
this addEventHandler ["Killed",
	{
		private ["_killed","_killer"];
		
		_killed = param [0,objNull];
		_killer = param [1,objNull];
				
		if (player == _killer) then
				{
					[] call cashonKillerFunction;
                        if (side _killer == side _killed) exitWith {"You killed a friendly player! bad boy!" remoteExec["hint", _killer];};
			
		};
	}
];

Share this post


Link to post
Share on other sites

You're running the "give me money" function before the side check, so that's working as written. :)

Share this post


Link to post
Share on other sites

You're running the "give me money" function before the side check, so that's working as written. :)

I tried

 

You're running the "give me money" function before the side check, so that's working as written. :)

so it would be like this then right? this is still giving me the money though. is it formatted wrong?

this addEventHandler ["Killed",
	{
		private ["_killed","_killer"];
		if (side _killer == side _killed) exitWith {"You killed a friendly player! bad boy!" remoteExec["hint", _killer];};
		
		_killed = param [0,objNull];
		_killer = param [1,objNull];
				
		if (player == _killer) then
		{
          						[] call cashonKillerFunction;
		};
	}
];

Share this post


Link to post
Share on other sites

Nope, that would give you an undefined error.  Put the check after the params and before the function call.

 

You also don't need the private line since param does that for you.

Share this post


Link to post
Share on other sites

Nope, that would give you an undefined error.  Put the check after the params and before the function call.

 

You also don't need the private line since param does that for you.

like this? 

 

Edit: it actually hasnt given me any errors with any of them, its just not working because its giving me money instead of a hint.

this addEventHandler ["Killed",
	{
		["_killed","_killer"];
				
		_killed = param [0,objNull];
		_killer = param [1,objNull];
		if (side _killer == side _killed) exitWith {"You killed a friendly player! bad boy!" remoteExec["hint", _killer];};
				
		if (player == _killer) then
		{
          						[] call cashonKillerFunction;
		};
	}
];

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  

×