Jump to content
Sign in to follow this  
BomboBombom

[Requesting assistance] MP Detailed kill messages to server log.

Recommended Posts

Hello there, I've been trying to make a script that will log player kills into the server logs. I've attempted to make a script that logs killer, victim, player id, location of both victim and killer at the time of the event, the direction they are facing and what weapon was used to kill with.

Should reactivate to be able to log again on all respawning that is a player controlled unit and preferably for all vehicles too.

http://forums.bistudio.com/showthread.php?139111-Player-Killed-By-Death-Message-to-Logs

I get the trigger to trigger, but it will not return the correct player name or id of killer or who was killed and neither does it seem to put the info into the log file, which I can not find.

Trigger:

- Triggers to anyone with condition true.

{ diag_log FORMAT ["Player: %1 UID: %2",_x,getPlayerUID _x]; _x addMPEventHandler ["MPKILLED",{ null = [_x] execVM "killed.sqf"}]; hint FORMAT ["%1 (%2)",_x,getPlayerUID _x]; } forEach units group player;

killed.sqf

private ["_victim","_killer"];

diag_log FORMAT ["%1 PID(%2) was killed by %3 PID(%4)",_killer,getPlayerUID _killer,_victim,getPlayerUID _victim];
hint FORMAT ["%1 PID(%2) was killed by %3 PID(%4)",_killer,getPlayerUID _killer,_victim,getPlayerUID _victim];

- It triggers on player death, but not AI kills with or without KILLER or MPKILLED event.

All help appreciated :-)

- Bomb.

Share this post


Link to post
Share on other sites

You fail to define "_victim" and "_killer" as they are not carried over as those variables how ever as a passed array. You would have to use select commands (I don't know which order the array is passed in but hypothetically speaking) like this......

_victim = _this select 0;
_killer = _this select 1;

Not sure if this is your problem, but that's all I saw.

Share this post


Link to post
Share on other sites
You fail to define "_victim" and "_killer" as they are not carried over as those variables how ever as a passed array. You would have to use select commands (I don't know which order the array is passed in but hypothetically speaking) like this......

_victim = _this select 0;
_killer = _this select 1;

Not sure if this is your problem, but that's all I saw.

Thanks for the spotting :-) Guess lack of sleep isn't good while trying to do these things. :p

~ Bombo.

---------- Post added at 06:00 ---------- Previous post was at 05:44 ----------

I do not see how the event handler is able to grab killer and killed, and it doesn't either. Are there any other event or more handlers that can be linked or used? (Multiplayer)

---------- Post added at 06:51 ---------- Previous post was at 06:00 ----------

* Trigger only works for one death.

* Trigger wont return a clean player name, it includes odd characters such as B 1-1-2 etc. Do not want :|

Must sleep. Night and thanks

Share this post


Link to post
Share on other sites

Init.sqf

TAG_KILLED_LOG = {
if (isServer) then 
{
	private ["_victim","_killer"];
	_victim = _this select 0;
	_killer = _this select 1;
	diag_log format ["=== MURDER LOG: [%1,%2] WAS SHOT BY [%3,%4]. TIME: %5 ===",name _victim,getPlayerUID _victim,name _killer,getPlayerUID _killer,round time];
};  
}; 

Init field of unit:

this addMPEventHandler ["MPKilled",{_this spawn TAG_KILLED_LOG;}];

I can confirm that this is working, even after death since I just tested it on a dedicated server. The only problem was that it was logging the death twice, not sure why. Might be becuase of some other addon that was running.

Server.rpt:

10:27:38 [1142,106.977,0,"XEH: PostInit Finished. State: _isClient=false, _isJip=false, _isDedClient=false, _isServer=true, _isDedServer=true, _playerCheckDone=true, _sp=false, _startInitDone=true, _postInitDone=true, _mpRespawn=true, _machineType=0, _sessionId=1, _level=0, _timeOut=false, _game=1, BIS_functions=L 1-1-A:1, group=L 1-1-A"]

10:27:50 WARNING: Function 'name' - Cuel is dead

10:27:50 "=== MURDER LOG: [ Cuel,<UID HERE>] WAS SHOT BY [Lev Soloveychik,]. TIME: 2 ==="

10:27:50 WARNING: Function 'name' - Cuel is dead

10:27:50 "=== MURDER LOG: [ Cuel,<UID HERE>] WAS SHOT BY [Lev Soloveychik,]. TIME: 2 ==="

10:28:03 WARNING: Function 'name' - Cuel is dead

10:28:03 "=== MURDER LOG: [ Cuel,<UID HERE>] WAS SHOT BY [Lev Soloveychik,]. TIME: 15 ==="

10:28:03 WARNING: Function 'name' - Cuel is dead

10:28:03 "=== MURDER LOG: [ Cuel,<UID HERE>] WAS SHOT BY [Lev Soloveychik,]. TIME: 15 ==="

10:28:15 WARNING: Function 'name' - Cuel is dead

10:28:15 "=== MURDER LOG: [ Cuel,<UID HERE>] WAS SHOT BY [Lev Soloveychik,]. TIME: 27 ==="

10:28:15 WARNING: Function 'name' - Cuel is dead

10:28:15 "=== MURDER LOG: [ Cuel,<UID HERE>] WAS SHOT BY [Lev Soloveychik,]. TIME: 27 ==="

EDIT:

Use this instead, everything goes into init.sqf. Works on both dedicated and listen server.


waitUntil {isDedicated or !isNull player};

if (isServer) then 
{
TAG_LOG_FUNC = 
{
	_victim = _this select 0;
	_killer = _this select 1;
	_killeruid = if (isPlayer _killer) then {getPlayerUID _killer} else {"(AI)"};
	diag_log text format ["KILLED LOG (TIME: %1) : [ %2 , %3 ] WAS KILLED BY [ %4 , %5 ]",round time,name _victim, getPlayerUID _victim, name _killer,_killeruid];
};

"TAG_MPKilledLog" addPublicVariableEventHandler
{
	_var = _this select 1;
	_var call TAG_LOG_FUNC;
};
};

if (local player) then 
{
player addEventHandler ["Killed", 
{
	if (isServer) then 
	{
		_this call TAG_LOG_FUNC;
	}
	else
	{
		TAG_MPKilledLog = _this; 
		publicVariableServer "TAG_MPKilledLog";
	}
}];
};

RPT:

10:47:39 [6571,215.772,0,"XEH: PostInit Finished. State: _isClient=false, _isJip=false, _isDedClient=false, _isServer=true, _isDedServer=true, _playerCheckDone=true, _sp=false, _startInitDone=true, _postInitDone=true, _mpRespawn=true, _machineType=0, _sessionId=1, _level=0, _timeOut=false, _game=1, BIS_functions=L 1-1-A:1, group=L 1-1-A"]

10:47:51 WARNING: Function 'name' - Cuel is dead

10:47:51 KILLED LOG (TIME: 5) : [ Cuel , <uiD>] WAS KILLED BY [ Lev Soloveychik , (AI) ]

10:48:04 WARNING: Function 'name' - SSG Cuel is dead

10:48:04 KILLED LOG (TIME: 12) : [ Cuel , <uid> ] WAS KILLED BY [ Lev Soloveychik , (AI) ]

Edited by cuel

Share this post


Link to post
Share on other sites

Oh wow, amazing. Thanks a whole bunch of tons of awesomeness.

I will be testing it in about 3 minutes :-)

Share this post


Link to post
Share on other sites

Can not find the log but it does work and trigger. Tested it with hint.

- Tested on dedicated and simply using local hosting through arma client.

Thanks a bunch again :O ~am poking script now for more detailed logging~

Edited by BomboBombom

Share this post


Link to post
Share on other sites

Thank you. Is there any way to log or send events besides the .rpt file?

---------- Post added at 03:22 ---------- Previous post was at 03:11 ----------

http://www.ofpec.com/COMREF/index.php?action=details&id=615&game=All

http://www.ofpec.com/COMREF/index.php?action=details&id=613&game=All

-- Am reading about these atm. Very little description on functions :|

Share this post


Link to post
Share on other sites

Not without using an addon (ARMA2net maybe?) or compiling your own .dll file

Share this post


Link to post
Share on other sites

I think I might have done something wrong here. Nothing at all shows in the RPT file and this shows in the scripts.log. Any suggestions would be appreciated.

14.09.2012 06:53:55: NAME (IP) GUID - #30 "call TAG_LOG_FUNC;
}
else
{
TAG_MPKilledLog = _this; 
publicVariableServer "TAG_MPKilledLog";
}
}];
};"

Share this post


Link to post
Share on other sites

Are you running 1.62?

Turn on -showScriptErrors

Share this post


Link to post
Share on other sites

Attempting to add the killers gun to the script, so I'm attempting to use damage handle to determine projectile source and then from that determine what gun the person killing used. Been delayed quite a bit in the progress. Will be trying simply identifying the projectiles first and see how that goes. Posting shortly.

- Player _x was shot with a _gun, fired by _y.

Rather than returning the info I need it makes me invincible though.

//waitUntil {isDedicated or !isNull player};
waitUntil {!isNull player};
hint "Start Script {";

//if (isServer) then if (isMultiplayer) then
{
TAG_LOG_FUNC = 
{
	_victim = _this select 0;
	_killer = _this select 3;
	_gun = _this select 4;
	_dmg = _this select 2;
	_kilGRD = mapGridPosition (getPos (_this select 3));
	_vicGRD = mapGridPosition (getPos (_this select 0));
	_killeruid = if (isPlayer _killer) then {getPlayerUID _killer} else {_killer};
	//[function][format] [[time]             [victim][uid]           [dmg]                 [grid][killer][uid] [projectile]      [grid][time]     [victim]      [uid]               [dmg] [grid]  [killer]    [uid]      [gun] [grid]             
	    hint text format ["%1 PLAYER KILL EVENT : %2 (%3) was hit for %4 damage and killed at %5 by %6 (%7) using %8 ammo in grid %9",round time,name _victim, getPlayerUID _victim,_dmg,_vicGRD,name _killer,_killeruid,_gun,_kilGRD];
	_victim removeMPEventHandler ["handleDamage", 0];
};

"TAG_MPKilledLog" addPublicVariableEventHandler
{
	_var = _this select 1;
	_var call TAG_LOG_FUNC;
};
};

if (local player) then 
{
player addEventHandler ["handleDamage", 
{
	//if (isServer) && (isPlayer (_this select 0)) && ((_this select 2) >= 0.9) then 
	if (isMultiplayer) && (isPlayer (_this select 0)) && ((_this select 2) >= 0.9) then 
	{
		hint "call TAG_LOG_FUNC";
		_this call TAG_LOG_FUNC;
	}
	else
	{
		TAG_MPKilledLog = _this; 
		publicVariableServer "TAG_MPKilledLog";
	}
}];
};
hint "} End Script";

Above is the code cuel provided but modified. Some changes made to test it out on lan host.

* It shouldn't.

Overwrite current damage handlers, simply add this to detect gun used to kill with.

* It should

Return gun used. (Currently returning ammo, but not even working because I can't die :p) Will try another method

! Will test using weaponState of triggering killer unit and old script. Should work fine.

Update

Can't get it to work. trrying to fix it

//waitUntil {isDedicated or !isNull player};
waitUntil {!isNull player};
hint "Start Script {";

//if (isServer) then 
if (isMultiplayer) then
{

TAG_LOG_FUNC = 
{
	//Player victim and murder person
	_victim = _this select 0;
	_killer = _this select 1;
	//Grid location of them perky persons
	_vicGRD = mapGridPosition (getPos (_this select 0));
	_kilGRD = mapGridPosition (getPos (_this select 1));
	//get gun
	_gun = weaponState (_this select 1); 
	//player UIDs
	_killeruid = if (isPlayer _killer) then {getPlayerUID _killer} else {_killer};
	_victimuid = if (isPlayer _killer) then {getPlayerUID _victim} else {_victim};
	//print or log data
	diag_log text format ["%1 PLAYER KILL EVENT == VICTIM %2 (%3) at grid %4. KILLER: %5 (%6) at grid %8 GUN: %7 ",round time,name _victim, getPlayerUID _victim,_vicGRD,name _killer,_killeruid,_kilGRD,_gun];
	//
	_victim removeMPEventHandler ["killed", 0];
};

"TAG_MPKilledLog" addPublicVariableEventHandler
{
	_var = _this select 1;
	_var call TAG_LOG_FUNC;
};
};

if (local player) then 
{
player addEventHandler ["Killed", 
{
	if (isServer) then 
	{
		_this call TAG_LOG_FUNC;
	}
	else
	{
		TAG_MPKilledLog = _this; 
		publicVariableServer "TAG_MPKilledLog";
	}
}];
};

above is test script.

See an error. Fixing and testing

"_gun = weaponState (_this select 1) select 0;" - was missing " select 0"

Edited by BomboBombom

Share this post


Link to post
Share on other sites

waitUntil {isDedicated or !isNull player};
//waitUntil {!isNull player};

if (isServer) then 
{

TAG_LOG_FUNC = 
{
	//Player victim and murder person
	_victim = _this select 0;
	_killer = _this select 1;

	//Grid location of them perky persons
	_vicGRD = mapGridPosition (getPos (_this select 0));
	_kilGRD = mapGridPosition (getPos (_this select 1));

	//get gun
	_gun = weaponState _killer; if (_gun select 0 == "Throw") then { _gun = _gun select 3 } else { _gun = _gun select 0 };

	//print or log data
	diag_log text format ["%1 PLAYER KILL EVENT == VICTIM %2 (%3) at grid %4. KILLER: %5 (%6) at grid %7 GUN: %8 ",round time,name _victim, getPlayerUID _victim,_vicGRD,name _killer,if (isPlayer _killer) then { getPlayerUID _killer } else { text format ["Other(%2)",typeOf _killer] },_kilGRD,_gun];
	_victim removeMPEventHandler ["Killed", 0];
};

"TAG_MPKilledLog" addPublicVariableEventHandler
{
	_var = _this select 1;
	_var call TAG_LOG_FUNC;
};

};

if (local player) then 
{
player addEventHandler ["Killed", 
{
	if (isServer) then 
	{
		_this call TAG_LOG_FUNC;
	}
	else
	{
		TAG_MPKilledLog = _this; 
		publicVariableServer "TAG_MPKilledLog";
	}
}];
};

- Tested with HINT using waitUntil {!isNull Player}; and "Killed" handler. MPKilled untested. Needs a test.

- Known problems (need a fix) :

a. If someone kills a person with a grenade and it is their last grenade or they switch weapon fast after throwing it. It will return the new weapon and not the grenade in the kill log. I'm not sure how to get the grenade kill event.

b. Doesn't return the correct values for "other" death source. Not looked into. Will attempt to fix.

Thanks for all the help! :-)) Would not be this far without it.

Cheers

Partial code from a file

Is

 _unit setVariable["PN_Fired",[_gun,_throw]]

then

	_gun = _killer getVariable ""PN_Fired"";
_gun = if (_gun select 0 == "Throw") then { text format ["%1(%2)",_gun select 1,_gun select 0] } else { _gun select 0 };
;

correct?

- Simply wondering if setVariable can be used as such.

Edited by BomboBombom

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  

×