#1

I'm trying to make a warning system, that kicks a player when he reaches 3 warns.
I've currently wrote this, but it seems like the code is not working.
Код:
CMD:warn(playerid, params[])
{
	new str[128], lookupid, reason[128];
    if(pData[playerid][Admin] > 3)
        {
            if(sscanf(params, "us",lookupid, reason)) return SendClientMessage(playerid ,COLOR_WHITE, "[Admin]:/warn [ID/Name] [Reason]");
            if(!IsPlayerConnected(lookupid)) return SendClientMessage(playerid, COLOR_WHITE, "[Error]: This Player is not connected.");
            format(str, sizeof(str), "[Admin]: %s(%d) has warned %s(%d) Reason: %s", GetName(playerid), playerid, GetName(lookupid),lookupid,reason);
            SendClientMessageToAll(COLOR_WHITE, str);
            pData[lookupid][Warns] + 1;
            SavePlayerData(lookupid);
            return 1;
        }
        if(pData[lookupid][Warns] = 3)
       	{
       		Kick(lookupid);
       		return 1;
       	} 
        else return SendClientMessage(playerid, COLOR_WHITE, "[Error]: You are not authorized to use this command.");
}
Reply
#2

What doesn't work ... Provide more info.
Reply
#3

- "s" specifier needs the size specified.
- Check if it is equal to INVALID_PLAYER_ID than calling IsPlayerConnected.
- Don't declare all the variables at the top but rather when needed.
- You returned a value so the kick would never happen.
- As of 0.3x, you have to delay the kick to send any client messages/show any dialog to the player who gets kicked.
- Comparing values is == and not a single one.
- This has no effect:
pawn Код:
pData[lookupid][Warns] + 1;
So fixing the above, becomes:
PHP код:
CMD:warn(playeridparams[])
{
    if (
pData[playerid][Admin] <= 3) return return SendClientMessage(playeridCOLOR_WHITE"[Error]: You are not authorized to use this command.");
    new 
lookupidreason[100];
    if (
sscanf(params"us[100]"lookupidreason)) return SendClientMessage(playeridCOLOR_WHITE"[Admin]:/warn [ID/Name] [Reason]");
    if (
lookupid == INVALID_PLAYER_ID) return SendClientMessage(playeridCOLOR_WHITE"[Error]: This Player is not connected.");
    new 
str[144];
    
format(strsizeof(str), "[Admin]: %s(%d) has warned %s(%d) Reason: %s"GetName(playerid), playeridGetName(lookupid), lookupidreason);
    
SendClientMessageToAll(COLOR_WHITEstr);
    
pData[lookupid][Warns]++;
    
SavePlayerData(lookupid);
    if (
pData[lookupid][Warns] == 3KickPlayer(lookupid);
    return 
1;
}
// function to delay the kick, you can specify the interval yourself - by default to 500 ms.
KickPlayer(playeridms 500) return SetTimerEx("DelayedKick"msfalse"i"playerid);
forward DelayedKick(playerid);
public 
DelayedKick(playerid) return Kick(playerid); 
Reply
#4

thanks for the explenation i understand now
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)