/ban command in SQLite - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: /ban command in SQLite (
/showthread.php?tid=378306)
/ban command in SQLite -
[HK]Ryder[AN] - 17.09.2012
Here is my ban command
pawn Код:
CMD:ban(playerid, params[])
{
new targetid, reason[128], name[MAX_PLAYER_NAME];
if(Bit16_Get(g_AdminLevel, playerid) > 0)
{
if(sscanf(params, "us[128]", targetid, reason))
{
return SCM(playerid, COL_RED, "Usage: /ban <Playerid/Part of name> <Message>");
}
else
{
if(IsPlayerConnected(targetid))
{
new string[128];
format(string, sizeof(string), "%s has been banned from the server", GetPlayerName(targetid, name, sizeof(name)));
SendClientMessageToAll(COL_RED, string);
Bit1_Set(g_PlayerBanned, targetid, 1);
Ban(targetid);
}
}
}
else
{
SCM(playerid, COL_RED, "You need to be an admin to use this command!");
}
return 1;
}
My OnPlayerConnect
pawn Код:
public OnPlayerConnect(playerid)
{
new
Query[ 1300 ],
Queryban[1300],
DBResult: pBan,
DBResult: Result,
banname[MAX_PLAYER_NAME],
name[ MAX_PLAYER_NAME ]
;
GetPlayerName(playerid, name, sizeof(name));
Bit1_Set(g_PlayerLogged, playerid, false);
format(Queryban, sizeof(Queryban), "SELECT `BANNED` FROM `USERS` WHERE `BANNED` = '%d'", DB_Escape(banname));
pBan = db_query(Database, Queryban);
if(Bit1_Get(g_PlayerBanned, playerid)) return Ban(playerid);
format(Query, sizeof(Query), "SELECT `NAME` FROM `USERS` WHERE `NAME` = '%s'", DB_Escape(name));
Result = db_query(Database, Query);
if(db_num_rows(Result))
{
format(Query, sizeof(Query), "{FFFFFF}Welcome %s(%d){FFFFFF} to the server, you're registered\n\nPlease log in by typing your password.", name, playerid);
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_PASSWORD, "{FFFFFF}Server", Query, "Login", "Leave");
}
else
{
format(Query, sizeof(Query), "{FFFFFF}Welcome %s(%d){FFFFFF} to the server, you're not{FFFFFF} registered\n\nPlease log in by typing your password.", name, playerid);
ShowPlayerDialog(playerid, 0, DIALOG_STYLE_PASSWORD, "{FFFFFF}Server", Query, "Register", "Leave");
}
db_free_result(Result);
return 1;
}
The problem is if i ban someone and he/she rejoins. it simple asks them to type their password and he/she can play. Why is the ban part not working?
Re: /ban command in SQLite -
RedJohn - 17.09.2012
pawn Код:
if(Bit1_Get(g_PlayerBanned, playerid) == 1) return Ban(playerid);
Have you tried that?
EDIT: Same code just optimized.
pawn Код:
CMD:ban(playerid, params[])
{
new targetid, reason[128], name[MAX_PLAYER_NAME];
if(Bit16_Get(g_AdminLevel, playerid) > 0) return SCM(playerid, COL_RED, "You need to be an admin to use this command!");
if(sscanf(params, "us[128]", targetid, reason)) return SCM(playerid, COL_RED, "Usage: /ban <Playerid/Part of name> <Message>");
if(!IsPlayerConnected(targetid)) return SCM(playerid, COL_RED, "Player is offline.");
new string[128];
format(string, sizeof(string), "%s has been banned from the server", GetPlayerName(targetid, name, sizeof(name)));
SendClientMessageToAll(COL_RED, string);
Bit1_Set(g_PlayerBanned, targetid, 1);
Ban(targetid);
return 1;
}