Jump to content

Help: Randomize Vehicle Plate Text when Respawn


Hadif

Recommended Posts

Posted

Someone knows how to reset randomize plate number when vehicle explode... eg: My car plate number is "ABC123", when my car explode, it change the plate number randomly to something else like "DEF456" or something... please help me, i ll try so many way but not find the solution...

addEventHandler ( "onResourceStart", getRootElement ( ), 
    function ( ) 
        vehicleSpawn ( ) 
    end 
) 
  
addEventHandler ( "onVehicleExplode", getRootElement ( ), 
    function ( ) 
        respawnExplodedVehicle ( ) 
    end 
) 
  
local defaultPlate = "GUEST " .. math.random ( 11, 99 ) 
  
function vehicleSpawn ( ) 
    local theVehicle = { } 
    theVehicle [ 1 ] = createVehicle ( 558, -301.7, 1767.8, 42.4, 0, 0, 88, defaultPlate, false, variant1, variant2 ) 
    local allVehicles = theVehicle 
    for theKey, allVehicles in ipairs ( allVehicles ) do 
        setElementData ( allVehicles, "Owner", "Free", true ) 
    end 
end 
  
function respawnExplodedVehicle ( ) 
    if ( getElementData ( source, "Owner" ) == "Free" ) then 
        setTimer ( respawnVehicle, 5000, 1, source ) 
    end 
end 

Posted
  
letters = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"} 
  
function randomPlate (vehicle) 
setVehiclePlateText(vehicle,letters[math.random(1,#letters)]..letters[math.random(1,#letters)]..letters[math.random(1,#letters)]..tostring(math.random(1,9))..tostring(math.random(1,9))..tostring(math.random(1,9)) 
end 
  

Posted
  
letters = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"} 
  
function randomPlate (vehicle) 
setVehiclePlateText(vehicle,letters[math.random(1,#letters)]..letters[math.random(1,#letters)]..letters[math.random(1,#letters)]..tostring(math.random(1,9))..tostring(math.random(1,9))..tostring(math.random(1,9)) 
end 
  

how?

Posted

put that in the code, and then add this:

  
function onExplode (vehicle) 
randomPlate(vehicle) 
end 
addEventHandler("onVehicleExplode",root,onExplode) 
  

Posted

Wait, i just realized that you don't need to randomize it, your problem is that it's being randomized.

but can you explain the problem more? is this happening AFTER the vehicle is respawned?

Posted
Wait, i just realized that you don't need to randomize it, your problem is that it's being randomized.

but can you explain the problem more? is this happening AFTER the vehicle is respawned?

yes, i want it to change the car numplate after it has been respawn, im glad u understand me....

Posted

Great, then, get the plate text using "getVehiclePlateText" BEFORE you spawn the vehicle, and after you spawn it use setVehiclePlateText and set it to the one you got from the first function.

Posted
Great, then, get the plate text using "getVehiclePlateText" BEFORE you spawn the vehicle, and after you spawn it use setVehiclePlateText and set it to the one you got from the first function.

no dude, i want it to change its numplate after respawn... eg: before "DRIVE 12", after respawn "DRIVE 94" :D

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...