MySQL BlueG CMD unwarn
#1

How to make a message (SendClientMessage) that the player has no warnings. E.g. The player has 3 warnings. Types 3 times CMD: /unwarn [Nick]. After entering the CMD 3 times, the player has no warnings. Enter the CMD 4 once the message shows "The player has no warnings".
Reply
#2

Made this real quick but should work. Make sure you edit the variables to match with your script.
Code:
CMD:unwarn(playerid, params[])
{
    if(!IsPlayerAdmin(playerid))
        return SendClientMessage(playerid, -1, "you are not authorized to use this command.");
    new targetid;
    if(sscanf(params, "u", targetid))
        return SendClientMessage(playerid, -1, "Usage: /unwarn [Nick]");
if(!PlayerInfo[targetid][pWarnings]) return SendClientMessage(playerid, -1, "That player has no warnings.");
PlayerInfo[targetid][pWarnings]--; SendClientMessage(playerid, -1 "You have successfully removed 1 warning from that player."); return 1; }
Reply
#3

Yes, but you still have to do it to check if the player has 0 warnings in the MySQL database.

How to change it to a newer version of MySQL BlueG.
Code:
stock MySQL_GetAccInt(column[], nick[])
{
	new string[128], value;
	format(string, sizeof(string), "SELECT `%s` FROM `accounts` WHERE `Nick` = '%s'", column, nick);
	mysql_query(string);
	mysql_store_result();
    if(mysql_num_rows())
    {
	   value = mysql_fetch_int();
    }
	mysql_free_result();
	return value;
}
EDIT: How the player is offline
Reply
#4

Help, please.
Code:
CMD:unwarn(playerid, params[])
{
	if(pInfo[playerid][pAdmin] == 1)
	{
		new string[256], name[MAX_PLAYER_NAME], query[150], rows;
			
		if(sscanf(params, "s[24]", name))
		{
			SendClientMessage(playerid, -1, "Usage: /unwarn [name]");
			return 1;
		}

		mysql_format(g_SQL, query, sizeof(query), "SELECT * FROM `accounts` WHERE `username` = '%e' LIMIT 0, 1", name);
		new Cache:result = mysql_query(g_SQL, query);
		cache_get_row_count(rows);

		if(!rows)
		{
		    SendClientMessage(playerid, -1, "This name does not exist or there is no prohibition under this name.");
		}

		mysql_format(g_SQL, query, sizeof(query), "SELECT `warns` FROM `accounts` WHERE `username` = '%e' LIMIT 1", name);
		mysql_tquery(g_SQL, query);

	 	for(new i = 0; i < rows; i ++)
		{
			if(pInfo[i][pWarn] >= 0) return SendClientMessage(playerid, -1, "The player has no warnings!");
			mysql_format(g_SQL, query, sizeof(query), "UPDATE `accounts` SET `warns` = `warns`-1 WHERE `id` = %d LIMIT 1", PlayerInfo[i][ID]);
			mysql_tquery(g_SQL, query);

	     	for(new x; x < MAX_PLAYERS; x++)
	     	{
		        if(pInfo[x][pAdmin] == 1)
		        {
					format(string, sizeof(string), "AdminWarn: %s(%d) unwarned %s", GetName(playerid), playerid, name);
					SendClientMessage(x, -1, string);
		        }
		    }
		}
		cache_delete(result);
	}
	else
	{
		SendClientMessage(playerid, -1, "You do not have access to the command!!");
	}
	return 1;
}
Reply
#5

PHP Code:
if(pInfo[i][pWarn] >= 0) return SendClientMessage(playerid, -1"The player has no warnings!"); 
Should be:

PHP Code:
if(pInfo[i][pWarn] == 0) return SendClientMessage(playerid, -1"The player has no warnings!"); 
https://sampwiki.blast.hk/wiki/Control_...ures#Operators
Reply
#6

The message pops up that the player has no warnings and the player has 3 warnings in the MySQL database.
Code:
CMD:unwarn(playerid, params[])
{
	if(pInfo[playerid][pAdmin] == 3)
	{
		new string[256], name[MAX_PLAYER_NAME], query[150], rows;
			
		if(sscanf(params, "s[24]", name))
		{
			SendClientMessage(playerid, -1, "Usage: /unwarn [name]");
			return 1;
		}

		mysql_format(g_SQL, query, sizeof(query), "SELECT * FROM `players` WHERE `username` = '%e' LIMIT 0, 1", name);
		new Cache:result = mysql_query(g_SQL, query);
		cache_get_row_count(rows);

		if(!rows)
		{
		    SendClientMessage(playerid, -1, "This name does not exist or there is no prohibition under this name.");
		}

		mysql_format(g_SQL, query, sizeof(query), "SELECT `warns` FROM `players` WHERE `username` = '%e' LIMIT 1", name);
		mysql_tquery(g_SQL, query);

	 	for(new i = 0; i < rows; i ++)
		{
			if(pInfo[i][pWarn] == 0) return SendClientMessage(playerid, -1, "The player has no warnings!");
			mysql_format(g_SQL, query, sizeof(query), "UPDATE `players` SET `warns` = `warns`-1 WHERE `id` = %d LIMIT 1", PlayerInfo[i][ID]);
			mysql_tquery(g_SQL, query);

	     	for(new x; x < MAX_PLAYERS; x++)
	     	{
		        if(pInfo[x][pAdmin] == 1)
		        {
					format(string, sizeof(string), "AdminWarn: %s(%d) unwarned %s", PlayerName(playerid), playerid, name);
					SendClientMessage(x, -1, string);
		        }
		    }
		}
		cache_delete(result);
	}
	else
	{
		SendClientMessage(playerid, -1, "You do not have access to the command!!");
	}
	return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)