private messages with zcmd and sscanf2(solved)
#1

Hi im trying to make a private message command using zcmd and sscanf im fairly new scripter and cant c what is wrong. The problem is the message is always cut short i have tryed changing the size of the arrays but always the same outcome here is the code.

pawn Код:
COMMAND:pm(playerid,params[])
{
    new ID;
    new PMstring[128];//the PM
    new string[128];//string used for SendClientMessage
    new Iname[MAX_PLAYER_NAME], Pname[MAX_PLAYER_NAME];
   
    sscanf(params,"is",ID,PMstring);
    format(PMstring,sizeof(PMstring),PMstring);
    GetPlayerName(ID,Iname,sizeof(Iname));
    GetPlayerName(playerid,Pname,sizeof(Pname));
   
    if(sscanf(params,"is",ID))return SendClientMessage(playerid,red,"Usage: /pm (id) (message)");
    if(sscanf(params,"s",PMstring))return SendClientMessage(playerid,red,"Usage: /pm (id) (message)");
    if(ID == INVALID_PLAYER_ID)return SendClientMessage(playerid,red,"Player Not Found");
   
     format(string,sizeof(string),"PM from %i[%s]: %s",playerid,Pname,PMstring);
    SendClientMessage(ID,0xFFD720FF,string);
    format(string,sizeof(string),"PM To %s: %s",Iname,PMstring);
    SendClientMessage(playerid,0xFFD720FF,string);
    PlayerPlaySound(ID,1085,0.0,0.0,0.0);
    return 1;
}
Thanks in advance probably a few things wrong any help is much appreciated.
Reply
#2

pawn Код:
COMMAND:pm(playerid,params[])
{
    new ID;
    new PMstring[128];//the PM
    new string[128];//string used for SendClientMessage
    new Iname[MAX_PLAYER_NAME], Pname[MAX_PLAYER_NAME];
   

    if (sscanf(params, "dz", id, PMstring))
    //'d' is the ID datatype (integer) and will store the number the player wrote inside ID
    //'z', which stands for optional string (wiki.sa-mp.com/wiki/Fast_Commands#Data_types), is for saving reasons (strings which can have multiple spaces (sscanf parts strings by spaces unless you choose your own delimiter))
    //and will save everything, what the player typed after the id, inside 'PMstring'
    {//sscanf returns 1 (or -1) if the operation didn't end succesfully (the user made a mistake)
        SendClientMessage(playerid,red,"Usage: /pm (id) (message)");
        return 1;
    }
   
    GetPlayerName(ID,Iname,sizeof(Iname));
    GetPlayerName(playerid,Pname,sizeof(Pname));
   
  format(string,sizeof(string),"PM from %i[%s]: %s",playerid,Pname,PMstring);
    SendClientMessage(ID,0xFFD720FF,string);
    format(string,sizeof(string),"PM To %s: %s",Iname,PMstring);
    SendClientMessage(playerid,0xFFD720FF,string);
    PlayerPlaySound(ID,1085,0.0,0.0,0.0);
    return 1;
}
Reply
#3

Quote:
Originally Posted by dice7
pawn Код:
COMMAND:pm(playerid,params[])
{
    new ID;
    new PMstring[128];//the PM
    new string[128];//string used for SendClientMessage
    new Iname[MAX_PLAYER_NAME], Pname[MAX_PLAYER_NAME];
   

    if (sscanf(params, "dz", id, PMstring))
    //'d' is the ID datatype (integer) and will store the number the player wrote inside ID
    //'z', which stands for optional string (wiki.sa-mp.com/wiki/Fast_Commands#Data_types), is for saving reasons (strings which can have multiple spaces (sscanf parts strings by spaces unless you choose your own delimiter))
    //and will save everything, what the player typed after the id, inside 'PMstring'
    {//sscanf returns 1 (or -1) if the operation didn't end succesfully (the user made a mistake)
        SendClientMessage(playerid,red,"Usage: /pm (id) (message)");
        return 1;
    }
   
    GetPlayerName(ID,Iname,sizeof(Iname));
    GetPlayerName(playerid,Pname,sizeof(Pname));
   
  format(string,sizeof(string),"PM from %i[%s]: %s",playerid,Pname,PMstring);
    SendClientMessage(ID,0xFFD720FF,string);
    format(string,sizeof(string),"PM To %s: %s",Iname,PMstring);
    SendClientMessage(playerid,0xFFD720FF,string);
    PlayerPlaySound(ID,1085,0.0,0.0,0.0);
    return 1;
}
Wouldnt 'u' be better? As its for PlayerID/PartOfName
Reply
#4

It differs from person to person. Some even use 'i', but I stick to 'd', since the 'part of name' thing in 'u' never worked for me
Reply
#5

Thanks both helped alot, ill have to read more documentation on sscanf thanks again

EDIT: btw im using sscanf2 and 'z' is depreciated. or so it says on the console window. just edited title sorry.

Just incase people need this in future here is the code for PM's that works for sscanf2.

pawn Код:
COMMAND:pm(playerid,params[])
{
    new ID;
    new PMstring[128];//the PM
    new string[128];//string used for SendClientMessage
    new Iname[MAX_PLAYER_NAME], Pname[MAX_PLAYER_NAME];

    if (sscanf(params, "ds[128]", ID, PMstring))
     {
      SendClientMessage(playerid,red,"Usage: /pm (id) (message)");
      return 1;
    }

    GetPlayerName(ID,Iname,sizeof(Iname));
    GetPlayerName(playerid,Pname,sizeof(Pname));

     format(string,128,"PM from %i[%s]: %s",playerid,Pname,PMstring);
    SendClientMessage(ID,0xFFD720FF,string);
    format(string,128,"PM To %s: %s",Iname,PMstring);
    SendClientMessage(playerid,0xFFD720FF,string);
    PlayerPlaySound(ID,1085,0.0,0.0,0.0);
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)