Params keep showing without working [sscanf]
#1

Well , Here is the command :


PHP код:
dcmd_createtele(playeridparams[])
{
    if( 
PlayerInfo[playerid][pAdmin] >= 1339)
    {
        new 
name[32], string[128];
        new 
idx GetFreeTeleSlot();
        if(
sscanf(params"s[32]"name)) return SendClientMessage(playeridX11_GREEN"USAGE: /createtele [name]");
        
GetPlayerPos(playeridTeleInfo[idx][tX], TeleInfo[idx][tY], TeleInfo[idx][tZ]);
        
GetPlayerFacingAngle(playeridTeleInfo[idx][tA]);
        
TeleInfo[idx][tVW] = GetPlayerVirtualWorld(playerid);
        
TeleInfo[idx][tInt] = GetPlayerInterior(playerid);
        
strmid(TeleInfo[idx][tName], name0strlen(name), 32);
        
format(stringsizeof(string), "Teleport Created: [Name: %s | ID: %d | X: %.02f | Y: %.02f | Z: %.02f | A: %.02f | VW: %d | Int: %d]",
        
TeleInfo[idx][tName], idxTeleInfo[idx][tX], TeleInfo[idx][tY], TeleInfo[idx][tZ], TeleInfo[idx][tA], TeleInfo[idx][tVW], TeleInfo[idx][tInt]);
        
SendClientMessage(playeridX11_ORANGEstring);
        
SaveTeleports();
    }
    else
    {
        
SendClientMessage(playeridX11_RED"ERROR: You are not authorized to use this command.");
    }
    return 
1;

Now when I type /createtele anything

It just shows me /createtele [name]

Anyway to fix that ?

Help is appreciated , Thanks in advance.
Reply
#2

Actually a 'a' must be there when you use arrays.
From the sscanf tut
Код:
new
    arr[5];
sscanf("1 2 3 4 5", "a<s>[5]", arr);
Or remove that [32] and it will work and btw MAX_PLAYER_NAME is defined as 24.So instead of 32 you can use 24 and save some bytes.

Or this is even better and must be the best.

There is one more sscanf specifier "u" it will detect a playerid or a name(It finds out if it is a id or a name string) and return the id(better than strings).

From the sscanf tutorial by ******
Quote:
Originally Posted by ******
Specifier(s) Name Example values
i, d Integer 1, 42, -10
c Character a, o, *
l Logical true, false
b Binary 01001, 0b1100
h, x Hex 1A, 0x23
o Octal 045 12
n Number 42, 0b010, 0xAC, 045
f Float 0.7, -99.5
g IEEE Float 0.7, -99.5, INFINITY, -INFINITY, NAN, NAN_E
u User name/id (bots and players) ******, 0
q Bot name/id ShopBot, 27
r Player name/id ******, 42
Reply
#3

But the telename is not the playername it's a teleport name try it like this.

pawn Код:
dcmd_createtele(playerid, params[])
{
    if( PlayerInfo[playerid][pAdmin] >= 1339)
    {
        new name[32], string[128];
        new idx = GetFreeTeleSlot();
        if(isnull(params)) SendClientMessage(playerid, X11_GREEN, "USAGE: /createtele [name]");
        else
        {
            sscanf(params, "s[32]", name);
            GetPlayerPos(playerid, TeleInfo[idx][tX], TeleInfo[idx][tY], TeleInfo[idx][tZ]);
            GetPlayerFacingAngle(playerid, TeleInfo[idx][tA]);
            TeleInfo[idx][tVW] = GetPlayerVirtualWorld(playerid);
            TeleInfo[idx][tInt] = GetPlayerInterior(playerid);
            strmid(TeleInfo[idx][tName], name, 0, strlen(name), 32);
            format(string, sizeof(string), "Teleport Created: [Name: %s | ID: %d | X: %.02f | Y: %.02f | Z: %.02f | A: %.02f | VW: %d | Int: %d]",
            TeleInfo[idx][tName], idx, TeleInfo[idx][tX], TeleInfo[idx][tY], TeleInfo[idx][tZ], TeleInfo[idx][tA], TeleInfo[idx][tVW], TeleInfo[idx][tInt]);
            SendClientMessage(playerid, X11_ORANGE, string);
            SaveTeleports();
        }
    }
    else SendClientMessage(playerid, X11_RED, "ERROR: You are not authorized to use this command.");
   return 1;
}
Reply
#4

Do you know that I love you guys ? Repped+
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)