Ban command
#1

Ok my problem is when i ban player example ID 24 its say Hunud has been banned by administrator Hunud! What wrong lol its say my name not banned name player! :P sorry bad english

Код:
CMD:ban(playerid, params[])
{
        if(pInfo[playerid][AL] < 2) return SCM(playerid, red, "[ERROR] No allow!");
		{
            new PID; 
            new reason[64]; 
            new str[128]; 
            new Playername[MAX_PLAYER_NAME], Adminname[MAX_PLAYER_NAME]; 
            GetPlayerName(playerid, Adminname, sizeof(Adminname)); 
            GetPlayerName(PID, Playername, sizeof(Playername));
            if(sscanf(params, "us[64]", PID,reason)) return SCM(playerid, red, "[U]: /ban playerid) reason)"); 
            if(!IsPlayerConnected(PID))
            return SCM(playerid, -1, "[ERROR]: no player!");
            format(str, sizeof(str), "%s has been banned by Administrator %s Reason: %s", Playername, Adminname, reason);
            SCMToAll(-1, str); 
            Ban(PID);
        }
        return 1;
}
Reply
#2

You can either use/try this:
PHP код:
CMD:ban(playeridparams[])
{
    if(
pInfo[playerid][AL] < 2) return SCM(playeridred"[ERROR] No allow!");
    {
        new 
PID
        new 
reason[64]; 
        new 
str[128]; 
        new 
Playername[MAX_PLAYER_NAME], Adminname[MAX_PLAYER_NAME]; 
        if(
sscanf(params"us[64]"PID,reason)) return SCM(playeridred"[U]: /ban playerid) reason)"); 
        if(!
IsPlayerConnected(PID)) return SCM(playerid, -1"[ERROR]: no player!");
        
GetPlayerName(playeridAdminnamesizeof(Adminname)); 
        
GetPlayerName(PIDPlayernamesizeof(Playername));
        
format(strsizeof(str), "%s has been banned by Administrator %s Reason: %s"PlayernameAdminnamereason);
        
SCMToAll(-1str); 
        
Ban(PID);
    }
    return 
1;

or this: (Recommend)

PHP код:
CMD:ban(playeridparams[])
{
    if(
pInfo[playerid][AL] < 2) return SCM(playeridred"[ERROR] No allow!");
    {
        new 
PID
        new 
reason[64]; 
        new 
str[128]; 
        if(
sscanf(params"us[64]"PID,reason)) return SCM(playeridred"[U]: /ban playerid) reason)"); 
        if(!
IsPlayerConnected(PID)) return SCM(playerid, -1"[ERROR]: no player!");
        
format(strsizeof(str), "%s has been banned by Administrator %s Reason: %s"GetName(PID), GetName(playerid), reason);
        
SCMToAll(-1str); 
        
Ban(PID);
    }
    return 
1;
}
GetName(playerid)
{
    new 
itsPlayerName[MAX_PLAYER_NAME];
    
GetPlayerName(playeriditsPlayerNamesizeof(itsPlayerName));
    return 
itsPlayerName;

Reply
#3

This dont work same problem
Reply
#4

You are using the command with someone or on yourself? lol
It should work.
Reply
#5

Quote:
Originally Posted by oMa37
Посмотреть сообщение
You are using the command with someone or on yourself? lol
It should work.
No LOL

When i test it on player/id example 1 my id is 0 its still say Hunud has been banned by Hunud but i type his ID LOL
Reply
#6

Not sure what the issue is, But try to update your includes (zcmd & sscanf2)

EDIT:

Quote:
Originally Posted by Gotham
Посмотреть сообщение
To save the banned play you should make a variable and stuffs, I may be able to help if you show,
On TOpic:It might be because there are no other players, If there are SCM may be bugged , use SendClientMessageToAll , don't be lazy to type the whole thing!
Well i'll give you the version of mine
PHP код:
CMD:ban(playeridparams[])
{
      if(
pInfo[playerid][AL] < 2) return SendClientMessage(playeridred"[ERROR] No allow!"); 
     {
          new 
PID;
          new 
reason[64];
          new 
str[128];
          new 
Aname[MAX_PLAYER_NAME],Pname[MAX_PLAYER_NAME];
          if(
sscanf(params,"us[64]",PID,reason)) return SendClientMessage(playeridred"[U]: /ban playerid) reason)");
          if(!
IsPlayerConnected(PID)) return SendClientMessage(playerid, -1"[ERROR]: no player!");
          
format(str,sizeof(str),"%s has been banned by Administrator %s Reason: %s",Pname,Aname,reason);
          
SendClientMessageToAll(-1,str);
          
Ban(PID);
          
         
//Rest part when I get your variables!
    
}
    return 
1;

*facepalm*
Reply
#7

To save the banned play you should make a variable and stuffs, I may be able to help if you show,
On TOpic:It might be because there are no other players, If there are SCM may be bugged , use SendClientMessageToAll , don't be lazy to type the whole thing!
Well i'll give you the version of mine
PHP код:
CMD:ban(playeridparams[])
{
      if(
pInfo[playerid][AL] < 2) return SendClientMessage(playeridred"[ERROR] No allow!"); 
     {
          new 
PID;
          new 
reason[64];
          new 
str[128];
          new 
Aname[MAX_PLAYER_NAME],Pname[MAX_PLAYER_NAME];
          
GetPlayerName(playerid,Aname,sizeof(Aname));
          
GetPlayerName(PID,Pname,sizeof(Pname));
          if(
sscanf(params,"us[64]",PID,reason)) return SendClientMessage(playeridred"[U]: /ban playerid) reason)");
          if(!
IsPlayerConnected(PID)) return SendClientMessage(playerid, -1"[ERROR]: no player!");
          
format(str,sizeof(str),"%s has been banned by Administrator %s Reason: %s",Pname,Aname,reason);
          
SendClientMessageToAll(-1,str);
          
Ban(PID);
          
         
//Rest part when I get your variables!
    
}
    return 
1;

Reply
#8

Quote:
Originally Posted by Gotham
Посмотреть сообщение
To save the banned play you should make a variable and stuffs, I may be able to help if you show,
On TOpic:It might be because there are no other players, If there are SCM may be bugged , use SendClientMessageToAll , don't be lazy to type the whole thing!
Well i'll give you the version of mine
PHP код:
CMD:ban(playeridparams[])
{
      if(
pInfo[playerid][AL] < 2) return SendClientMessage(playeridred"[ERROR] No allow!"); 
     {
          new 
PID;
          new 
reason[64];
          new 
str[128];
          new 
Aname[MAX_PLAYER_NAME],Pname[MAX_PLAYER_NAME];
          if(
sscanf(params,"us[64]",PID,reason)) return SendClientMessage(playeridred"[U]: /ban playerid) reason)");
          if(!
IsPlayerConnected(PID)) return SendClientMessage(playerid, -1"[ERROR]: no player!");
          
format(str,sizeof(str),"%s has been banned by Administrator %s Reason: %s",Pname,Aname,reason);
          
SendClientMessageToAll(-1,str);
          
Ban(PID);
          
         
//Rest part when I get your variables!
    
}
    return 
1;

LOL this one wont work!
Reply
#9

Quote:
Originally Posted by Hunud
Посмотреть сообщение
This dont work same problem
the code provided by oMa should work as per my analysis you might doing something wrong somewhere just do a debug
like this add some debugging in that code
PHP код:
CMD:ban(playeridparams[]) 

    if(
pInfo[playerid][AL] < 2) return SCM(playeridred"[ERROR] No allow!"); 
    { 
        new 
PID;  
        new 
reason[64];  
        new 
str[128];  
        new 
Playername[MAX_PLAYER_NAME], Adminname[MAX_PLAYER_NAME];  
        if(
sscanf(params"us[64]"PID,reason)) return SCM(playeridred"[U]: /ban playerid) reason)");  
        if(!
IsPlayerConnected(PID)) return SCM(playerid, -1"[ERROR]: no player!"); 
        
printf("all condition passed");
        
GetPlayerName(playeridAdminnamesizeof(Adminname));  
        
GetPlayerName(PIDPlayernamesizeof(Playername)); 
        
printf("user =%s target=%s",Adminname,Playername);
        
format(strsizeof(str), "%s has been banned by Administrator %s Reason: %s"PlayernameAdminnamereason); 
        
SCMToAll(-1str);  
        
printf("message = %s",str);
        
Ban(PID); 
    } 
    
printf("out of if");
    return 
1

post what is displaying on server log now.
Reply
#10

To me it seems that the problem is here:
pawn Код:
GetPlayerName(PID, Playername, sizeof(Playername));
            if(sscanf(params, "us[64]", PID,reason)) return SCM(playerid, red, "[U]: /ban playerid) reason)");
You are using GetPlayerName(PID...); before you actually assign a value to PID. So basically when you use GetPlayerName it is most likely getting the name of playerid 0 instead of the target player.

I would restructure your command like below and give it another try:
pawn Код:
CMD:ban(playerid, params[])
{
    if(pInfo[playerid][AL] < 2) return SCM(playerid, red, "[ERROR] No allow!");
    {
        if(sscanf(params, "us[64]", PID,reason)) return SCM(playerid, red, "[U]: /ban playerid) reason)");
        if(!IsPlayerConnected(PID))
        return SCM(playerid, -1, "[ERROR]: no player!");
        new PID;
        new reason[64];
        new str[128];
        new Playername[MAX_PLAYER_NAME], Adminname[MAX_PLAYER_NAME];
        GetPlayerName(playerid, Adminname, sizeof(Adminname));
        GetPlayerName(PID, Playername, sizeof(Playername));          
        format(str, sizeof(str), "%s has been banned by Administrator %s Reason: %s", Playername, Adminname, reason);
        SCMToAll(-1, str);
        Ban(PID);
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)