What is wrong with it? - 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)
+--- Thread: What is wrong with it? (
/showthread.php?tid=292791)
What is wrong with it? -
Kostas' - 25.10.2011
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;
}
Re: What is wrong with it? -
Vince - 25.10.2011
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;
}
Re: What is wrong with it? -
Kostas' - 25.10.2011
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