15.10.2017, 17:08
This is kind of confusing considering "Oban" = Offline ban, but you're not doing any checks too see if the account exists, you're only banning the player if they're online
Do you have an "Accounts Table"?
But maybe something like this?
Obviously you'll need to change it to match your stuff but that's pretty much the code needed.
I ain't got time to be guessing your table names, an making the whole command for you, so this is just an example of what will work
Do you have an "Accounts Table"?
But maybe something like this?
PHP код:
YCMD:oban(playerid, params[], help) {
if(help) {
SendClientMessage(playerid, X11_WHITE, "Bans an offline player");
return 1;
}
new username[(MAX_PLAYER_NAME*2)+1],reason[128];
if(!sscanf(params,"s[" #MAX_PLAYER_NAME "]s[128]",username,reason)) {
mysql_real_escape_string(username, username);
format(szquery, sizeof(szquery), "SELECT `username` FROM `accounts` WHERE `username` = '%s'",username);
mysql_function_query(SQL_Handle_Name, szquery, true, "OfflineBanPlayer", "dss",playerid,username,reason);
} else {
SendClientMessage(playerid, X11_WHITE, "USAGE: /oban [username] [reason]");
}
return 1;
}
forward OfflineBanPlayer(playerid, name[],reason[])
public OfflineBanPlayer(playerid, name[],reason[]) {
new accname[128];
new rows, fields;
cache_get_data(rows, fields);
if(rows < 1) {
SendClientMessage(playerid, X11_TOMATO_2, "* User not found");
return 1;
}
cache_get_row(0,0,accname);
format(banreason, sizeof(banreason), "INSERT INTO `playerbans` (`banned_by`, `banned_for`, `player_banned`, `player_ip`) VALUES ('%s', '%s', '%s')", adminName, reason, name);
mysql_query(banreason, MYSQL_ADD_BAN, playerid, connection);
format(szquery, sizeof(szquery), "[AdmWarn]: %s has OBanned %s: %s",GetPlayerName(playerid, accname), name, reason);
SendMessageToAdmins(msg);
return 1;
}
I ain't got time to be guessing your table names, an making the whole command for you, so this is just an example of what will work