mgdmgd Posted March 29, 2017 Author Share Posted March 29, 2017 On 3/24/2017 at 13:55, NeXuS™ said: Ohh, just in the air? For the server side. Later on, you can use the customNames table to set their custom name back after respawn. customNames = {} addCommandHandler("customname", function(thePlayer, cmdName, customName) local cVeh = getPedOccupiedVehicle(thePlayer) setElementData(cVeh, "customName", customName) customNames[cVeh] = customName end) For the client side. addEventHandler("onClientRender", getRootElement(), function() local pX, pY, pZ = getElementPosition(localPlayer) for i, k in ipairs(getElementsByType("vehicle")) do if getElementData(k, "customName") then local cX, cY, cZ = getElementPosition(k) if getDistanceBetweenPoints3D(cX, cY, cZ, pX, pY, pZ) <= 20 then if isLineOfSightClear(cX, cY, cZ+1, pX, pY, pZ+1) then local cX, cY = getScreenFromWorldPosition(cX, cY, cZ+1) if cX and cY then dxDrawText(getElementData(k, "customName"), cX, cY) end end end end end) This one should work just fine. Not tested tho. Give me a feedback of it. Still working on the texture one. It didn't work bro Link to comment
NeXuS™ Posted March 29, 2017 Share Posted March 29, 2017 What is not working with it tho? Any error? Link to comment
mgdmgd Posted March 29, 2017 Author Share Posted March 29, 2017 Nope, when i write /customname ingame nothing happens, plus i tested it on a friend server and had no console since my server isn't ready yet @NeXuS™ Link to comment
NeXuS™ Posted March 29, 2017 Share Posted March 29, 2017 Gonna give it a go in 10 mins. Can you wait a bit please? Link to comment
mgdmgd Posted March 29, 2017 Author Share Posted March 29, 2017 1 minute ago, NeXuS™ said: Gonna give it a go in 10 mins. Can you wait a bit please? Sure thing thanks bro Link to comment
NeXuS™ Posted March 29, 2017 Share Posted March 29, 2017 There was an error in the client-side script. An end was missing. addEventHandler("onClientRender", getRootElement(), function() local pX, pY, pZ = getElementPosition(localPlayer) for i, k in ipairs(getElementsByType("vehicle")) do if getElementData(k, "customName") then local cX, cY, cZ = getElementPosition(k) if getDistanceBetweenPoints3D(cX, cY, cZ, pX, pY, pZ) <= 20 then if isLineOfSightClear(cX, cY, cZ+1, pX, pY, pZ+1) then local cX, cY = getScreenFromWorldPosition(cX, cY, cZ+1) if cX and cY then dxDrawText(getElementData(k, "customName"), cX, cY) end end end end end end) Link to comment
mgdmgd Posted March 29, 2017 Author Share Posted March 29, 2017 1 minute ago, NeXuS™ said: There was an error in the client-side script. An end was missing. addEventHandler("onClientRender", getRootElement(), function() local pX, pY, pZ = getElementPosition(localPlayer) for i, k in ipairs(getElementsByType("vehicle")) do if getElementData(k, "customName") then local cX, cY, cZ = getElementPosition(k) if getDistanceBetweenPoints3D(cX, cY, cZ, pX, pY, pZ) <= 20 then if isLineOfSightClear(cX, cY, cZ+1, pX, pY, pZ+1) then local cX, cY = getScreenFromWorldPosition(cX, cY, cZ+1) if cX and cY then dxDrawText(getElementData(k, "customName"), cX, cY) end end end end end end) Hope it works now But i was wondering, how can i make the names save even if the cars respawn? Link to comment
NeXuS™ Posted March 29, 2017 Share Posted March 29, 2017 (edited) If it is respawned, the element data is still saved. The problem starts if your car got destroyed. You'll have to save the cars in a database, else how do you know which car needs a customname? Edited March 29, 2017 by NeXuS™ Link to comment
mgdmgd Posted March 29, 2017 Author Share Posted March 29, 2017 the cars gets saved in the database but i want the text to get saved as well, i can make a new cloumn and identify it in the script? Link to comment
NeXuS™ Posted March 29, 2017 Share Posted March 29, 2017 Yeah, that's all you'll have to do. If you need further help with that one too, feel free to ask. 1 Link to comment
mgdmgd Posted April 1, 2017 Author Share Posted April 1, 2017 On 3/29/2017 at 13:17, NeXuS™ said: Yeah, that's all you'll have to do. If you need further help with that one too, feel free to ask. Okay so i am facing another problem It appears for me but doesn't appear for other players and once i get out of the car it disappears can you help me with that? Link to comment
NeXuS™ Posted April 1, 2017 Share Posted April 1, 2017 (edited) I think it's because the player's model is blocking the isLineOfSightClear function. Try this one. addEventHandler("onClientRender", getRootElement(), function() local pX, pY, pZ = getElementPosition(localPlayer) for i, k in ipairs(getElementsByType("vehicle")) do if getElementData(k, "customName") then local cX, cY, cZ = getElementPosition(k) if getDistanceBetweenPoints3D(cX, cY, cZ, pX, pY, pZ) <= 20 then if isLineOfSightClear(cX, cY, cZ+1, pX, pY, pZ+1, true, true, true, true, true, false, false, localPlayer) then local cX, cY = getScreenFromWorldPosition(cX, cY, cZ+1) if cX and cY then dxDrawText(getElementData(k, "customName"), cX, cY) end end end end end end) Edited April 1, 2017 by NeXuS™ Link to comment
mgdmgd Posted April 1, 2017 Author Share Posted April 1, 2017 14 minutes ago, NeXuS™ said: I think it's because the player's model is blocking the isLineOfSightClear function. Try this one. addEventHandler("onClientRender", getRootElement(), function() local pX, pY, pZ = getElementPosition(localPlayer) for i, k in ipairs(getElementsByType("vehicle")) do if getElementData(k, "customName") then local cX, cY, cZ = getElementPosition(k) if getDistanceBetweenPoints3D(cX, cY, cZ, pX, pY, pZ) <= 20 then if isLineOfSightClear(cX, cY, cZ+1, pX, pY, pZ+1, true, true, true, true, true, false, false, localPlayer) then local cX, cY = getScreenFromWorldPosition(cX, cY, cZ+1) if cX and cY then dxDrawText(getElementData(k, "customName"), cX, cY) end end end end end end) The text appears and disappears now but it shows for all but disappears a lot, and can somehow it be at the end of the car? like here http://prntscr.com/er5xw2 Link to comment
NeXuS™ Posted April 1, 2017 Share Posted April 1, 2017 Just calculate the position. You can attach an element to the car and set it's collision to false, and then create the text on that object. Whatever you want. The script itself works totally fine for me wo/ any disappearing. Do you have any errors in debugscript mode? Link to comment
mgdmgd Posted April 1, 2017 Author Share Posted April 1, 2017 Nope, but when the car jumps the text appears but when i am driving it keeps disappearing and appearing Link to comment
NeXuS™ Posted April 1, 2017 Share Posted April 1, 2017 addEventHandler("onClientRender", getRootElement(), function() local pX, pY, pZ = getElementPosition(localPlayer) for i, k in ipairs(getElementsByType("vehicle")) do if getElementData(k, "customName") then local cX, cY, cZ = getElementPosition(k) if getDistanceBetweenPoints3D(cX, cY, cZ, pX, pY, pZ) <= 20 then local ignoredElement = getPedOccupiedVehicle(localPlayer) and getPedOccupiedVehicle(localPlayer) or localPlayer if isLineOfSightClear(cX, cY, cZ+1, pX, pY, pZ+1, true, true, true, true, true, false, false, ignoredElement) then local cX, cY = getScreenFromWorldPosition(cX, cY, cZ+1) if cX and cY then dxDrawText(getElementData(k, "customName"), cX, cY) end end end end end end) Link to comment
mgdmgd Posted April 1, 2017 Author Share Posted April 1, 2017 10 minutes ago, NeXuS™ said: addEventHandler("onClientRender", getRootElement(), function() local pX, pY, pZ = getElementPosition(localPlayer) for i, k in ipairs(getElementsByType("vehicle")) do if getElementData(k, "customName") then local cX, cY, cZ = getElementPosition(k) if getDistanceBetweenPoints3D(cX, cY, cZ, pX, pY, pZ) <= 20 then local ignoredElement = getPedOccupiedVehicle(localPlayer) and getPedOccupiedVehicle(localPlayer) or localPlayer if isLineOfSightClear(cX, cY, cZ+1, pX, pY, pZ+1, true, true, true, true, true, false, false, ignoredElement) then local cX, cY = getScreenFromWorldPosition(cX, cY, cZ+1) if cX and cY then dxDrawText(getElementData(k, "customName"), cX, cY) end end end end end end) Thank you!! 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