Reuno Posted August 18, 2016 Share Posted August 18, 2016 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
Chaos Posted August 18, 2016 Share Posted August 18, 2016 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
Reuno Posted August 18, 2016 Author Share Posted August 18, 2016 Well , it's not the problem , my cod is working perfectly it displays the vehicles name , but the main problem is that the vehicle's name appears for a moment only then disappears . Link to comment
Simple0x47 Posted August 18, 2016 Share Posted August 18, 2016 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
Reuno Posted August 18, 2016 Author Share Posted August 18, 2016 Well , it's still the same problem , i guess it's related to timers or something . Link to comment
Reuno Posted August 18, 2016 Author Share Posted August 18, 2016 Sorry for bumping , i just added addEventHandler ( "onClientRender", getRootElement(), carName ) , it appears now , but now the problem is how to let it disappear ! Link to comment
Wumbaloo Posted August 18, 2016 Share Posted August 18, 2016 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
Reuno Posted August 18, 2016 Author Share Posted August 18, 2016 Not really , this will remove the text after you leave the car , what i want is remove the text after 3 secs Link to comment
Wumbaloo Posted August 18, 2016 Share Posted August 18, 2016 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
EstrategiaGTA Posted August 18, 2016 Share Posted August 18, 2016 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
Simple0x47 Posted August 18, 2016 Share Posted August 18, 2016 Why you didn't use the toggle function :`v Link to comment
EstrategiaGTA Posted August 18, 2016 Share Posted August 18, 2016 Why you didn't use the toggle function :`v I guess he didn't realize. Yet if he's using your way then: setTimer (showName, 3000, 1, vehicleName, false) Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now