SA-MP Forums Archive
Vehicle Plate change help - 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: Vehicle Plate change help (/showthread.php?tid=602160)



Vehicle Plate change help - jimis - 03.03.2016

PHP код:
                        new id GetVehicleID(vehicleid);
                        new 
string[20];
            if(
id <= 99)
            {
                
format(stringsizeof(string),"kmk:00 %d",params);
                
SetVehicleNumberPlate(id,string);
            }
            else
            if(
id <= 999)
            {
                  
format(stringsizeof(string),"kmk:0 %d",params);
                
SetVehicleNumberPlate(idstring);
              }
              else
              if(
id <= 9999)
              {
                  
format(stringsizeof(string),"kmk: %d",params);
                
SetVehicleNumberPlate(idstring);
             } 
                        
SetVehicleToRespawn(id); 
Hi guys, i have this code to change vehicle plate, id= my vehicle system id, and params is because i am using this under CMDlate, The problem is that , when i am into a vehicle and type /plate 21 , the plate replaced with "KMK:0053" BUT it should replaced with "KMK:0021" , Someone help me please ,
thanks!


Re: Vehicle Plate change help - Amit1998 - 03.03.2016

Post the entire script please


Re: Vehicle Plate change help - Crayder - 03.03.2016

Quote:

id= my vehicle system id

That's obviously the problem then. You need to use the VEHICLE ID.

(Don't trust the Amit1998 guy(plus, he still has Triangle in his signature, the "free" hosting), the problem is obvious... xD)


Re: Vehicle Plate change help - Burridge - 03.03.2016

It looks to me as though you are checking the vehicle id instead of the params in your check.

Код:
if(id <= 99) // this code is checking if your vehicle id is less than or equal to 99
I assume that you want to check what was entered in the params so that you can set the plate accordingly. If this is the case you should be checking what was entered into the command (the params) instead of the vehicle ID. However I don't think "if(params <= 99)" will work as params is a string. So you could use strval.

Код:
new platenumber = strval(params);
new id = GetVehicleID(vehicleid); 
new string[20]; 

if(platenumber<= 99) 
{ 
    format(string, sizeof(string),"kmk:00 %d",platenumber); 
    SetVehicleNumberPlate(id,string); 
} 
else if(platenumber <= 999) 
{ 
    format(string, sizeof(string),"kmk:0 %d",platenumber); 
    SetVehicleNumberPlate(id, string); 
} 
else if(platenumber <= 9999) 
{ 
    format(string, sizeof(string),"kmk: %d",platenumber); 
    SetVehicleNumberPlate(id, string); 
}  
SetVehicleToRespawn(id);
Hopefully if I got the right idea this'll fix your problem

EDIT: See below for a shortened way of doing this command. Thanks Crayder!


Re: Vehicle Plate change help - Crayder - 03.03.2016

Just noting, your code could be shrunken to:
pawn Код:
new platenumber = strval(params);
new id = GetVehicleID(vehicleid);
new string[20];

format(string, sizeof(string),"KMK:%04d",platenumber);
SetVehicleNumberPlate(id,string);
SetVehicleToRespawn(id);
"%04d" means fill with leading zeros to 4 characters.


Re: Vehicle Plate change help - jimis - 03.03.2016

ok guys thanks you all , my problem solved thanks for helping me