Warns -
yvoms - 21.07.2016
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.");
}
Re: Warns -
Freaksken - 21.07.2016
What doesn't work ... Provide more info.
Re: Warns -
Konstantinos - 21.07.2016
- "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(playerid, params[])
{
if (pData[playerid][Admin] <= 3) return return SendClientMessage(playerid, COLOR_WHITE, "[Error]: You are not authorized to use this command.");
new lookupid, reason[100];
if (sscanf(params, "us[100]", lookupid, reason)) return SendClientMessage(playerid, COLOR_WHITE, "[Admin]:/warn [ID/Name] [Reason]");
if (lookupid == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_WHITE, "[Error]: This Player is not connected.");
new str[144];
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]++;
SavePlayerData(lookupid);
if (pData[lookupid][Warns] == 3) KickPlayer(lookupid);
return 1;
}
// function to delay the kick, you can specify the interval yourself - by default to 500 ms.
KickPlayer(playerid, ms = 500) return SetTimerEx("DelayedKick", ms, false, "i", playerid);
forward DelayedKick(playerid);
public DelayedKick(playerid) return Kick(playerid);
Re: Warns -
yvoms - 22.07.2016
thanks for the explenation i understand now