omg xD strtok help!
#1

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)
Reply
#2

Use ZCMD and SSCANF
Reply
#3

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 ??
Reply
#4

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?
Reply
#5

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 ?
Reply
#6

If it compiles with no errors, give it a try lol
Reply
#7

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
Reply
#8

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:
If i could try it i would..don't have gta installed on this laptop, but from the looks of it..it should work?
Reply
#9

it worked, thanks
Reply
#10

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

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


Forum Jump:


Users browsing this thread: 1 Guest(s)