Jump to content

Vehicle's name


Reuno

Recommended Posts

Helloo everyone , so i was trying to make a script which allows you to see the vehicle's name you entered , but i got a problem , when i get in a vehicle , it shows it's name , but for less than 1 second then it disappears , i searched hard in mtasa's wiki , but i still didn't find any , so what should i add so it can appear for an amount of time (more than a second) , here's the cod :

function carName () 
   local player      = getLocalPlayer() 
   local vehicleName = getVehicleName ( getPedOccupiedVehicle ( player ) ) 
   dxDrawText ( vehicleName , 320, 380+115, 2500, 150, tocolor ( 255, 255, 255, 255 ), 1.5, "bankgothic" ) 
end 
addEventHandler( "onClientVehicleEnter", getRootElement(), carName ) 

Link to comment
Helloo everyone , so i was trying to make a script which allows you to see the vehicle's name you entered , but i got a problem , when i get in a vehicle , it shows it's name , but for less than 1 second then it disappears , i searched hard in mtasa's wiki , but i still didn't find any , so what should i add so it can appear for an amount of time (more than a second) , here's the cod :
function carName () 
   local player      = getLocalPlayer() 
   local vehicleName = getVehicleName ( getPedOccupiedVehicle ( player ) ) 
   dxDrawText ( vehicleName , 320, 380+115, 2500, 150, tocolor ( 255, 255, 255, 255 ), 1.5, "bankgothic" ) 
end 
addEventHandler( "onClientVehicleEnter", getRootElement(), carName ) 

The source of the event is the vehicle that the player entered. Try this

function carName () 
   local vehicleName = getVehicleName ( source ) 
   dxDrawText ( vehicleName , 320, 380+115, 2500, 150, tocolor ( 255, 255, 255, 255 ), 1.5, "bankgothic" ) 
end 
addEventHandler( "onClientVehicleEnter", getRootElement(), carName ) 

Link to comment

That's because you're not using onClientRender.

  
   function showName( name, a ) 
    dxDrawText ( name, 320, 380+115, 2500, 150, tocolor ( 255, 255, 255, 255 ), 1.5, "bankgothic" ) 
    if a then 
      addEventHandler("onClientRender", root, showName) 
    else 
      removeEventHandler("onClientRender", root, showName) 
    end     
  
    function carName () 
       local player      = getLocalPlayer() 
       local vehicleName = getVehicleName ( getPedOccupiedVehicle ( player ) ) 
       showName( vehicleName, true ) 
    end 
    addEventHandler( "onClientVehicleEnter", getRootElement(), carName ) 
  

That's a way to do it with toggle :v

Link to comment

Not tested but should work

function drawCarName() 
    local player = getLocalPlayer() 
    local vehicleName = getVehicleName(getPedOccupiedVehicle(player)) 
    addEventHandler("onClientRender", getRootElement(), dxDrawCarName) 
end 
addEventHandler( "onClientVehicleEnter", getRootElement(), drawCarName) 
  
function removeCarName() 
    removeEventHandler("onClientRender", getRootElement(), dxDrawCarName) 
end 
addEventHandler( "onClientVehicleExit", getRootElement(), removeCarName) 
  
function dxDrawCarName() 
    local vehicle = getPedOccupiedVehicle(getLocalPlayer()) 
    if vehicle then 
    dxDrawText ( getVehicleName(vehicle), 320, 380+115, 2500, 150, tocolor ( 255, 255, 255, 255 ), 1.5, "bankgothic" ) 
    end 
end 

Link to comment

So just add a SetTimer like this:

function drawCarName() 
    local player = getLocalPlayer() 
    local vehicleName = getVehicleName(getPedOccupiedVehicle(player)) 
    addEventHandler("onClientRender", getRootElement(), dxDrawCarName) 
    setTimer(function () 
        removeEventHandler("onClientRender", getRootElement(), dxDrawCarName) 
    end, 3000, 1) 
end 
addEventHandler( "onClientVehicleEnter", getRootElement(), drawCarName) 
  
function dxDrawCarName() 
    local vehicle = getPedOccupiedVehicle(getLocalPlayer()) 
    if vehicle then 
    dxDrawText ( getVehicleName(vehicle), 320, 380+115, 2500, 150, tocolor ( 255, 255, 255, 255 ), 1.5, "bankgothic" ) 
    end 
end 

Link to comment
So just add a SetTimer like this:
function drawCarName() 
    local player = getLocalPlayer() 
    local vehicleName = getVehicleName(getPedOccupiedVehicle(player)) 
    addEventHandler("onClientRender", getRootElement(), dxDrawCarName) 
    setTimer(function () 
        removeEventHandler("onClientRender", getRootElement(), dxDrawCarName) 
    end, 3000, 1) 
end 
addEventHandler( "onClientVehicleEnter", getRootElement(), drawCarName) 
  
function dxDrawCarName() 
    local vehicle = getPedOccupiedVehicle(getLocalPlayer()) 
    if vehicle then 
    dxDrawText ( getVehicleName(vehicle), 320, 380+115, 2500, 150, tocolor ( 255, 255, 255, 255 ), 1.5, "bankgothic" ) 
    end 
end 

Even easier (and using less lines):

setTimer (removeEventHandler, 3000, 1, "onClientRender", root, dxDrawCarName) 

Link to comment

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...