Correct me if i'm wrong.
#1

Hey all,
I created a ban system and wanna load the banned status on player connect
Код:
public OnPlayerConnect(playerid)
{
	new query[256],pname[24],dialog[256];
	GetPlayerName(playerid, pname, 24);
	format(query, sizeof(query), "SELECT * FROM bans WHERE username = '%s'",pname);
	mysql_query(query);
	mysql_store_result();
	new row[128];
	new field[5][32];
	mysql_fetch_row_format(row, "|");
	explode(row, field, "|");
	mysql_free_result();
	Banned[playerid] = strval(field[1]);
	if(Banned[playerid] == 1)
	{
		format(dialog, sizeof(dialog), "You are banned from this server\nUsername : %s\nReason : %s\nBanning Admin : %s",pname,field[2],field[3]);
		ShowPlayerDialog(playerid, DIALOG_BANNED, DIALOG_STYLE_MSGBOX, "Banned", dialog, "Ok", "");
		Kick(playerid);
	}
	return 1;
}
This is my code, if its wrong to save Banned to the variable correct me.
NP : i use Westie explode function :
Код:
explode(const sSource[], aExplode[][], const sDelimiter[] = " ", iVertices = sizeof aExplode, iLength = sizeof aExplode[]) // Created by Westie
{
	new
		iNode,
		iPointer,
		iPrevious = -1,
		iDelimiter = strlen(sDelimiter);

	while(iNode < iVertices)
	{
		iPointer = strfind(sSource, sDelimiter, false, iPointer);

		if(iPointer == -1)
		{
			strmid(aExplode[iNode], sSource, iPrevious, strlen(sSource), iLength);
			break;
		}
		else
		{
			strmid(aExplode[iNode], sSource, iPrevious, iPointer, iLength);
		}

		iPrevious = (iPointer += iDelimiter);
		++iNode;
	}
	return iPrevious;
}
Thanks in advance for helping me
Reply
#2

Your code is a bit messy. It would be better to make a seperate function for that but when I script my ban system what I do is when a player is banned, I put his name, reason, admin who banned etc... and unban date (UNIX Timestamp).
Then when a player connects
I execute
Код:
SELECT * FROM bans WHERE username = '%s'
if the rows affected is equal to 0 then that player is not banned
if it's 1 (Anything more than that and you have a bug somewhere)
I check the current timestamp to the unban date, if current stamp is less than the unban stamp then that player is still banned if it's not then he is no longed banned and I run this
Код:
DELETE FROM bans WHERE username = '%s
It's more flexible I guess since you can save a lot more data than just banned or not.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)