What is wrong with it?
#1

I had a problem with the gamemode yesterday and commands bugged, so I started again.
I have carcolor command but any number I put the car was painted to black color. I wrote /carcolor 6 6 for yellow and it paints black. What is wrong?
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    new cmd[256], tmp[256], idx;
    if(strcmp(cmd, "/carcolor", true) == 0) {
        new color1, color2;
        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp)) return SendClientMessage(playerid, -1, "USAGE: /carcolor [color1] [color2]");
        color1 = strval(tmp);
        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp)) return SendClientMessage(playerid, -1, "USAGE: /carcolor [color1] [color2]");
        color2 = strval(tmp);
        ChangeVehicleColor(GetPlayerVehicleID(playerid), color1, color2);
        return 1;
    }
    return 0;
}
Reply
#2

Please, please, stop using strtok! I can't really tell what's wrong, because the code itself looks okay. Here you have the sscanf equivalent though;

pawn Код:
CMD:carcolor(playerid, params[])
{
    new
        vehicleid = GetPlayerVehicleID(playerid),
        color1, color2;

    if(!vehicleid)
        return SendClientMessage(playerid, COLOR_RED, "Not in a vehicle!");

    if(sscanf(params, "dd", color1, color2))
        return SendClientMessage(playerid, COLOR_YELLOW, "Usage: /carcolor [col 1] [col 2]");

    ChangeVehicleColor(vehicleid, color1, color2);
    return 1;
}
Reply
#3

But I have 18 cmds + 61 teleports with strtok. It's a little difficult to change them all.
By the way the color 1 doesn't work. the color 2 works
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)