SA-MP Forums Archive
Command Help. - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Command Help. (/showthread.php?tid=163709)



Command Help. - CSMajor - 28.07.2010

Ok so I've got a command that is supposed to be like this:

COMMAND: /playername [ID]

and its supposed to respond like this:

RESPONSE: ID: [ID] | Player Name: [PLAYERNAME]

This is the code to do it:

pawn Код:
if (!strcmp("/playername", cmdtext, false, 11))
    {
        if(!cmdtext[11])return SendClientMessage(playerid,0xFF0000FF,"USAGE: /playername [ID]");
        {
        new str[128];
        new name;
        name = GetPlayerName(cmdtext[12],str,sizeof(str));
        SendClientMessage(playerid,0x00000000,"ID: "+cmdtext[12]+ " Is Player Name: "+name+".");
        return true;
        }
    }
But i cant figure out how to make it so it shows the Response, i have
pawn Код:
SendClientMessage(playerid,0x00000000,"ID: "+cmdtext[12]+ " Is Player Name: "+name+".");
As the response but i get an error saying:

Код:
error 001: expected token: "-string end-", but found "-identifier-"
I cant figure out how to combine strings with variables i used the plus oppertation but it is not correct. I get the error posted, when i try. How can i solve this issue?


Re: Command Help. - Kar - 28.07.2010

ui need another " in there


Re: Command Help. - Vince - 28.07.2010

You will need either sscanf or strtok for that. Search around a bit.


Re: Command Help. - Conroy - 28.07.2010

Use strtok, a lot easier.

pawn Код:
//OnPlayerCommandText
    new cmd[128], idx;
    cmd = strtok(cmdtext, idx);

    if(!strcmp("/playername", cmd)) {
        new tmp[128];
        tmp = strtok(cmdtext, idx);
        if(!IsPlayerConnected(strval(tmp))) return SendClientMessage(playerid, COLOR_RED, "ERROR: Invalid player.");
        new name[MAX_PLAYER_NAME];
        GetPlayerName(strval(tmp), name, sizeof(name));
        new message[128];
        format(message, sizeof(message), "RESPONSE: ID: %i | Player Name: %s", strval(tmp), name);
        SendClientMessage(playerid, COLOR_GREEN, message);
        return 1;
    }
Try that, if you get errors about not having strtok, put this at the bottom of your script:

pawn Код:
strtok(const string[], &index)
{
    new length = strlen(string);
    while ((index < length) && (string[index] <= ' '))
    {
        index++;
    }
 
    new offset = index;
    new result[20];
    while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
    {
        result[index - offset] = string[index];
        index++;
    }
    result[index - offset] = EOS;
    return result;
}



Re: Command Help. - iggy1 - 28.07.2010

I think sscanf is easier + faster here is a version of what you want that should work.

pawn Код:
if (!strcmp("/playername", cmdtext, false, 11))
{
    new id;
    if(sscanf(params,"d",id))return SendClientMessage(playerid,0xff0000FF,"USAGE: /playername [ID]");
    {
        if(id != INVALID_PLAER_ID)
        {
            new str[128];
            format(str,128,"ID:%i Is Player Name:%s",id,PlayerName(playerid));
            SendClientMessage(playerid,0xff0000FF,str);
            return true;
        }
        else return SendClientMessage(playerid,0xff0000FF,"ERROR: player not found!");
    }
}
and at bottom of script
pawn Код:
stock PlayerName(playerid)
{
    new pname[MAX_PLAYER_NAME];
    GetPlayerName(playerid,pname,sizeof(pname));
    return pname;
}
Note you will need the sscanf include or sscanf 2.0(plugin) for this method.


Re: Command Help. - CSMajor - 28.07.2010

I do not understand how to use sscanf, or strtok can someone breif me on how to use them??


Re: Command Help. - iggy1 - 28.07.2010

I couldn't explain that but look for tutorials that use them. might be a good idea to read though the topics.
Strtok: https://sampwiki.blast.hk/wiki/Strtok
sscanf: http://forum.sa-mp.com/showthread.ph...ghlight=sscanf

These are the places i learned from, i beleive its best to use sscanf as its faster.


Re: Command Help. - CSMajor - 28.07.2010

i cant get sscanf to work. i followed the plugins directions but it doesnt work

EDIT: ok ill use strtok becuase i cant install the plugin for sscanf.