Car Colour Changing
#1

How would i go about making a command that changes the colour of your car? Like /colour <First Colour> <Second Colour>



Reply
#2

https://sampwiki.blast.hk/wiki/ChangeVehicleColor

Wiki is your friend!
Reply
#3

I don't mean that. I mean the player using the command can choose what the two colours should be.
Reply
#4

If you don't have already, put the strtok-function in your gamemode. (You can find that function in lvdm.pwn which came with serverdownload).

Put (if you don't have already) at the top of your OnPlayerCommandText-callback:
Код:
new cmd[256], idx;
cmd = strtok(cmdtext, idx);
and then your command will be:
Код:
if(strcmp(cmd, "/carcolor", true)==0)
{
  if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER)
  {
    SendClientMessage(playerid, 0xFF0000AA, "You can only use this command while driving a vehicle!");
    return 1;
  }
  new tmp1[256], tmp2[256];
  tmp1= strtok(cmdtext, idx);
  tmp2= strtok(cmdtext, idx);
  if(!strlen(tmp1) || !strlen(tmp2))
  {
    SendClientMessage(playerid, 0xFF0000AA, "Use: /carcolor [color1] [color2]");
    return 1;
  }
  new color1 = strval(tmp1);
  new color2 = strval(tmp2);
  ChangeVehicleColor(GetPlayerVehicleID(playerid), color1, color2);
  return 1;
}
Reply
#5

Sandra, you should know that you shouldn't use 256 as string variable size...
Reply
#6

yea , because you can't write 67 figures
Reply
#7

Thank you very much
Reply
#8

Quote:
Originally Posted by MoroJr™
yea , because you can't write 67 figures
huh?
Reply
#9

Quote:
Originally Posted by lrZ^ aka LarzI
Sandra, you should know that you shouldn't use 256 as string variable size...
Making stringvariable size less then 255, you will get "array sizes do not match, or destination array is too small"-error with strtok
Reply
#10

Quote:
Originally Posted by =>Sandra<=
Quote:
Originally Posted by lrZ^ aka LarzI
Sandra, you should know that you shouldn't use 256 as string variable size...
Making stringvariable size less then 255, you will get "array sizes do not match, or destination array is too small"-error with strtok
only if you use some kinds of noob modifications of strtok

thats the orginal from pawn-lang.pdf (2006)
pawn Код:
strtok(const string[], &index)
{
    new length = strlen(string)
    /* skip leading white space */
    while (index < length && string[index] <= ' ')
    index++
    /* store the word letter for letter */
    new offset = index /* save start position of token */
    new result[20] /* string to store the word in */
    while (index < length && string[index] > ' ' && index - offset < sizeof result - 1)
    {
        result[index - offset] = string[index]
        index++
    }
    result[index - offset] = EOS /* zero-terminate the string */
    return result
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)