/vehcolor CMD Problem.
#1

Good Morning Everyone!.
I would like to know why is this script not working? The color doesn't changes properly.

Код:
if (strcmp("/vehcolor", cmd, true) == 0)
	{
		new Color1[128];
	    new Color2[128];
	    new currentveh;
	    Color1 = strtok(cmdtext, idx);
	    Color2 = strrest(cmdtext, idx);
	    currentveh = GetPlayerVehicleID(playerid);
	    if(!IsPlayerInVehicle(playerid, currentveh))
	    {
			SendClientMessage(playerid, COLOR_RED,"You must be in a vehicle to do this action!");
			return 1;
		}
	  	if (strval(Color1) > 255)
	  	{
	    SendClientMessage(playerid, COLOR_RED, "Invalid Color ID");
	    return 1;
	 }
	 if (strval(Color2) > 255)
   	 {
   	  	SendClientMessage(playerid, COLOR_RED, "Invalid Color ID");
	   	return 1;
   	 }
   	 else
   	 {
   	     new string[128];
		 ChangeVehicleColor(currentveh, strval(Color1), strval(Color2));
		 format(string,sizeof(string),"Your car color have been changed to (ID: %d) and (ID: %d)", strval(Color1), strval(Color2));
		 SendClientMessage(playerid, COLOR_GREEN, string);
		 return 1;
  	 }
  	 }
Reply
#2

Quote:
Originally Posted by TitanForceGeneral
Посмотреть сообщение
Good Morning Everyone!.
I would like to know why is this script not working? The color doesn't changes properly.

Код:
if (strcmp("/vehcolor", cmd, true) == 0)
	{
		new Color1[128];
	    new Color2[128];
	    new currentveh;
	    Color1 = strtok(cmdtext, idx);
	    Color2 = strrest(cmdtext, idx);
	    currentveh = GetPlayerVehicleID(playerid);
	    if(!IsPlayerInVehicle(playerid, currentveh))
	    {
			SendClientMessage(playerid, COLOR_RED,"You must be in a vehicle to do this action!");
			return 1;
		}
	  	if (strval(Color1) > 255)
	  	{
	    SendClientMessage(playerid, COLOR_RED, "Invalid Color ID");
	    return 1;
	 }
	 if (strval(Color2) > 255)
   	 {
   	  	SendClientMessage(playerid, COLOR_RED, "Invalid Color ID");
	   	return 1;
   	 }
   	 else
   	 {
   	     new string[128];
		 ChangeVehicleColor(currentveh, strval(Color1), strval(Color2));
		 format(string,sizeof(string),"Your car color have been changed to (ID: %d) and (ID: %d)", strval(Color1), strval(Color2));
		 SendClientMessage(playerid, COLOR_GREEN, string);
		 return 1;
  	 }
  	 }
Hello.
Why don't You use zcmd, which is a way more better and easier? And then Your code would look like this:
pawn Код:
COMMAND:vehcolor ( playerid, params[] ) {
    if( !IsPlayerInAnyVehicle( playerid ) ) // If player is not in vehicle, then don't do anything.
        return true;
   
    new Color[2];
    if( sscanf(params, "dd", Color[0], Color[1] ) ) {
        SendClientMessage( playerid, -1, "Usage: /vehcolor [0-255] [0-255]");
        return true;
    }
   
    if( Color[0] < 0 || Color[1] < 0 ||
        Color[0] > 255 || Color[1] > 255
    )  {
        SendClientMessage( playerid, -1, "Invalid color pair.");
        return true;
    }
   
   
    if( ChangeVehicleColor( GetPlayerVehicleID( playerid ), Color[0], Color[1] ) ) {
        new Output[64];
        format( Output, 64, "Your car color have been changed to (ID: %d) and (ID: %d)", Color[0], Color[1] );
     // Max output length for this one is 59
        SendClientMessage( playerid, -1, Output );
    } else {
        SendClientMessage( playerid, -1, "Failed to change the color. Try again." );
    }
   
    return true;
}
Greetings.
Reply
#3

CMD:vehcolor(playerid,params []){
new color1,color2;
if(sscanf(params,"dd", color1,color2)) return SendClientMessage(playerid, -1,"Usage: /vehcolor [color1] [color2]");
new currentveh = GetPlayerVehicleID(playerid);
if(color1 > 255) return SendClientMessage(playerid,-1,"Invalid color id. ");
if(color1 < 0 ) return SendClientMessage(playerid, -1, "Invalid color id.");
if(color2 > 255) return SendClientMessage(playerid,-1,"Invalid color id. ");
if(color2 < 0 ) return SendClientMessage(playerid, -1, "Invalid color id.");
ChangeVehicleColor(currentveh,color1,color2);
return 1;
}
Reply
#4

Quote:
Originally Posted by LetsOWN[PL]
Посмотреть сообщение
Hello.
Why don't You use zcmd, which is a way more better and easier? And then Your code would look like this:
pawn Код:
COMMAND:vehcolor ( playerid, params[] ) {
    if( !IsPlayerInAnyVehicle( playerid ) ) // If player is not in vehicle, then don't do anything.
        return true;
   
    new Color[2];
    if( sscanf(params, "dd", Color[0], Color[1] ) ) {
        SendClientMessage( playerid, -1, "Usage: /vehcolor [0-255] [0-255]");
        return true;
    }
   
    if( Color[0] < 0 || Color[1] < 0 ||
        Color[0] > 255 || Color[1] > 255
    )  {
        SendClientMessage( playerid, -1, "Invalid color pair.");
        return true;
    }
   
   
    if( ChangeVehicleColor( GetPlayerVehicleID( playerid ), Color[0], Color[1] ) ) {
        new Output[64];
        format( Output, 64, "Your car color have been changed to (ID: %d) and (ID: %d)", Color[0], Color[1] );
     // Max output length for this one is 59
        SendClientMessage( playerid, -1, Output );
    } else {
        SendClientMessage( playerid, -1, "Failed to change the color. Try again." );
    }
   
    return true;
}
Greetings.
If i use this than i get the following errors.
Код:
C:\Users\Damman\Desktop\SA-MP Test\gamemodes\edrift2.pwn(24780) : error 029: invalid expression, assumed zero
C:\Users\Damman\Desktop\SA-MP Test\gamemodes\edrift2.pwn(24780) : error 017: undefined symbol "cmd_vehcolor"
C:\Users\Damman\Desktop\SA-MP Test\gamemodes\edrift2.pwn(24780) : error 029: invalid expression, assumed zero
C:\Users\Damman\Desktop\SA-MP Test\gamemodes\edrift2.pwn(24780) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


4 Errors.
Reply
#5

Quote:
Originally Posted by ZToPMaN
Посмотреть сообщение
CMD:vehcolor(playerid,params []){
new color1,color2;
if(sscanf(params,"dd", color1,color2)) return SendClientMessage(playerid, -1,"Usage: /vehcolor [color1] [color2]");
new currentveh = GetPlayerVehicleID(playerid);
if(color1 > 255) return SendClientMessage(playerid,-1,"Invalid color id. ");
if(color1 < 0 ) return SendClientMessage(playerid, -1, "Invalid color id.");
if(color2 > 255) return SendClientMessage(playerid,-1,"Invalid color id. ");
if(color2 < 0 ) return SendClientMessage(playerid, -1, "Invalid color id.");
ChangeVehicleColor(currentveh,color1,color2);
return 1;
}
Why use 4 lines for something that can be done in 1? Or in 2 if you want it to look good.

if(color1 < 0 || color1 > 255 || color2 < 0 || color2 > 255) return SendClientMessage(playerid, -1, "Invalid color ID.");

would be a replacement to those 4 lines.
Reply
#6

PHP код:
if(strcmp("/vehcolor",cmd,true) == 0)
{
    new 
color[2],currentveh,string[145];
    
color[0] = strtok(cmdtext,idx);
    
color[1] = strtok(cmdtext,idx);
    
currentveh GetPlayerVehicleID(playerid);
    if(!
IsPlayerInAnyVehicle(playerid))return SendClientMessage(playerid,COLOR_RED,"You must be in a vehicle to do this action!");
    if(
color[0] > 255)return SendClientMessage(playerid,COLOR_RED,"Invalid Color ID");
    if(
color[1] > 255)return SendClientMessage(playerid,COLOR_RED,"Invalid Color ID");
    
ChangeVehicleColor(currentveh,color[0],color[1]);
    
format(string,sizeof string,"Your car color have been changed to (ID: %d) and (ID: %d)",color[0],color[1]);
    
SendClientMessage(playerid,COLOR_GREEN,string);
    return 
1;

Take this. It should work.
Reply
#7

Quote:
Originally Posted by ZToPMaN
Посмотреть сообщение
CMD:vehcolor(playerid,params []){
new color1,color2;
if(sscanf(params,"dd", color1,color2)) return SendClientMessage(playerid, -1,"Usage: /vehcolor [color1] [color2]");
new currentveh = GetPlayerVehicleID(playerid);
if(color1 > 255) return SendClientMessage(playerid,-1,"Invalid color id. ");
if(color1 < 0 ) return SendClientMessage(playerid, -1, "Invalid color id.");
if(color2 > 255) return SendClientMessage(playerid,-1,"Invalid color id. ");
if(color2 < 0 ) return SendClientMessage(playerid, -1, "Invalid color id.");
ChangeVehicleColor(currentveh,color1,color2);
return 1;
}
Код:
C:\Users\Damman\Desktop\SA-MP Test\gamemodes\edrift2.pwn(24780) : error 029: invalid expression, assumed zero
C:\Users\Damman\Desktop\SA-MP Test\gamemodes\edrift2.pwn(24780) : error 017: undefined symbol "cmd_vehcolor"
C:\Users\Damman\Desktop\SA-MP Test\gamemodes\edrift2.pwn(24780) : error 029: invalid expression, assumed zero
C:\Users\Damman\Desktop\SA-MP Test\gamemodes\edrift2.pwn(24780) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


4 Errors.
Reply
#8

Quote:
Originally Posted by ZToPMaN
Посмотреть сообщение
CMD:vehcolor(playerid,params []){
new color1,color2;
if(sscanf(params,"dd", color1,color2)) return SendClientMessage(playerid, -1,"Usage: /vehcolor [color1] [color2]");
new currentveh = GetPlayerVehicleID(playerid);
if(color1 > 255) return SendClientMessage(playerid,-1,"Invalid color id. ");
if(color1 < 0 ) return SendClientMessage(playerid, -1, "Invalid color id.");
if(color2 > 255) return SendClientMessage(playerid,-1,"Invalid color id. ");
if(color2 < 0 ) return SendClientMessage(playerid, -1, "Invalid color id.");
ChangeVehicleColor(currentveh,color1,color2);
return 1;
}
He don't use ZCMD.

-------------------
Take my code, that should work:
PHP код:
if(strcmp("/vehcolor",cmd,true) == 0

    new 
color[2],currentveh,string[145]; 
    
color[0] = strtok(cmdtext,idx); 
    
color[1] = strtok(cmdtext,idx); 
    
currentveh GetPlayerVehicleID(playerid); 
    if(!
IsPlayerInAnyVehicle(playerid))return SendClientMessage(playerid,COLOR_RED,"You must be in a vehicle to do this action!"); 
    if(
color[0] > 255)return SendClientMessage(playerid,COLOR_RED,"Invalid Color ID"); 
    if(
color[1] > 255)return SendClientMessage(playerid,COLOR_RED,"Invalid Color ID"); 
    
ChangeVehicleColor(currentveh,color[0],color[1]); 
    
format(string,sizeof string,"Your car color have been changed to (ID: %d) and (ID: %d)",color[0],color[1]); 
    
SendClientMessage(playerid,COLOR_GREEN,string); 
    return 
1

Reply
#9

Quote:
Originally Posted by MarvinPWN
Посмотреть сообщение
PHP код:
if(strcmp("/vehcolor",cmd,true) == 0)
{
    new 
color[2],currentveh,string[145];
    
color[0] = strtok(cmdtext,idx);
    
color[1] = strtok(cmdtext,idx);
    
currentveh GetPlayerVehicleID(playerid);
    if(!
IsPlayerInAnyVehicle(playerid))return SendClientMessage(playerid,COLOR_RED,"You must be in a vehicle to do this action!");
    if(
color[0] > 255)return SendClientMessage(playerid,COLOR_RED,"Invalid Color ID");
    if(
color[1] > 255)return SendClientMessage(playerid,COLOR_RED,"Invalid Color ID");
    
ChangeVehicleColor(currentveh,color[0],color[1]);
    
format(string,sizeof string,"Your car color have been changed to (ID: %d) and (ID: %d)",color[0],color[1]);
    
SendClientMessage(playerid,COLOR_GREEN,string);
    return 
1;

Take this. It should work.
I get this
Код:
C:\Users\Damman\Desktop\SA-MP Test\gamemodes\edrift2.pwn(24783) : error 006: must be assigned to an array
C:\Users\Damman\Desktop\SA-MP Test\gamemodes\edrift2.pwn(24784) : error 006: must be assigned to an array
C:\Users\Damman\Desktop\SA-MP Test\gamemodes\edrift2.pwn(31188) : error 025: function heading differs from prototype
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


3 Errors.
Reply
#10

Download sscanf and ZCMD and here's the command.

Код:
CMD:vehcolor(playerid, params[])
{
    new color1, color2;

    if(!IsPlayerInAnyVehicle(playerid))
        return SendClientMessage(playerid, -1, "Error: You must be in a vehicle.");
    if(sscanf(params, "dd", color1, color2))
        return SendClientMessage(playerid, -1, "USAGE: /vehcolor [color] [color]");
    if(color1 < 0 || color1 > 255 | color2 < 0 || color2 > 255)
        return SendClientMessage(playerid, -1, "Error: You have entered an invalid color ID.");

    ChangeVehicleColor(GetPlayerVehicleID(playerid), color1, color2);

    SendClientMessage(playerid, -1, "SERVER: You have successfully changed the color of your vehicle.");

    return 1;
}
This should do it.

Just make sure to add sscanf and ZCMD to your script properly.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)