Help me fix /pm bug
#1

And me again, with another bug.
Now there is PM bug on my server. When i tried to do /pm, it appears like this.

There is no names and the ID is weird. I tried to pm to myself (/pm 0 test)

Please help me fix it.
Here is the code
PHP код:
CMD:pm(playeridparams[])
{
     new 
string[256], giveplayeridreason[128];
    if(
sscanf(params"us[128]"giveplayeridreason)) return SendClientMessage(playeridCOLOR_GREY"[USAGE] /pm [ID] [Message]");
    if(!
IsPlayerConnected(giveplayerid)) return SendClientMessage(playeridCOLOR_GREY"That user is not connected!");
    if(
ToggleAllPM 1)
     {
        if(
togglepm[giveplayerid] == 0)
         {
              
SendClientMessage(playeridCOLOR_LIGHTGREENS"[PM]{FFFFFF} Player tersebut menutup Player Messenger");
              return 
1;
         }
        
format(stringsizeof(string), "(( PM from [%d] %s: %s ))"GetPlayerNameEx(playerid), playeridreason);
        
SendClientMessage(giveplayeridCOLOR_YELLOWstring);
        
format(stringsizeof(string), "(( PM to [%d] %s: %s ))"GetPlayerNameEx(giveplayerid), giveplayeridreason);
        
SendClientMessage(playeridCOLOR_YELLOWstring);
    }
    else
    {
        
SendClientMessage(playeridCOLOR_LIGHTGREENS"[SERVER]{FFFFFF} System Player Messenger has been turned off.");
    }
    return 
1;
}
CMD:togallpm(playeridparams[])
{
    if(!
gPlayerLogged{playerid}) return SendClientMessage(playeridCOLOR_GREY"You need to login first before using any command.");
    if(
AdminOnDuty[playerid] < 1) return SendClientMessage(playeridCOLOR_GREY"{007FFF}[IZIN] {FFFFFF}You must be on duty administrator to use this command");
    if(
PlayerInfo[playerid][pAdmin] < 1) return SendClientMessage(playeridCOLOR_GREY"{007FFF}[Izin] {FFFFFF}You are not authorized to use this command!");
    if(
ToggleAllPM == 0)
    {
        
ToggleAllPM 1;
        
SendClientMessageToAll(COLOR_LIGHTGREENS"[SERVER]{FFFFFF} System Player Message has been turned to [OFF].");
    }
    else
    {
        
ToggleAllPM 0;
        
SendClientMessageToAll(COLOR_LIGHTGREENS"[SERVER]{FFFFFF} System Player Message has been turned to [ON].");
    }
    return 
1;

THE /togpm
PHP код:
CMD:togpm(playerid,params[])
{
    if(
togglepm[playerid] == 1)
    {
        
SendClientMessage(playerid,0xff9900aa,"You have opened PM.");
        
togglepm[playerid] = 0;
    }
    else if(
togglepm[playerid] == 0)
    {
        
SendClientMessage(playerid,0xff9900aa,"You have closed PM.");
        
togglepm[playerid] = 1;
    }
    return 
1;

Reply
#2

"%s" is for all kind of values, "%d" is only for numeric values. You are using them wrong in your format statement.
You are using %d for name which is not numeric value. So it should be %s for name and %d for playerid.
Reply
#3

%s string %d integer %f float

https://sampwiki.blast.hk/wiki/Format
Reply
#4

Код:
format(string, sizeof(string), "(( PM from [%s] %s: %s ))", GetPlayerNameEx(playerid), playerid, reason); 
SendClientMessage(giveplayerid, COLOR_YELLOW, string); 
format(string, sizeof(string), "(( PM to [%s] %s: %s ))", GetPlayerNameEx(giveplayerid), giveplayerid, reason); 
SendClientMessage(playerid, COLOR_YELLOW, string);
This maybe?
Reply
#5

Quote:
Originally Posted by ShadowMortar
Посмотреть сообщение
This maybe?
No, because the %s where it needs to be %d will cause the same error.

It's because he's muddled the order of the params at the end of the format function.

Where they have
Код:
format(string, sizeof(string), "(( PM from [%d] %s: %s ))", GetPlayerNameEx(playerid), playerid, reason);
format(string, sizeof(string), "(( PM to [%d] %s: %s ))", GetPlayerNameEx(giveplayerid), giveplayerid, reason);
They should have...

Код:
format(string, sizeof(string), "(( PM from [%d] %s: %s ))", playerid, GetPlayerNameEx(playerid), reason); 
format(string, sizeof(string), "(( PM to [%d] %s: %s ))", giveplayerid, GetPlayerNameEx(giveplayerid), reason);
Reply
#6

Quote:
Originally Posted by Inn0cent
Посмотреть сообщение
"%s" is for all kind of values, "%d" is only for numeric values. You are using them wrong in your format statement.
You are using %d for name which is not numeric value. So it should be %s for name and %d for playerid.
Wow! Thank you. It works.

changed it to
Код:
format(string, sizeof(string), "(( PM from %s[%d]: %s ))", GetPlayerNameEx(playerid), playerid, reason);
format(string, sizeof(string), "(( PM to %s[%d]: %s ))", GetPlayerNameEx(giveplayerid), giveplayerid, reason);
Reply
#7

id should be a int and name should be a string
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)