WolfPire Posted March 11, 2012 Share Posted March 11, 2012 Well... I'm making a Vehicle Info script which consists in getting the vehicle HP and other stuff and render it in a guiLabel. Weirdly it's trolling me with the HP rendering. Take a look at it please s: i'm getting dizzy~ Client local screenW,screenH=guiGetScreenSize() function values() vehicle = getPedOccupiedVehicle ( localPlayer ) if vehicle then HP = getElementHealth (vehicle) vehname = getVehicleName ( vehicle ) vehID = getElementModel ( vehicle ) end end addEventHandler("onClientRender",root,values) function drawGUI() if vehicle then HPG = guiCreateLabel(0,0,1247.0,328.0,"Health: ", false) NG = guiCreateLabel(0,0,1247.0,303.0,"Vehicle: ".. vehname .." (ID: " .. vehID .. " ) ", false) G = guiCreateLabel(0,0,1247.0,303.0,"Vehicle Info", false) guiSetFont(G,"default-bold-small") guiSetFont(NG,"default-small") guiSetFont(HPG,"default-small") guiLabelSetColor(G,0,200,0) local windowW1,windowH1=guiGetSize(HPG,false) local x1,y1 = (screenW-windowW1)/2,(screenH-windowH1)/2 guiSetPosition(HPG,x1 + 1020,y1 + 40,false) local windowW2,windowH2=guiGetSize(NG,false) local x2,y2 = (screenW-windowW2)/2,(screenH-windowH2)/2 guiSetPosition(NG,x2 + 1020,y2 + 40,false) local windowW3,windowH3=guiGetSize(G,false) local x3,y3 = (screenW-windowW3)/2,(screenH-windowH3)/2 guiSetPosition(G,x3 + 1000,y3 + 10,false) addEventHandler("onClientRender",root,renderHP) end end addEventHandler("onClientPlayerVehicleEnter", root, drawGUI) function renderHP() if HPG then guiSetText(HPG,"Health: ".. math.floor(HP) .."") else removeEventHandler("onClientRender",root,renderHP) end end function doText(command, ...) if command == "showvi" then guiSetVisibility(HPG,true) guiSetVisibility(NG,true) guiSetVisibility(G,true) elseif command == "hidevi" then guiSetVisibility(HPG,false) guiSetVisibility(NG,false) guiSetVisibility(G,false) end end addCommandHandler("showvi", doText) addCommandHandler("hidevi", doText) function deleteGUI() if HPG then destroyElement(HPG) destroyElement(NG) destroyElement(G) end end addEventHandler("onClientVehicleExit",root,deleteGUI) Link to comment
Castillo Posted March 11, 2012 Share Posted March 11, 2012 And the problem is? you didn't specify it. Link to comment
WolfPire Posted March 11, 2012 Author Share Posted March 11, 2012 And the problem is? you didn't specify it. When i step down of the bike i get this error flooding my debug: "WARNING: VehicleInfo/VI.lua:40: Bad argument @ 'guiSetText' [Expected gui-element at argument 1]" Link to comment
Castillo Posted March 11, 2012 Share Posted March 11, 2012 local screenW, screenH = guiGetScreenSize() function values() vehicle = getPedOccupiedVehicle ( localPlayer ) if vehicle then HP = getElementHealth (vehicle) vehname = getVehicleName ( vehicle ) vehID = getElementModel ( vehicle ) end end addEventHandler("onClientRender",root,values) function drawGUI() if ( source == localPlayer and vehicle ) then HPG = guiCreateLabel(0,0,1247.0,328.0,"Health: ", false) NG = guiCreateLabel(0,0,1247.0,303.0,"Vehicle: ".. vehname .." (ID: " .. vehID .. " ) ", false) G = guiCreateLabel(0,0,1247.0,303.0,"Vehicle Info", false) guiSetFont(G,"default-bold-small") guiSetFont(NG,"default-small") guiSetFont(HPG,"default-small") guiLabelSetColor(G,0,200,0) local windowW1,windowH1=guiGetSize(HPG,false) local x1,y1 = (screenW-windowW1)/2,(screenH-windowH1)/2 guiSetPosition(HPG,x1 + 1020,y1 + 40,false) local windowW2,windowH2=guiGetSize(NG,false) local x2,y2 = (screenW-windowW2)/2,(screenH-windowH2)/2 guiSetPosition(NG,x2 + 1020,y2 + 40,false) local windowW3,windowH3=guiGetSize(G,false) local x3,y3 = (screenW-windowW3)/2,(screenH-windowH3)/2 guiSetPosition(G,x3 + 1000,y3 + 10,false) addEventHandler("onClientRender",root,renderHP) end end addEventHandler("onClientPlayerVehicleEnter", root, drawGUI) function renderHP() if HPG then guiSetText(HPG,"Health: ".. math.floor(HP) .."") else removeEventHandler("onClientRender",root,renderHP) end end function doText(command, ...) if ( command == "showvi" ) then guiSetVisibility(HPG,true) guiSetVisibility(NG,true) guiSetVisibility(G,true) elseif ( command == "hidevi" ) then guiSetVisibility(HPG,false) guiSetVisibility(NG,false) guiSetVisibility(G,false) end end addCommandHandler("showvi", doText) addCommandHandler("hidevi", doText) function deleteGUI( thePlayer ) if ( thePlayer == localPlayer ) then if HPG then destroyElement(HPG) destroyElement(NG) destroyElement(G) removeEventHandler("onClientRender",root,renderHP) end end end addEventHandler("onClientVehicleExit",root,deleteGUI) Try that. Link to comment
Fentas Posted March 11, 2012 Share Posted March 11, 2012 guiSetText(HPG,"Health: ".. math.floor(HP) .."") >>> guiSetText(HPG,"Health: ".. math.floor(HP)) Link to comment
WolfPire Posted March 11, 2012 Author Share Posted March 11, 2012 local screenW, screenH = guiGetScreenSize() function values() vehicle = getPedOccupiedVehicle ( localPlayer ) if vehicle then HP = getElementHealth (vehicle) vehname = getVehicleName ( vehicle ) vehID = getElementModel ( vehicle ) end end addEventHandler("onClientRender",root,values) function drawGUI() if ( source == localPlayer and vehicle ) then HPG = guiCreateLabel(0,0,1247.0,328.0,"Health: ", false) NG = guiCreateLabel(0,0,1247.0,303.0,"Vehicle: ".. vehname .." (ID: " .. vehID .. " ) ", false) G = guiCreateLabel(0,0,1247.0,303.0,"Vehicle Info", false) guiSetFont(G,"default-bold-small") guiSetFont(NG,"default-small") guiSetFont(HPG,"default-small") guiLabelSetColor(G,0,200,0) local windowW1,windowH1=guiGetSize(HPG,false) local x1,y1 = (screenW-windowW1)/2,(screenH-windowH1)/2 guiSetPosition(HPG,x1 + 1020,y1 + 40,false) local windowW2,windowH2=guiGetSize(NG,false) local x2,y2 = (screenW-windowW2)/2,(screenH-windowH2)/2 guiSetPosition(NG,x2 + 1020,y2 + 40,false) local windowW3,windowH3=guiGetSize(G,false) local x3,y3 = (screenW-windowW3)/2,(screenH-windowH3)/2 guiSetPosition(G,x3 + 1000,y3 + 10,false) addEventHandler("onClientRender",root,renderHP) end end addEventHandler("onClientPlayerVehicleEnter", root, drawGUI) function renderHP() if HPG then guiSetText(HPG,"Health: ".. math.floor(HP) .."") else removeEventHandler("onClientRender",root,renderHP) end end function doText(command, ...) if ( command == "showvi" ) then guiSetVisibility(HPG,true) guiSetVisibility(NG,true) guiSetVisibility(G,true) elseif ( command == "hidevi" ) then guiSetVisibility(HPG,false) guiSetVisibility(NG,false) guiSetVisibility(G,false) end end addCommandHandler("showvi", doText) addCommandHandler("hidevi", doText) function deleteGUI( thePlayer ) if ( thePlayer == localPlayer ) then if HPG then destroyElement(HPG) destroyElement(NG) destroyElement(G) removeEventHandler("onClientRender",root,renderHP) end end end addEventHandler("onClientVehicleExit",root,deleteGUI) Try that. Works like a charm. Thanks! 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