Skip to content

Instantly share code, notes, and snippets.

@GeorgeDettmer
Last active August 29, 2015 14:12
Show Gist options
  • Save GeorgeDettmer/9ac06a14902641fbc83c to your computer and use it in GitHub Desktop.
Save GeorgeDettmer/9ac06a14902641fbc83c to your computer and use it in GitHub Desktop.
Naughty
/*
Parameters:
0 :: SCALAR: Player netId to which punishment applies (netId player)
1 :: SCALAR: Points to be deducted from current points (or default if player has not been punished before)
2 :: STRING(Optional): Reason for point deduction
Examples:
[netId player,10,"team killing"] call NAUGHTY
Note:
To have players kicked from the server by battleye add '4=IS_NAUGHTY' to your 'publicvariable.txt' filter?
*/
if isServer then {
NAUGHTY_POINTS_DEFAULT = 100; //Default starting point count
NAUGHTY_UIDS = [];
NAUGHTY_POINTS = [];
NAUGHTY = {
_obj = objectFromNetId (_this select 0);
if (typeName (_this select 1) == "BOOL" && {_this select 1}) exitWith {
(owner _obj) publicVariableClient "IS_NAUGHTY"
};
_uid = getPlayerUID _obj;
private "_idx";
if !(_uid in NAUGHTY_UIDS) then [{
_idx = NAUGHTY_UIDS pushBack _uid;
NAUGHTY_POINTS set [_idx,NAUGHTY_POINTS_DEFAULT-(_this select 1)]
},{
_idx = NAUGHTY_UIDS find _uid;
NAUGHTY_POINTS set [_idx,(NAUGHTY_POINTS select _idx)-(_this select 1)]
}];
_pts = NAUGHTY_POINTS select _idx;
if (_pts < 0) then [{
IS_NAUGHTY = nil
},{
IS_NAUGHTY = [_pts,(_this select 1)];
if (count _this == 3) then {
0 = IS_NAUGHTY pushBack toLower(_this select 2)
};
}];
(owner _obj) publicVariableClient "IS_NAUGHTY"
};
"PV__NAUGHTY" addPublicVariableEventHandler {
(_this select 1) call NAUGHTY;
};
};
if hasInterface then {
"IS_NAUGHTY" addPublicVariableEventHandler {
if (isNil 'IS_NAUGHTY') exitWith {
publicVariableServer (_this select 0);
endMission "END1";
};
if (typeName (_this select 1) == "ARRAY") then {
_this = _this select 1;
_points = [_this, 0, 0, [0]] call BIS_fnc_param;
_lost = [_this, 1, 1, [1]] call BIS_fnc_param;
systemChat format["NAUGHTY: You %1 %2 for %4, you have %3 left",
(if (_lost < 0) then [{_lost = _lost + (_lost*2); "gained"},{"lost"}]),
(if (_lost == 1) then [{"1 point"},{format["%1 points",_lost]}]),
(if (_points == 1) then [{"1 point"},{format["%1 points",_points]}]),
([_this, 2, "misbehaviour", [""]] call BIS_fnc_param)
]
};
};
if !isServer then {
NAUGHTY = {
PV__NAUGHTY = _this;
publicVariableServer "PV__NAUGHTY";
};
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment