Making vehicle plates random LS-%d
#1

Hey so I need a code which sets every car's license plate to LS-%d, %d is the number between 1000 and 9999, any help?
Reply
#2

https://sampwiki.blast.hk/wiki/Random read the example the wiki gives, it isnt hard at all to make.
Reply
#3

Код:
public OnVehicleSpawn(vehicleid)
{
    new string[32];
    if(vehicleid >= 0 && vehicleid <= 2000)
    {
        new randnumb = 1000 + random(9999);
        format(string, sizeof(string),"LS - %d",randnumb);
        SetVehicleNumberPlate(vehicleid, string);
        SetVehicleToRespawn(vehicleid);
    }
}
It should work, if it don't respawn all the cars when you start the server.
Reply
#4

Hash, fixed:
pawn Код:
public OnVehicleSpawn(vehicleid)
{
    new string[32];
    if(vehicleid >= 0 && vehicleid <= 2000)
    {
        new randnumb = 1000 + random(8999);
        format(string, sizeof(string),"LS - %d",randnumb);
        SetVehicleNumberPlate(vehicleid, string);
        SetVehicleToRespawn(vehicleid);
    }
}
Otherwise you could get 10999.
Reply
#5

Ow yeah lol,
Reply
#6

Its weird but at me it just keeps the normal plate how is this possible? :O
Reply
#7

OnVehicleSpawn isn't called when the vehicle is created.
It only gets called when the vehicle respawns after it has been used.

So, when you create the vehicle during OnGameModeInit, use this code to respawn it with the changed plate:
pawn Код:
public OnGameModeInit()
{
    // Create a new static vehicle during GameModeInit
    new vehicleid = AddStaticVehicleEx(Model, X, Y, Z, Rotation, C1, C2, SpawnDelay);
    new string[32];
    new randnumb = 1000 + random(8999);
    format(string, sizeof(string),"LS - %d",randnumb);
    SetVehicleNumberPlate(vehicleid, string);
    SetVehicleToRespawn(vehicleid);
}
The check "if(vehicleid >= 0 && vehicleid <= 2000)" isn't needed as there can only be 2000 vehicles spawned.

Replace the values after "AddStaticVehicleEx" to some meaningfull values.
Reply
#8

so if i want to my plate changing random and saving in file like aaa 001 or aba 021 how to make it?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)