Vehicle License plate -
DannySnoopy - 12.03.2012
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!
Re: Vehicle License plate -
DannySnoopy - 12.03.2012
Sorry for bumping, any one? help?
Re: Vehicle License plate -
clavador - 12.03.2012
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;
}
Re: Vehicle License plate -
Vince - 12.03.2012
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 );
Re: Vehicle License plate -
DannySnoopy - 12.03.2012
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..
Re: Vehicle License plate -
Jonny5 - 12.03.2012
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.
Re: Vehicle License plate -
DannySnoopy - 12.03.2012
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.
Re: Vehicle License plate -
DannySnoopy - 12.03.2012
Can some one explain me why it doesnt works? i'v even placed it on "OnVehicleSpawn"
still it doesn't shows me
Re: Vehicle License plate -
clavador - 12.03.2012
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;
}
Re: Vehicle License plate -
Jonny5 - 12.03.2012
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..