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



Random Vehicle Plate - Ballu Miaa - 24.01.2012

Hello Everyone,

I tried to make a function using for loop for all vehicle's which set's Vehicle's number plate according to the vehicleid.

I mean if the vehicleid = 1 then the Plate will be CW 1 Or something. For Vehicleid = 2 it shud be CW 2.

Im out of idea's and how can i do it , Not able to use SetVehicleNumberPlate correctly. If someone can suggest something or code me this function , will be fucking awesome.!

Thanks
Ballu Miaa



Re: Random Vehicle Plate - [HK]Ryder[AN] - 24.01.2012

EDIT:Here is the code
pawn Код:
public OnVehicleSpawn(vehicleid)
{
new str[32]; format(str, sizeof str, "SAMP %i", vehicleid);
SetVehicleNumberPlate(vehicleid, str);
SetVehicleToRespawn(vehicleid);
return 1;
}
This will work.
Note - don't change the 32 cell bit to something else in the str[32] code and also don't remove SetVehicleToRespawn cause the effects and changes take place after respawn.


Re: Random Vehicle Plate - Ballu Miaa - 24.01.2012

Thanks Mate! Need to use /rac to take affect always. Anyway to avoid it?


Re: Random Vehicle Plate - Ballu Miaa - 24.01.2012

Guy after using the above code vehicle plate's doesnt change. I have to use /rac to take affect.
Even though i've added this function under OnGameModeInIt()
pawn Код:
forward UpdatePlates();
public UpdatePlates()
{
    for(new i=0;i >= MAX_VEHICLES;i++)
    {
        SetVehicleToRespawn(i);
    }
    return 1;
}
Im still not able to set vehicle plate's. Only /rac make's it working but its need an admin to /rac always!
Is there any fix for that?


Re: Random Vehicle Plate - [ABK]Antonio - 24.01.2012

Quote:
Originally Posted by Ballu Miaa
Посмотреть сообщение
Guy after using the above code vehicle plate's doesnt change. I have to use /rac to take affect.
Even though i've added this function under OnGameModeInIt()
pawn Код:
forward UpdatePlates();
public UpdatePlates()
{
    for(new i=0;i >= MAX_VEHICLES;i++)
    {
        SetVehicleToRespawn(i);
    }
    return 1;
}
Im still not able to set vehicle plate's. Only /rac make's it working but its need an admin to /rac always!
Is there any fix for that?
You know that loop never starts right

pawn Код:
for(new i=0;i >= MAX_VEHICLES;i++)
should be
pawn Код:
for(new i=0;i <= MAX_VEHICLES;i++)



Re: Random Vehicle Plate - BMUK - 24.01.2012

Quote:
Originally Posted by [HK]Ryder[AN]
Посмотреть сообщение
EDIT:Here is the code
pawn Код:
public OnVehicleSpawn(vehicleid)
{
new str[32]; format(str, sizeof str, "SAMP %i", vehicleid);
SetVehicleNumberPlate(vehicleid, str);
SetVehicleToRespawn(vehicleid);
return 1;
}
This will work.
Note - don't change the 32 cell bit to something else in the str[32] code and also don't remove SetVehicleToRespawn cause the effects and changes take place after respawn.
OnVehicleSpawn is not called for preloaded vehicles or vehicles created in game so that will only work if a vehicle dies.

You can use the following under OnGameModeInit. You don't need to respawn the vehicle because the vehicle will need to be streamed in anyway. Add it at the end of the callback.

pawn Код:
new str[32];
for( new i = 0; i < MAX_VEHICLES; i++)
{
    format( str, sizeof(str), "SAMP %i", i);
    SetVehicleNumberPlate(i, str);
}
You could do some additional checks like if the target vehicle actually has a numberplate.

For setting numberplates ingame then set the numberplate as usual, again no need to respawn as the vehicle will be auto streamed in anyway.

Also, [ABK]Antonio - That doesnt matter.

http://i40.tinypic.com/1552frq.jpg


Re: Random Vehicle Plate - MP2 - 24.01.2012

May I ask the reason behind the string being 32 cells? That string need only have a 10 cell array. 'SAMP xxxx' = 9 + 1 null thing.


Re: Random Vehicle Plate - Ballu Miaa - 24.01.2012

Quote:
Originally Posted by BMUK
Посмотреть сообщение
OnVehicleSpawn is not called for preloaded vehicles or vehicles created in game so that will only work if a vehicle dies.

You can use the following under OnGameModeInit. You don't need to respawn the vehicle because the vehicle will need to be streamed in anyway. Add it at the end of the callback.

pawn Код:
new str[32];
for( new i = 0; i < MAX_VEHICLES; i++)
{
    format( str, sizeof(str), "SAMP %i", i);
    SetVehicleNumberPlate(i, str);
}
You could do some additional checks like if the target vehicle actually has a numberplate.

For setting numberplates ingame then set the numberplate as usual, again no need to respawn as the vehicle will be auto streamed in anyway.

Also, [ABK]Antonio - That doesnt matter.

http://i40.tinypic.com/1552frq.jpg
Doesnt work! The above code was better i guess. I dont know whats the damn problem!


Re: Random Vehicle Plate - BMUK - 24.01.2012

Works for me as per my screenshot in my post above.


Re: Random Vehicle Plate - Ballu Miaa - 25.01.2012

I dont know bro. This is just wierd ass hell :O