English Automatic player ban in script

  • Auteur de la discussion Auteur de la discussion AltisLifeDev
  • Date de début Date de début
17/4/23
16
2
1
100
Inside life_server\Functions\Systems create a file fn_banplayer.sqf
[CODE lang="cpp" title="fn_banplayer.sqf"]/*
File: fn_banplayer.sqf
Description:
Bans a player and logs the event to the database.

Parameters:
0: OBJECT (Player to be banned)
1: STRING (Reason for the ban)
*/

// Validate parameters
params ["_cheater", "_banReason"];
if (!isPlayer _cheater) exitWith {};
if (isNil "_banReason") then { _banReason = "No reason provided"; };

_cheatID = getPlayerUID _cheater;
_cheaterName = name _cheater;

format['#exec ban "%1"', _cheatID] call TON_fnc_sendCommand;

diag_log format ["Player: %1 (UID: %2) has been banned for: %3", _cheaterName, _cheatID, _banReason];
private _query = format [ // Prepare SQL query
"INSERT INTO ban_log (cheater_name, cheater_uid, ban_reason) VALUES ('%1', '%2', '%3')",
_cheaterName, _cheatID, _banReason
];
[_query, 1, false] call DB_fnc_asyncCall;[/CODE]

As well fn_sendCommand.sqf
[CODE lang="cpp" title="fn_sendCommand.sqf"]/*
File: fn_sendCommand.sqf
Author: Extremo DevTeam
Description: Sends a server command with a password.
*/

private["_command","_password","_return"]; // Declare private variables
_command = _this; // Assign the input parameter (the command) to _command
_password = "command password Here"; // Set the server command password

// If the password is empty (this condition will never be true with the hard-coded password)
if (_password isEqualTo "") then {
_password = "empty"; // Set the password to "empty" if it was empty
};

// Execute the server command with the password and store the result in _return
_return = _password serverCommand _command;

_return;[/CODE]

Inside life_server\config.cpp add inside class TON_System
[CODE lang="cpp" title="config.cpp"]class banPlayer {};
class sendCommand {};[/CODE]

Now go to your mission file and open CfgRemoteExec.hpp and add
[CODE lang="cpp" title="CfgRemoteExec.hpp"]F(TON_fnc_banPlayer,SERVER)[/CODE]

Here is the table to add to your DB
Code:
CREATE TABLE `ban_log` (
    `id` INT NOT NULL AUTO_INCREMENT,
    `cheater_name` VARCHAR(255) NOT NULL,
    `cheater_uid` VARCHAR(20) NOT NULL,
    `ban_reason` TEXT NOT NULL,
    `ban_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (`id`)
);

Here is how to use the ban function:
Code:
[player,"Speed Hacking"] remoteExecCall ["TON_fnc_banPlayer", 2];

Here is an example:

C++:
if((getAnimSpeedCoef player) > 1.1) then {
        [profileName,getPlayerUID player,"speed_hack"] remoteExec ["SPY_fnc_cookieJar",RSERV];
        [profileName,"Speed Hacking"] remoteExec ["SPY_fnc_notifyAdmins",RCLIENT];
        [player,"Speed Hacking"] remoteExecCall ["TON_fnc_banPlayer", 2];
        player setAnimSpeedCoef 1;
        sleep 0.5;
    };