Vehicle License plate
#1

Hello, i'v searched all over the tutorials, every where i can, tried a lot of ways to make it.
But i cannot make vehicle license plate as the ID, example i'v added
AddStaticVehicle........ and so on. so the vehicle is ID 1

So what i want is the vehicle plate will be like this "LV-01", or lets say i have vehicle id 123, so i want the plate to be
"LV-123" and so on, i want the vehicle id to be the number plate. +1 rep for helpers!! thank you!
Reply
#2

Sorry for bumping, any one? help?
Reply
#3

Didn't test it, but this should work:

pawn Код:
stock ChangeVehPlate( vehicleid )
{
    new string[8], string2[4];
   
    if( vehicleid < 10 ) format(string2,sizeof(string2),"00%i", vehicleid );
    else if( vehicleid < 100 ) format(string2,sizeof(string2),"0%i", vehicleid );
    else format(string2,sizeof(string2),"%i", vehicleid );
   
    format(string,sizeof(string),"LV-%s", string2 );
   
    SetVehicleNumberPlate( vehicleid, string );
   
    return 1;
}
Reply
#4

Quote:
Originally Posted by clavador
Посмотреть сообщение
pawn Код:
if( vehicleid < 10 ) format(string2,sizeof(string2),"00%i", vehicleid );
    else if( vehicleid < 100 ) format(string2,sizeof(string2),"0%i", vehicleid );
    else format(string2,sizeof(string2),"%i", vehicleid );
Can't believe that there are still people doing that. Just doing the following will make sure that the length of the number is always 3 characters long, padding it with zeros if it's not.

pawn Код:
format(string2,sizeof(string2),"%03i", vehicleid );
Reply
#5

Quote:
Originally Posted by clavador
Посмотреть сообщение
Didn't test it, but this should work:

pawn Код:
stock ChangeVehPlate( vehicleid )
{
    new string[8], string2[4];
   
    if( vehicleid < 10 ) format(string2,sizeof(string2),"00%i", vehicleid );
    else if( vehicleid < 100 ) format(string2,sizeof(string2),"0%i", vehicleid );
    else format(string2,sizeof(string2),"%i", vehicleid );
   
    format(string,sizeof(string),"LV-%s", string2 );
   
    SetVehicleNumberPlate( vehicleid, string );
   
    return 1;
}
Didn't work, i have a vehicle i added from AddStaticVehicle and it doesnt show the plate in game..
Reply
#6

are you setting the plate right away?

I use something like this for mine

pawn Код:
new numplate_test[32];
vid = AddStaticVehicleEx(vehicletype,SpawnX,SpawnY,SpawnZ,SpawnRot,Color1,Color2,(15*60)); // respawn 15 minutes

format(numplate_test,32+1,"LV-{%d}",vid);
SetVehicleNumberPlate(vid, numplate_test);
but i do it while my server is loading,
orther wise youll have to respawn the car to show the plate i think.
Reply
#7

Quote:
Originally Posted by Jonny5
Посмотреть сообщение
are you setting the plate right away?

I use something like this for mine

pawn Код:
new numplate_test[32];
vid = AddStaticVehicleEx(vehicletype,SpawnX,SpawnY,SpawnZ,SpawnRot,Color1,Color2,(15*60)); // respawn 15 minutes

format(numplate_test,32+1,"LV-{%d}",vid);
SetVehicleNumberPlate(vid, numplate_test);
but i do it while my server is loading,
orther wise youll have to respawn the car to show the plate i think.
Well when the server loaded up, it auto respawns vehicle as far as i know, so it should work right after server is on.
Reply
#8

Can some one explain me why it doesnt works? i'v even placed it on "OnVehicleSpawn"
still it doesn't shows me
Reply
#9

Quote:
Originally Posted by ThePandaDK
Посмотреть сообщение
Can some one explain me why it doesnt works? i'v even placed it on "OnVehicleSpawn"
still it doesn't shows me
After you change a vehicle's plate, you need to respawn it again for the changes to be noticed.

Read this: https://sampwiki.blast.hk/wiki/SetVehicleNumberPlate

Should be something like:

pawn Код:
public OnVehicleSpawn( vehicleid )
{
         ChangeVehPlate( vehicleid );
         SetVehicleToRespawn(vehicleid);
         return 1;
}

stock ChangeVehPlate( vehicleid )
{
    new string[8], string2[4];
   
    format(string2,sizeof(string2),"%03i", vehicleid );  
    format(string,sizeof(string),"LV-%s", string2 );
   
    SetVehicleNumberPlate( vehicleid, string );
   
    return 1;
}
or just add the SetVehicleToRespawn inside the function "ChangeVehPlate", before the return and on OnVehicleSpawn put the function, like this:

pawn Код:
public OnVehicleSpawn( vehicleid )
{
         ChangeVehPlate( vehicleid );
         
         return 1;
}

stock ChangeVehPlate( vehicleid )
{
    new string[8], string2[4];
   
    format(string2,sizeof(string2),"%03i", vehicleid );  
    format(string,sizeof(string),"LV-%s", string2 );
   
    SetVehicleNumberPlate( vehicleid, string );

    SetVehicleToRespawn(vehicleid);
   
    return 1;
}
Reply
#10

using it in a command would require you to ;
save the pos of the veh,
remove the player from it
set the plate
respawn the veh
move the veh to the saved pos
put player back in the car.


for static ones try..


pawn Код:
new numplate_test[11],vid;
vid = AddStaticVehicleEx(vehicletype,SpawnX,SpawnY,SpawnZ,SpawnRot,Color1,Color2,(15*60)); // respawn 15 minutes

format(numplate_test,10,"LV-{%d}",vid);
SetVehicleNumberPlate(vid, numplate_test);


//next AddStaticVehicle ......

vid = AddStaticVehicleEx(vehicletype,SpawnX,SpawnY,SpawnZ,SpawnRot,Color1,Color2,(15*60)); // respawn 15 minutes

format(numplate_test,10,"LV-{%d}",vid);
SetVehicleNumberPlate(vid, numplate_test);
this code works fine in OnGameModeInit()

you should not be setting the plate in OnVehicleSpawn()
it needs to happen before this callback from what iv read..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)