Ban Problem
#1

Hey!

Im having a problem with this code

Quote:

CMD:ban(playerid, params[]) //Ban a Player
{
new pID, reason[128], string[128], Year, Month, Day;
if(pInfo[playerid][pAdmin] < 1) return SendClientMessage(playerid, COLOR_RED, "ERROR: You are not authorized to use this command.");
if(sscanf(params, "us[128]", pID, reason)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /ban (Username/ID) (Reason)");
if(!IsPlayerConnected(pID)) return SendClientMessage(playerid, COLOR_RED, "ERROR: Wrong ID or that player is not connected.");
SetTimerEx("BanTimer", 10, 0, "d", pID);
format(string,sizeof(string), "{33CCFF}[BAN] %s {FFFFFF}has been banned from the server by {33CCFF}%s (%s).", pInfo[pID][pName], pInfo[playerid][pName], reason);
SendClientMessageToAll(-1, string);
getdate(Year, Month, Day);
pInfo[pID][pBanned] = 1;
strcpy(pInfo[pID][pBanAdmin], pInfo[playerid][pName], MAX_PLAYER_NAME);
pInfo[pID][pBanReason] = reason;
pInfo[pID][pBanD] = Day;
pInfo[pID][pBanM] = Month;
pInfo[pID][pBanY] = Year;
new query[256];
mysql_format(Database, query, sizeof(query), "INSERT INTO `banned` (`Username`, `Admin`, `Reason`, `Day`, `Month`, `Year`) VALUES ('%s', '%s', '%s', '%d', '%d', '%d')", pInfo[pID][pName], pInfo[pID][pBanAdmin], pInfo[pID][pBanReason], pInfo[pID][pBanD], pInfo[pID][pBanM], pInfo[pID][pBanY]);
mysql_query(Database, query);

//Textdraws
TextDrawShowForPlayer(playerid, BanBox1);
TextDrawShowForPlayer(playerid, BanBox2);
TextDrawShowForPlayer(playerid, BanOverview);
TextDrawShowForPlayer(playerid, BanAppeal);
TextDrawShowForPlayer(playerid, BanBox3);
PlayerTextDrawShow(playerid, PlayerName[playerid]);
PlayerTextDrawShow(playerid, AdminName[playerid]);
PlayerTextDrawShow(playerid, BanReason[playerid]);
PlayerTextDrawShow(playerid, BanDate[playerid]);

new PlayerNameTextdraw[256], AdminNameTextdraw[256], BanReasonTextdraw[256], BanDateTextdraw[256];
format(PlayerNameTextdraw, sizeof(PlayerNameTextdraw), "Player Name: %s", pInfo[pID][pName]);
format(AdminNameTextdraw, sizeof(AdminNameTextdraw), "Admin Name: %s", pInfo[playerid][pName]);
format(BanReasonTextdraw, sizeof(BanReasonTextdraw), "Reason: %s", reason);
format(BanDateTextdraw, sizeof(BanDateTextdraw), "Date: %d/%d/%d", pInfo[pID][pBanD], pInfo[pID][pBanM], pInfo[pID][pBanY]);
PlayerTextDrawSetString(pID, PlayerName[playerid], PlayerNameTextdraw);
PlayerTextDrawSetString(pID, AdminName[playerid], AdminNameTextdraw);
PlayerTextDrawSetString(pID, BanReason[playerid], BanReasonTextdraw);
PlayerTextDrawSetString(pID, BanDate[playerid], BanDateTextdraw);
TogglePlayerControllable(playerid, 0);
return 1;
}

Quote:

forward BanTimer(pID);
public BanTimer(pID)
{
Kick(pID);
}

It bans the guy who issued the command either way you turn it. But in MySQL it adds the guy you wanted to ban.
Reply
#2

Use the

Kick(pID); in the command at last instead of settimer!
Reply
#3

Don't kick the pID before you finish with everything.
and TogglePlayerControllable(playerid, 0); would freeze you.
Reply
#4

You are setting everything for playerid(person who executes the command). Instead of Pid(player who should be banned.)
PHP код:
TextDrawShowForPlayer(playeridBanBox1);
TextDrawShowForPlayer(playeridBanBox2);
TextDrawShowForPlayer(playeridBanOverview);
TextDrawShowForPlayer(playeridBanAppeal);
TextDrawShowForPlayer(playeridBanBox3);
PlayerTextDrawShow(playeridPlayerName[playerid]);
PlayerTextDrawShow(playeridAdminName[playerid]);
PlayerTextDrawShow(playeridBanReason[playerid]);
PlayerTextDrawShow(playeridBanDate[playerid]); 
As in the code above you are showing everything to playerid, who in this case is the admin banning the player.
Change playerid to pID.
Reply
#5

Is there even point for wasting so many textdraw slots for simple ban message, because with those slots you can build some good interface systems like cool inventory system, stats etc.
And first you don't need to try to build some badass roleplay server, but start from something simpler
PHP код:
#define scm SendClientMessage
#define func%0(%1) forward%0(%1); public%0(%1)
enum PlayerEnum{
    
pSid,
    
pAdmin,
    
pName[24],
    
bool:pLogged
};
CMD:ban(pidp[]){ //Ban a Player
    
new id,s[300];
    if(
pInfo[pid][pAdmin] < 1)return scm(pid,-1,"ERROR: You are not authorized to use this command.");
    if(
sscanf(p,"us[120]",id,p))return scm(pid,-1,"USAGE: /ban (Username/ID) (Reason)");
    if(!
IsPlayerConnected(id) || !pInfo[pid][pLogged])return scm(pid,-1,"ERROR: Wrong ID or that player is not connected.");
    
//just simple mysql request, you don't need to change enum info because he will be kicked anyway...
    
mysql_format(Database,s,sizeof(s),"UPDATE players SET banned='1',banstart=UNIX_TIMESTAMP(),bannersid='%d',banreason='%e' where sqlid='%d'",
    
pInfo[pid][pSid],p,pInfo[id][pSid]);
    
//mysql_query(Database, query); is used for threaded inline querys
    
mysql_tquery(Database,s);
    
format(s,sizeof(s),"{33CCFF}[BAN] %s {FFFFFF}has been banned from the server by {33CCFF}%s (%s)."pInfo[id][pName],pInfo[pid][pName],p);
    
SendClientMessageToAll(-1,s);
    
//first you set the value
    //i think player knows his name
    //format(s, sizeof(s), "Player Name: %s", pInfo[pID][pName]);
    //PlayerTextDrawSetString(id, PlayerName[id], s);
    
format(ssizeof(s), "Admin Name: %s"pInfo[pid][pName]);
    
PlayerTextDrawSetString(idAdminName[id], s);
    
format(ssizeof(s), "Reason: %s"p);
    
PlayerTextDrawSetString(idBanReason[id], s);
    
//no point for that when he knows todays date waste of information
    //format(s, sizeof(s), "Date: %d/%d/%d", pInfo[pID][pBanD], pInfo[pID][pBanM], pInfo[pID][pBanY]);
    //PlayerTextDrawSetString(id, BanDate[id], s);
    
    //then you show textdraw
    
TextDrawShowForPlayer(idBanBox1);
    
TextDrawShowForPlayer(idBanBox2);
    
TextDrawShowForPlayer(idBanOverview);
    
TextDrawShowForPlayer(idBanAppeal);
    
TextDrawShowForPlayer(idBanBox3);
    
//PlayerTextDrawShow(id, PlayerName[id]);
    
PlayerTextDrawShow(idAdminName[id]);
    
PlayerTextDrawShow(idBanReason[id]);
    
//PlayerTextDrawShow(id, BanDate[id]);
    
    //then you freeze
    
TogglePlayerControllable(id0);
    
    
//kick
    //little delay must be there, because information can then reace to player
    
SetTimerEx("KickPlayer",250,false,"d",id);    
    return 
1;
}
func KickPlayer(pid)return Kick(pid); 
Reply
#6

Quote:
Originally Posted by CodeStyle175
Посмотреть сообщение
Is there even point for wasting so many textdraw slots for simple ban message, because with those slots you can build some good interface systems like cool inventory system, stats etc.
And thats why you should destroy the textdraw if their are player textdraws and not in use.
for example when a player opens an inventory create the td's. When he closes it, destroy them. This way you will never reach the limit unless you have 1000 players using it on the same time lol.

Further its not a bad idea to create a textdraw for a banned player. This way you can provide info on the screen in a way you couldnt do with normal dialogs.
Reply
#7

Yea i also do that, but in this script i don't see where he destroys it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)