SA-MP Forums Archive
omg xD strtok 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: omg xD strtok help! (/showthread.php?tid=246064)



omg xD strtok help! - Rivera - 02.04.2011

Hi guys. I thought trying to use strtok... only once I think. So, I made 2 cmds. Should these work IG (I have not installed GTA :P)?

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    new cmd[128], idx;
    cmd = strtok(cmdtext, idx);
   
    if(strcmp(cmd, "/pay", true) == 0) {
        new tmp[128], tmp2[128];
        tmp = strtok(cmdtext, idx);
        tmp2 = strtok(cmdtext, idx);
   
    if(!strlen(tmp)) {
        SendClientMessage(playerid, COLOR_ORANGE, "Syntax Error: /pay [playerid] [amount]");
        return 1;
    }
   
    if(!strlen(tmp2)) {
        SendClientMessage(playerid, COLOR_ORANGE, "Syntax Error: /pay [playerid] [amount]");
        return 1;
    }
   
    new id, v;
    id = strval(tmp);
    v = strval(tmp2);
   
    if(GetPlayerMoney(playerid) < v) {
        SendClientMessage(playerid, COLOR_GREY, "You can't afford that much!");
        return 1;
    }
   
    new name[MAX_PLAYER_NAME], name2[MAX_PLAYER_NAME], string[128];
    GetPlayerName(playerid, name, MAX_PLAYER_NAME);
    GetPlayerName(id, name2, MAX_PLAYER_NAME);
    format(string, sizeof(string), "You have sent $%i to %s", v, name2);
    SendClientMessage(playerid, COLOR_TAN, string);
    format(string, sizeof(string), "You have received $%i from %s", v, name);
    SendClientMessage(id, COLOR_TAN, string);
    GivePlayerMoney(id, v);
    GivePlayerMoney(playerid, 0 - v);
    return 1;
}

    if(strcmp(cmd, "/sethealth", true) == 0) {
        new tmp[128], tmp2[128];
        tmp = strtok(cmdtext, idx);
        tmp2 = strtok(cmdtext, idx);
       
    if(!strlen(tmp)) {
        SendClientMessage(playerid, COLOR_ORANGE, "Syntax Error: /sethealth [playerid] [amount]");
        return 1;
    }
   
    if(!strlen(tmp2)) {
        SendClientMessage(playerid, COLOR_ORANGE, "Syntax Error: /sethealth [playerid] [amount]");
        return 1;
    }
   
    new id, v;
    id = strval(tmp);
    v = strval(tmp2);
   
    if(id == INVALID_PLAYER_ID) {
        SendClientMessage(playerid, COLOR_GREY, "Error: Player not found");
        return 1;
    }
   
    if(!IsPlayerAdmin(playerid)) {
        SendClientMessage(playerid, COLOR_BRIGHTRED, "You have no acces to this command");
        return 1;
    }
   
    SetPlayerHealth(id, v);
    return 1;
}
    return 0;
}
xD (MILAN 3 - 0 INTER omg !! FORCA MILAN)


Re: omg xD strtok help! - Marricio - 02.04.2011

Use ZCMD and SSCANF


Re: omg xD strtok help! - Rivera - 02.04.2011

Quote:

Use ZCMD and SSCANF

omg... :P

Yes, I use ZCMD and SSCANF but I wanter to give a try to strtok, so will this work ??


Re: omg xD strtok help! - xir - 02.04.2011

If you use zcmd & sscanf, why do try with strtok and strcmp which is outdated, where you have sscanf & zcmd fast and easy to use?


Re: omg xD strtok help! - Rivera - 03.04.2011

You guys don't even try to understand. What's your problem? Okay, I WANT to use strtok. Any problem? That's what I want and I am not going to change my mind. Now, if you can answer my question and leave the useless comments ?


Re: omg xD strtok help! - airsoft - 03.04.2011

If it compiles with no errors, give it a try lol


Re: omg xD strtok help! - Rivera - 03.04.2011

Yeah! Well, it compiles with warnings in lines like these:

pawn Код:
if(!strlen(tmp)) {
        SendClientMessage(playerid, COLOR_ORANGE, "Syntax Error: /pay [playerid] [amount]");
        return 1;
    }
   
    if(!strlen(tmp2)) {
        SendClientMessage(playerid, COLOR_ORANGE, "Syntax Error: /pay [playerid] [amount]");
        return 1;
    }
It says:

pawn Код:
C:\Documents and Settings\B-SpaCe\My Documents\SpaCe\Script\gamemodes\UK-RP1.pwn(110) : warning 217: loose indentation



Re: omg xD strtok help! - s0nic - 03.04.2011

Of course it does..your code has poor indentation not hard to fix if you spend the time going line by line indenting it properly..
Like so:
Код:
http://pastebin.com/ALTYb7zZ
If i could try it i would..don't have gta installed on this laptop, but from the looks of it..it should work?


Re: omg xD strtok help! - Rivera - 03.04.2011

it worked, thanks


Re: omg xD strtok help! - sansko - 03.04.2011

why always ZCMD and not YCMD (if you use ******' his system)


Re: omg xD strtok help! - Max_Coldheart - 03.04.2011

Dont worry, Loose Indentation is no hard warning, Just about ur identation.
But when I look at it I think it will work.