SA-MP Forums Archive
Problem with warn-command! - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Problem with warn-command! (/showthread.php?tid=320598)



Problem with warn-command! - Twisted_Insane - 23.02.2012

'Sup y'all?

Well, I'm makin' a warn-command, which kicks the player when he gets more than 3 warnings, but it doesn't work! When I warn myself, there's written: 98/3 warnings, and the player won't after 3 times get kicked...Okay, I get no errors, but I still am not sure what to do:

PHP код:
    #define MAX_WARNINGS 3 
PHP код:
CMD:warn(playerid,params[])
{
    if(
PlayerInfo[playerid][pAdmin] >= 3)
    {
            new 
Target;
            new 
Reason[50];
           
// if(sscanf(params, "us[50]", Target)) SendClientMessage(playerid, COLOR_LIGHTBLUE, "USAGE: /warn [playerid] [reason]");
            
if(!sscanf(params"us[50]"TargetReason))
            {
                
//if(Target == playerid) return SendClientMessage(playerid, COLOR_RED, "SERVER: Cant perform this command on yourself!" );
                
if(!IsPlayerConnected(Target))
                    return 
SendClientMessage(playeridCOLOR_RED"ERROR: Player is not connected!");
                if(
PlayerInfo[Target][pAdmin] > PlayerInfo[playerid][pAdmin]) return SendClientMessage(playerid,COLOR_RED,"ERROR: You can't perform this command on Admins that are higher than your level!");
                
PlayerInfo[Target][Warnings]++;
                new 
tname[MAX_PLAYER_NAME];
                
GetPlayerName(Target,tname,sizeof(tname));
                new 
pname[MAX_PLAYER_NAME];
                
GetPlayerName(playerid,pname,sizeof(pname));
                new 
MyString[256];
                new 
TargetString[256];
                
WarnLog(Target);
                
format(MyString,sizeof MyString"You have warned %s! (Reason: %s) (Warnings: %d/%d)"tnameReasonPlayerInfo[Target][Warnings],MAX_WARNINGS);
                
format(TargetString,sizeof TargetString"Administrator %s has given %s a warning! Reason: %s (Warnings: %d/%d)"pnametnameReason,PlayerInfo[Target][Warnings],MAX_WARNINGS);
                
SendClientMessage(TargetCOLOR_REDTargetString);
                
SendClientMessageToAll(COLOR_YELLOWMyString);
                if(
PlayerInfo[Target][Warnings] == MAX_WARNINGS)
                {
                    new 
kstring[256];
                    new 
name[MAX_PLAYER_NAME];
                    
GetPlayerName(Target,name,sizeof(name));
                    
format(kstring,sizeof(kstring),"Player %s (ID:%d) got kicked! (Reason: Maximum warnings)"nameTarget);
                    
SendClientMessageToAll(COLOR_RED,kstring);
                    
PlayerInfo[Target][Warnings] = 0;
                    
WarnKick(Target);
                    
Kick(Target);
                }
            }
    }
    else return 
SendClientMessage(playerid,COLOR_RED,"ERROR: You must be level 3 to perform this command!");
    return 
1;

PHP код:
            stock WarnKick(Target)
            {
                    new 
File:Log fopen(warnPATHio_append);
                 new    
logData[128];
                 new 
name[MAX_PLAYER_NAME];
                 
GetPlayerName(Target,name,sizeof(name));
                new 
fTime[6];
                
getdate(fTime[0], fTime[1], fTime[2]);
                
gettime(fTime[3], fTime[4], fTime[5]);
                
format(logDatasizeof logData"[%02d/%02d/%04d || %02d:%02d:%02d]%s got kicked for reaching maximum warnings!\r\n"fTime[2], fTime[1], fTime[0], fTime[3], fTime[4], fTime[5], name);
                
fwrite(LoglogData);
                
fclose(Log);
                return 
1;
            }
            
            
stock WarnLog(Target)
            {
                  new 
File:Log fopen(warnPATHio_append);
                 new    
logData[128];
                 new 
name[MAX_PLAYER_NAME];
                 
GetPlayerName(Target,name,sizeof(name));
                new 
fTime[6];
                
getdate(fTime[0], fTime[1], fTime[2]);
                
gettime(fTime[3], fTime[4], fTime[5]);
                
format(logDatasizeof logData"[%02d/%02d/%04d || %02d:%02d:%02d]%s got warned!\r\n"fTime[2], fTime[1], fTime[0], fTime[3], fTime[4], fTime[5], name);
                
fwrite(LoglogData);
                
fclose(Log);
                return 
1;
            } 



Re: Problem with warn-command! - Tanush123 - 23.02.2012

Just to start off, why you use sscanf 2 times? And also sendclientmessage's string should be 128, you don't need to define 3 strings. Just use 1 like i did below.
pawn Код:
CMD:warn(playerid,params[])
{
    if(PlayerInfo[playerid][pAdmin] >= 3)
    {

            new Target;
            new Reason[50];
            if(sscanf(params, "us[50]", Target,Reason)) SendClientMessage(playerid, COLOR_LIGHTBLUE, "USAGE: /warn [playerid] [reason]");
             if(Target == playerid) return SendClientMessage(playerid, COLOR_RED, "SERVER: Cant perform this command on yourself!" );
                if(Target == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "ERROR: Player is not connected!");
                if(PlayerInfo[Target][pAdmin] > PlayerInfo[playerid][pAdmin]) return SendClientMessage(playerid,COLOR_RED,"ERROR: You can't perform this command on Admins that are higher than your level!");
                PlayerInfo[Target][Warnings] ++;
                new tname[MAX_PLAYER_NAME];
                GetPlayerName(Target,tname,sizeof(tname));
                new pname[MAX_PLAYER_NAME];
                GetPlayerName(playerid,pname,sizeof(pname));
                new MyString[128];
               WarnLog(Target);
                format(MyString,sizeof MyString, "You have warned %s! (Reason: %s) (Warnings: %d/%d)", tname, Reason, PlayerInfo[Target][Warnings],MAX_WARNINGS);
                SendClientMessageToAll(COLOR_YELLOW,MyString);
                format(MyString,sizeof(MyString), "Administrator %s has given %s a warning! Reason: %s (Warnings: %d/%d)", pname, tname, Reason,PlayerInfo[Target][Warnings],MAX_WARNINGS);
                SendClientMessage(Target, COLOR_RED, MyString);
                if(PlayerInfo[Target][Warnings] == MAX_WARNINGS)
                {
                    new name[MAX_PLAYER_NAME];
                    GetPlayerName(Target,name,sizeof(name));
                    format(MyString,sizeof(MyString),"Player %s (ID:%d) got kicked! (Reason: Maximum warnings)", name, Target);
                    SendClientMessageToAll(COLOR_RED,MyString);
                    WarnKick(Target);
                    Kick(Target);
                }

    }
    else return SendClientMessage(playerid,COLOR_RED,"ERROR: You must be level 3 to perform this command!");
    return 1;
}
This should work


Re: Problem with warn-command! - Twisted_Insane - 24.02.2012

This still doesn't work, I don't know why... I can warn myself infinite times, starting from 98/3, and I don't even have to put an ID or reason for warning!

Here my command again:

PHP код:
COMMAND:warn(playerid,params[])
{
    if(
PlayerInfo[playerid][pAdmin] >= 3)
    {
            new 
Target;
            new 
Reason[50];
           if(
sscanf(params"us[50]"Target,Reason)) SendClientMessage(playeridCOLOR_LIGHTBLUE"USAGE: /warn [playerid] [reason]");
            {
                
//if(Target == playerid) return SendClientMessage(playerid, COLOR_RED, "SERVER: Cant perform this command on yourself!" );
                
if(!IsPlayerConnected(Target))
                    return 
SendClientMessage(playeridCOLOR_RED"ERROR: Player is not connected!");
                if(
PlayerInfo[Target][pAdmin] > PlayerInfo[playerid][pAdmin]) return SendClientMessage(playerid,COLOR_RED,"ERROR: You can't perform this command on Admins that are higher than your level!");
                
PlayerInfo[Target][Warnings]++;
                new 
tname[MAX_PLAYER_NAME];
                
GetPlayerName(Target,tname,sizeof(tname));
                new 
pname[MAX_PLAYER_NAME];
                
GetPlayerName(playerid,pname,sizeof(pname));
                new 
MyString[128];
                
WarnLog(Target);
                
format(MyString,sizeof MyString"You have warned %s! (Reason: %s) (Warnings: %d/%d)"tnameReasonPlayerInfo[Target][Warnings],MAX_WARNINGS);
                
SendClientMessage(TargetCOLOR_REDMyString);
                
format(MyString,sizeof MyString"Administrator %s has given %s a warning! Reason: %s (Warnings: %d/%d)"pnametnameReason,PlayerInfo[Target][Warnings],MAX_WARNINGS);
                
SendClientMessageToAll(COLOR_YELLOWMyString);
                if(
PlayerInfo[Target][Warnings] == MAX_WARNINGS)
                {
                    new 
name[MAX_PLAYER_NAME];
                    
GetPlayerName(Target,name,sizeof(name));
                    
format(MyString,sizeof(MyString),"Player %s (ID:%d) got kicked! (Reason: Maximum warnings)"nameTarget);
                    
SendClientMessageToAll(COLOR_RED,MyString);
                    
PlayerInfo[Target][Warnings] = 0;
                    
WarnKick(Target);
                    
Kick(Target);
                }
            }
    }
    else return 
SendClientMessage(playerid,COLOR_RED,"ERROR: You must be level 3 to perform this command!");
    return 
1;




Re: Problem with warn-command! - Tanush123 - 25.02.2012

Oh it doesnt work, try doing like this
pawn Код:
CMD:warn(playerid,params[])
{
    if(PlayerInfo[playerid][pAdmin] >= 3)
    {

            new Target;
            new Reason[50];
            if(sscanf(params, "us[50]", Target,Reason)) SendClientMessage(playerid, COLOR_LIGHTBLUE, "USAGE: /warn [playerid] [reason]");
             if(Target == playerid) return SendClientMessage(playerid, COLOR_RED, "SERVER: Cant perform this command on yourself!" );
                if(Target == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "ERROR: Player is not connected!");
                if(PlayerInfo[Target][pAdmin] > PlayerInfo[playerid][pAdmin]) return SendClientMessage(playerid,COLOR_RED,"ERROR: You can't perform this command on Admins that are higher than your level!");
                PlayerInfo[Target][Warnings] ++;
                new tname[MAX_PLAYER_NAME];
                GetPlayerName(Target,tname,sizeof(tname));
                new pname[MAX_PLAYER_NAME];
                GetPlayerName(playerid,pname,sizeof(pname));
                new MyString[128];
               WarnLog(Target);
                format(MyString,sizeof MyString, "You have warned %s! (Reason: %s) (Warnings: %d/%d)", tname, Reason, PlayerInfo[Target][Warnings],MAX_WARNINGS);
                SendClientMessageToAll(COLOR_YELLOW,MyString);
                format(MyString,sizeof(MyString), "Administrator %s has given %s a warning! Reason: %s (Warnings: %d/%d)", pname, tname, Reason,PlayerInfo[Target][Warnings],MAX_WARNINGS);
                SendClientMessage(Target, COLOR_RED, MyString);
                if(PlayerInfo[Target][Warnings] == 3)
                {
                    new name[MAX_PLAYER_NAME];
                    GetPlayerName(Target,name,sizeof(name));
                    format(MyString,sizeof(MyString),"Player %s (ID:%d) got kicked! (Reason: Maximum warnings)", name, Target);
                    SendClientMessageToAll(COLOR_RED,MyString);
                    WarnKick(Target);
                    Kick(Target);
                }

    }
    else return SendClientMessage(playerid,COLOR_RED,"ERROR: You must be level 3 to perform this command!");
    return 1;
}



Re: Problem with warn-command! - Konstantinos - 25.02.2012

Twisted should edit his post that it solved. He PM me and I made it for him.


Re: Problem with warn-command! - HighPitchedVoice - 25.02.2012

CMD:warn(playerid, params[])
{
if (PlayerInfo[playerid][pAdmin] >= 2)
{
new string[128], giveplayerid, reason[64];
if(sscanf(params, "us[64]", giveplayerid, reason)) return SendClientMessageEx(playerid, COLOR_WHITE, "USAGE: /warn [playerid] [reason]");

if(IsPlayerConnected(giveplayerid))
{
if(PlayerInfo[giveplayerid][pAdmin] >= 2)
{
SendClientMessageEx(playerid, COLOR_GRAD2, "Admins can not be warned !");
return 1;
}
PlayerInfo[giveplayerid][pWarns] += 1;
if(PlayerInfo[giveplayerid][pWarns] >= 3)
{
new year, month,day;
new ip[32];
GetPlayerIp(giveplayerid,ip,sizeof(ip));
getdate(year, month, day);
format(string, sizeof(string), "AdmCmd: %s (IP: %s) was banned by %s (had 3 Warnings), reason: %s (%d-%d-%d)", GetPlayerNameEx(giveplayerid), ip, GetPlayerNameEx(playerid), reason,month,day,year);
Log("logs/ban.log", string);
format(string, sizeof(string), "AdmCmd: %s was banned by %s (had 3 Warnings), reason: %s", GetPlayerNameEx(giveplayerid), GetPlayerNameEx(playerid), reason);
SendClientMessageToAllEx(COLOR_LIGHTRED, string);
PlayerInfo[giveplayerid][pBanned] = 1;
AddBan(ip);
Kick(giveplayerid);
return 1;
}
new year, month, day;
getdate(year, month, day);
format(string, sizeof(string), "AdmCmd: %s was warned by %s, reason: %s", GetPlayerNameEx(giveplayerid), GetPlayerNameEx(playerid), reason);
ABroadCast(COLOR_LIGHTRED, string, 2);
format(string, sizeof(string), "AdmCmd: %s was warned by %s, reason: %s (%d-%d-%d)", GetPlayerNameEx(giveplayerid), GetPlayerNameEx(playerid), reason,month, day, year);
Log("logs/admin.log", string);
format(string, sizeof(string), "You were warned by %s, reason: %s", GetPlayerNameEx(playerid), reason);
SendClientMessageEx(giveplayerid, COLOR_LIGHTRED, string);
return 1;

}
}
else SendClientMessageEx(playerid, COLOR_GRAD1, "Invalid player specified.");
return 1;
}


Re: Problem with warn-command! - Tanush123 - 26.02.2012

Quote:
Originally Posted by HighPitchedVoice
Посмотреть сообщение
CMD:warn(playerid, params[])
{
if (PlayerInfo[playerid][pAdmin] >= 2)
{
new string[128], giveplayerid, reason[64];
if(sscanf(params, "us[64]", giveplayerid, reason)) return SendClientMessageEx(playerid, COLOR_WHITE, "USAGE: /warn [playerid] [reason]");

if(IsPlayerConnected(giveplayerid))
{
if(PlayerInfo[giveplayerid][pAdmin] >= 2)
{
SendClientMessageEx(playerid, COLOR_GRAD2, "Admins can not be warned !");
return 1;
}
PlayerInfo[giveplayerid][pWarns] += 1;
if(PlayerInfo[giveplayerid][pWarns] >= 3)
{
new year, month,day;
new ip[32];
GetPlayerIp(giveplayerid,ip,sizeof(ip));
getdate(year, month, day);
format(string, sizeof(string), "AdmCmd: %s (IP: %s) was banned by %s (had 3 Warnings), reason: %s (%d-%d-%d)", GetPlayerNameEx(giveplayerid), ip, GetPlayerNameEx(playerid), reason,month,day,year);
Log("logs/ban.log", string);
format(string, sizeof(string), "AdmCmd: %s was banned by %s (had 3 Warnings), reason: %s", GetPlayerNameEx(giveplayerid), GetPlayerNameEx(playerid), reason);
SendClientMessageToAllEx(COLOR_LIGHTRED, string);
PlayerInfo[giveplayerid][pBanned] = 1;
AddBan(ip);
Kick(giveplayerid);
return 1;
}
new year, month, day;
getdate(year, month, day);
format(string, sizeof(string), "AdmCmd: %s was warned by %s, reason: %s", GetPlayerNameEx(giveplayerid), GetPlayerNameEx(playerid), reason);
ABroadCast(COLOR_LIGHTRED, string, 2);
format(string, sizeof(string), "AdmCmd: %s was warned by %s, reason: %s (%d-%d-%d)", GetPlayerNameEx(giveplayerid), GetPlayerNameEx(playerid), reason,month, day, year);
Log("logs/admin.log", string);
format(string, sizeof(string), "You were warned by %s, reason: %s", GetPlayerNameEx(playerid), reason);
SendClientMessageEx(giveplayerid, COLOR_LIGHTRED, string);
return 1;

}
}
else SendClientMessageEx(playerid, COLOR_GRAD1, "Invalid player specified.");
return 1;
}
Learn to use [ p a w n ] and im sure you copyed this from a script right?