2015-11-15 02:08:41 +00:00
/*
DMS_fnc_PlayerAwardOnAIKill
Created by eraser1
Gives (or removes) a player's respect/poptabs for killing an AI.
Usage:
[
_playerObj,
_unit,
_AISide,
_AIType,
_roadKilled
] call DMS_fnc_PlayerAwardOnAIKill;
Returns nothing
*/
if !(params
[
2016-06-07 03:47:15 +00:00
"_playerObj",
"_unit",
"_AISide",
"_AIType",
"_roadKilled"
2015-11-15 02:08:41 +00:00
])
exitWith
{
diag_log format ["DMS ERROR :: Calling DMS_fnc_PlayerAwardOnAIKill with invalid parameters: %1",_this];
};
2016-05-07 03:44:48 +00:00
private _playerUID = getPlayerUID _playerObj;
2015-11-15 02:08:41 +00:00
if ((!isNull _playerObj) && {(_playerUID != "") && {_playerObj isKindOf "Exile_Unit_Player"}}) then
{
2016-05-07 03:44:48 +00:00
private _moneyChange = missionNamespace getVariable [format ["DMS_%1_%2_MoneyGain",_AISide,_AIType],0];
private _repChange = missionNamespace getVariable [format ["DMS_%1_%2_RepGain",_AISide,_AIType],0];
private _rankChange = missionNamespace getVariable [format ["DMS_%1_%2_RankGain",_AISide,_AIType],0];
2016-02-17 23:58:05 +00:00
2016-02-17 08:11:17 +00:00
// Check for individually defined AI money/respect/rank.
2016-05-07 03:44:48 +00:00
private _unitMoney = _unit getVariable ["DMS_AI_Money",""];
private _unitRespect = _unit getVariable ["DMS_AI_Respect",""];
private _unitRank = _unit getVariable ["DMS_AI_Rank",""];
2016-02-17 23:58:05 +00:00
2015-11-15 02:08:41 +00:00
if !(_unitMoney isEqualTo "") then
{
_moneyChange = _unitMoney;
};
if !(_unitRespect isEqualTo "") then
{
_repChange = _unitRespect;
};
2016-02-17 23:58:05 +00:00
2016-02-17 08:11:17 +00:00
if !(_unitRank isEqualTo "") then
{
_rankChange = _unitRank;
};
2015-11-15 02:08:41 +00:00
2016-01-07 00:38:55 +00:00
if (_roadKilled && {_unit getVariable ["DMS_Diff_RepOrTabs_on_roadkill",DMS_Diff_RepOrTabs_on_roadkill]}) then
2015-12-24 19:45:20 +00:00
{
_moneyChange = missionNamespace getVariable [format ["DMS_%1_%2_RoadkillMoney",_AISide,_AIType],0];
_repChange = missionNamespace getVariable [format ["DMS_%1_%2_RoadkillRep",_AISide,_AIType],0];
2016-02-17 08:11:17 +00:00
_rankChange = missionNamespace getVariable [format ["DMS_%1_%2_RoadkillRank",_AISide,_AIType],0];
2015-12-24 19:45:20 +00:00
};
2016-02-17 23:58:05 +00:00
if ((_moneyChange!=0) || {_repChange!=0} || {_rankChange!=0}) then
2015-11-15 02:08:41 +00:00
{
2016-05-07 03:44:48 +00:00
private _playerMoney = _playerObj getVariable ["ExileMoney", 0];
private _playerRespect = _playerObj getVariable ["ExileScore", 0];
private _playerRank = _playerObj getVariable ["ExileHumanity", 0];
private _unitName = name _unit;
2015-11-15 02:08:41 +00:00
2016-01-07 00:38:55 +00:00
/*
2015-11-15 02:08:41 +00:00
if (DMS_DEBUG) then
{
2016-02-17 08:11:17 +00:00
format ["PlayerAwardOnAIKill :: Attempting to give %1 (%2) %3 poptabs and %4 respect and %5 rank. Player currently has %6 tabs and %7 respect and &8 rank.", name _playerObj, _playerUID, _moneyChange, _repChange, _rankChange,_playerMoney, _playerRespect,_playerRank] call DMS_fnc_DebugLog;
2015-11-15 02:08:41 +00:00
};
2016-01-07 00:38:55 +00:00
*/
2015-11-15 02:08:41 +00:00
if (_moneyChange!=0) then
{
2016-05-15 18:55:18 +00:00
private _distance = [];
2015-11-15 02:08:41 +00:00
// Set client's money
// I also make sure that they don't get negative poptabs
_playerMoney = (_playerMoney + _moneyChange) max 0;
_playerObj setVariable ["ExileMoney",_playerMoney];
2016-05-07 03:44:48 +00:00
private _msgType = "moneyReceivedRequest";
private _msgParams = [str _playerMoney, format ["killed %1",_unitName]];
2015-11-15 02:08:41 +00:00
if (_moneyChange<0) then
{
// Change message for players when they're actually LOSING poptabs
_msgType = "notificationRequest";
2016-05-12 11:29:02 +00:00
_msgParams = ["Whoops",[format ["Lost %1 poptabs for killing %2 AI!",abs _moneyChange,_AIType]]]; //changed wording, negative result is not necessarily a roadkill
2015-11-15 02:08:41 +00:00
// With the error message the money value won't be updated on the client, so I just directly PVC the value.
ExileClientPlayerMoney = _playerMoney;
(owner _playerObj) publicVariableClient "ExileClientPlayerMoney";
ExileClientPlayerMoney = nil;
};
if (DMS_Show_Kill_Poptabs_Notification) then
{
// Send notification and update client's money stats
[_playerObj, _msgType, _msgParams] call ExileServer_system_network_send_to;
}
else
{
// Player's money will already be updated for negative values, so let's not create unnecessary network traffic by sending another PVC
if (_moneyChange>0) then
{
ExileClientPlayerMoney = _playerMoney;
(owner _playerObj) publicVariableClient "ExileClientPlayerMoney";
ExileClientPlayerMoney = nil;
};
};
};
if (_repChange!=0) then
{
2016-05-07 03:44:48 +00:00
private _attributes = [[format ["KILLED %1",toUpper(_unitName)],_repChange]];
2015-11-15 02:08:41 +00:00
if (DMS_AIKill_DistanceBonusCoefficient>0) then
{
_distance = floor (_unit distance _playerObj);
if (_distance>DMS_AIKill_DistanceBonusMinDistance) then
{
2016-05-07 03:44:48 +00:00
private _distanceBonus = floor (_distance * DMS_AIKill_DistanceBonusCoefficient);
2015-11-15 02:08:41 +00:00
_attributes pushBack [format ["%1m RANGE BONUS",_distance], _distanceBonus];
_repChange = _repChange + _distanceBonus;
};
};
// Set client's respect
_playerRespect = _playerRespect + _repChange;
_playerObj setVariable ["ExileScore",_playerRespect];
if (DMS_Show_Kill_Respect_Notification) then
{
// Send frag message
[_playerObj, "showFragRequest", [_attributes]] call ExileServer_system_network_send_to;
};
// Send updated respect value to client
ExileClientPlayerScore = _playerRespect;
(owner _playerObj) publicVariableClient "ExileClientPlayerScore";
ExileClientPlayerScore = nil;
};
2016-04-15 02:20:26 +00:00
2016-02-17 23:58:05 +00:00
//DONKEYPUNCH CUSTOM KILL STAT ADD FOR AI KILL
2016-02-17 08:11:17 +00:00
if (DMS_Add_AIKill2DB) then
{
_newKillerFrags = _killer getVariable ["ExileKills", 0];
_newKillerFrags = _newKillerFrags + 1;
_killer setVariable ["ExileKills", _newKillerFrags];
format["addAccountKill:%1", getPlayerUID _killer] call ExileServer_system_database_query_fireAndForget;
ExileClientPlayerKills = _newKillerFrags;
(owner _playerObj) publicVariableClient "ExileClientPlayerKills";
ExileClientPlayerKills = nil;
};
2016-04-15 02:20:26 +00:00
2016-02-17 08:11:17 +00:00
//DONKEYPUNCH CUSTOM KILL RANK CHANGE FOR AI KILL
if (DMS_Enable_RankChange) then
{
if (_rankChange!=0) then
{
_playerRank = (_playerRank+_rankChange);
2016-02-19 06:39:00 +00:00
_killer setVariable ["ExileHumanity",_playerRank];
2016-02-17 08:11:17 +00:00
format["modifyAccountHumanity:%1:%2",_rankChange,getPlayerUID _killer] call ExileServer_system_database_query_fireAndForget;
ExileClientPlayerHumanity = _playerRank;
(owner _playerObj) publicVariableClient "ExileClientPlayerHumanity";
ExileClientPlayerHumanity = nil;
};
};
2016-04-15 02:20:26 +00:00
2015-11-15 02:08:41 +00:00
if (DMS_DEBUG) then
{
format ["PlayerAwardOnAIKill :: %1 (%2) awarded %3 poptabs and %4 respect for killing %5. Player's money is now %6, and respect is now %7. Roadkill: %8", name _playerObj, _playerUID, _moneyChange, _repChange, _unit, _playerMoney, _playerRespect, _roadKilled] call DMS_fnc_DebugLog;
};
// Update client database entry
format["setAccountMoneyAndRespect:%1:%2:%3", _playerMoney, _playerRespect, _playerUID] call ExileServer_system_database_query_fireAndForget;
2016-01-07 00:38:55 +00:00
if (DMS_Show_Party_Kill_Notification) then
{
2016-05-07 03:44:48 +00:00
private _group = group _playerObj;
private _members = units _group;
2016-01-07 00:38:55 +00:00
if (!(_group isEqualTo ExileGraveyardGroup) && {(count _members)>1}) then
{
2016-05-07 03:44:48 +00:00
private _msg = format
2016-01-10 01:54:50 +00:00
[
2016-05-07 03:44:48 +00:00
"%1 killed %2 from %3 meters away and received %4 poptabs, and %5 respect.",
2016-01-10 01:54:50 +00:00
name _playerObj,
2016-02-07 20:24:35 +00:00
_unitName,
2016-05-15 18:55:18 +00:00
if (_distance isEqualTo []) then {floor(_unit distance _playerObj)} else {_distance},
2016-01-10 01:54:50 +00:00
_moneyChange,
2016-05-07 03:44:48 +00:00
_repChange
2016-01-10 01:54:50 +00:00
];
2016-05-07 03:44:48 +00:00
if (DMS_Enable_RankChange) then
{
_msg = _msg + format[" (+%1 rank)", _rankChange];
};
2016-01-07 00:38:55 +00:00
{
_msg remoteExecCall ["systemChat", _x];
} forEach _members;
};
};
2015-11-15 02:08:41 +00:00
}
else
{
if (DMS_DEBUG) then
{
format ["PlayerAwardOnAIKill :: %1 (%2) was not awarded any poptabs or respect.", name _playerObj, _playerUID] call DMS_fnc_DebugLog;
};
};
}
else
{
if (DMS_DEBUG) then
{
format ["PlayerAwardOnAIKill :: No reward for non-player _playerObj: %1",_playerObj] call DMS_fnc_DebugLog;
};
2016-01-07 00:38:55 +00:00
};