Vehicle Plate change help
#1

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!
Reply
#2

Post the entire script please
Reply
#3

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)
Reply
#4

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!
Reply
#5

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.
Reply
#6

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


Forum Jump:


Users browsing this thread: 1 Guest(s)