drk Posted February 2, 2012 Share Posted February 2, 2012 --vehicle health local vehHealth = getElementHealth(getPedOccupiedVehicle(localPlayer)) if vehHealth then local health = math.max(health - 250, 0)/750 local r = -510*(health^2) local g,b = math.max(math.min(r+255*health+255,255),0), math.max(math.min(p+765*health,255),0) dxDrawRectangle(screenWidth-587,screenHeight-63,screenWidth-726,screenHeight-587,math.floor(256-256*(health)),tocolor(g,b,0,getElementAlpha(vehHealth)),false) end Why don't appear anything in the screen? It is anything wrong? Link to comment
JR10 Posted February 2, 2012 Share Posted February 2, 2012 Where is screenWidth and screenHeight defined? You need to add dxDrawRectangle to onClientRender event. The argument in getElementAlpha is wrong, supposed to be an element. Link to comment
drk Posted February 2, 2012 Author Share Posted February 2, 2012 Ah, local screenWidth, screenHeight = guiGetScreenSize() and it is on onClientRender event. I will solve getElementAlpha problem . Link to comment
JR10 Posted February 2, 2012 Share Posted February 2, 2012 math.floor(256-256*(health)) What is that? 0*health, so it will always return zero. Link to comment
drk Posted February 2, 2012 Author Share Posted February 2, 2012 I've solved the problem but the bar not appear. Link to comment
drk Posted February 2, 2012 Author Share Posted February 2, 2012 function Spectate.Render() local screenWidth, screenHeight = guiGetScreenSize() if Spectate.Render == true then --local TextWidth = dxGetTextWidth( string.gsub ( "Currently spectating:", '#%x%x%x%x%x%x', '' ), 0.55, "default-bold" ) --dxDrawColorText( string.gsub ( "#60f8ffCurrently spectating:", '#%x%x%x%x%x%x', '#000000' ) , 1+screenWidth/2-TextWidth/2, 1+screenHeight-120, 1+screenWidth/2-TextWidth/2, 1+screenHeight-120, tocolor(0, 0, 0, 255), 0.55, "default-bold" ) --dxDrawColorText( "#60f8ffCurrently spectating:" , screenWidth/2-TextWidth/2, screenHeight-120, screenWidth/2-TextWidth/2, screenHeight-120, tocolor(255, 255, 255, 255), 0.55, "default-bold" ) if Spectate.TargetPlayer then local r,g,b = 255,255,255 local team = getPlayerTeam(Spectate.TargetPlayer) if team then r,g,b = getTeamColor(team) end local TargetWidth = dxGetTextWidth( string.gsub ( _getPlayerName(Spectate.TargetPlayer), '#%x%x%x%x%x%x', '' ), 0.46, "bankgothic" ) local TargetHeight = dxGetFontHeight( 0.55, "bankgothic" ) dxDrawColorText( string.gsub ( _getPlayerName(Spectate.TargetPlayer), '#%x%x%x%x%x%x', '#000000' ) , 1+screenWidth/3.8-TargetWidth/6.25, 1+screenHeight-99+TargetHeight, 1+screenWidth/2-TargetWidth/2, 1+screenHeight-120+TargetHeight, tocolor(0, 0, 0, 255), 0.55, "bankgothic" ) dxDrawColorText( _getPlayerName(Spectate.TargetPlayer) , screenWidth/3.8-TargetWidth/6.25, screenHeight-99+TargetHeight, screenWidth/2-TargetWidth/2, screenHeight-120+TargetHeight, tocolor(r, g, b, 255), 0.55, "bankgothic" ) --vehicle health local vehHealth = getElementHealth(getPedOccupiedVehicle(Spectate.TargetPlayer)) if vehHealth then local health = math.max(health - 250, 0)/750 local r = -510*(health^2) local g,b = math.max(math.min(r+255*health+255,255),0), math.max(math.min(p+765*health,255),0) dxDrawRectangle(screenWidth-587,screenHeight-63,screenWidth-726,screenHeight-587,math.floor(200*(health)),tocolor(g,b,0,getElementAlpha(Spectate.TargetPlayer)),false) end else local NoOneWidth = dxGetTextWidth( string.gsub ( "No one to spectate", '#%x%x%x%x%x%x', '' ), 0.55, "bankgothic" ) local NoOneHeight = dxGetFontHeight( 0.55, "bankgothic" ) dxDrawColorText( string.gsub ( "#FFFFFFNo one to spectate", '#%x%x%x%x%x%x', '#000000' ), 1+screenWidth/4-NoOneWidth/6, 1+screenHeight-90+NoOneHeight, 1+screenWidth/2-NoOneWidth/2, 1+screenHeight-120+NoOneHeight, tocolor(0, 0, 0, 255), 0.55, "bankgothic" ) dxDrawColorText( "#FFFFFFNo one to spectate", screenWidth/4-NoOneWidth/6, screenHeight-90+NoOneHeight, screenWidth/2-NoOneWidth/2, screenHeight-120+NoOneHeight, tocolor(255, 255, 255, 255), 0.55, "bankgothic" ) end if Spectate.active and Spectate.savePos then --local JoinWidth = dxGetTextWidth( string.gsub ( "Press 'B' to join", '#%x%x%x%x%x%x', '' ), 0.55, "default-bold" ) --local JoinHeight = dxGetFontHeight( 0.55, "default-bold" ) --dxDrawColorText( string.gsub ("#FFFFFFPress #ffffff'B'#FFFFFF to join", '#%x%x%x%x%x%x', '' ), 1+screenWidth/4-JoinWidth/6, 1+screenHeight-90+JoinHeight*3, 1+screenWidth/2-JoinWidth/2, 1+screenHeight-120+JoinHeight*3, tocolor(0, 0, 0, 255), 0.55, "default-bold" ) --dxDrawColorText( "#FFFFFFPress #ffffff'B'#60f8ff to join", screenWidth/4-JoinWidth/6, screenHeight-90+JoinHeight*3, screenWidth/2-JoinWidth/2, screenHeight-120+JoinHeight*3, tocolor(255, 255, 255, 255), 0.55, "default-bold" ) end end end addEventHandler("onClientRender", g_Root, Spectate.Render) I get this error: "Cannot perform arithmetic on global 'health' ( a nil value )" Link to comment
Castillo Posted February 2, 2012 Share Posted February 2, 2012 function Spectate.Render() local screenWidth, screenHeight = guiGetScreenSize() if Spectate.Render == true then --local TextWidth = dxGetTextWidth( string.gsub ( "Currently spectating:", '#%x%x%x%x%x%x', '' ), 0.55, "default-bold" ) --dxDrawColorText( string.gsub ( "#60f8ffCurrently spectating:", '#%x%x%x%x%x%x', '#000000' ) , 1+screenWidth/2-TextWidth/2, 1+screenHeight-120, 1+screenWidth/2-TextWidth/2, 1+screenHeight-120, tocolor(0, 0, 0, 255), 0.55, "default-bold" ) --dxDrawColorText( "#60f8ffCurrently spectating:" , screenWidth/2-TextWidth/2, screenHeight-120, screenWidth/2-TextWidth/2, screenHeight-120, tocolor(255, 255, 255, 255), 0.55, "default-bold" ) if Spectate.TargetPlayer then local r,g,b = 255,255,255 local team = getPlayerTeam(Spectate.TargetPlayer) if team then r,g,b = getTeamColor(team) end local TargetWidth = dxGetTextWidth( string.gsub ( _getPlayerName(Spectate.TargetPlayer), '#%x%x%x%x%x%x', '' ), 0.46, "bankgothic" ) local TargetHeight = dxGetFontHeight( 0.55, "bankgothic" ) dxDrawColorText( string.gsub ( _getPlayerName(Spectate.TargetPlayer), '#%x%x%x%x%x%x', '#000000' ) , 1+screenWidth/3.8-TargetWidth/6.25, 1+screenHeight-99+TargetHeight, 1+screenWidth/2-TargetWidth/2, 1+screenHeight-120+TargetHeight, tocolor(0, 0, 0, 255), 0.55, "bankgothic" ) dxDrawColorText( _getPlayerName(Spectate.TargetPlayer) , screenWidth/3.8-TargetWidth/6.25, screenHeight-99+TargetHeight, screenWidth/2-TargetWidth/2, screenHeight-120+TargetHeight, tocolor(r, g, b, 255), 0.55, "bankgothic" ) --vehicle health local health = getElementHealth(getPedOccupiedVehicle(Spectate.TargetPlayer)) if health then local health = math.max(health - 250, 0)/750 local r = -510*(health^2) local g,b = math.max(math.min(r+255*health+255,255),0), math.max(math.min(p+765*health,255),0) dxDrawRectangle(screenWidth-587,screenHeight-63,screenWidth-726,screenHeight-587,math.floor(200*(health)),tocolor(g,b,0,getElementAlpha(Spectate.TargetPlayer)),false) end else local NoOneWidth = dxGetTextWidth( string.gsub ( "No one to spectate", '#%x%x%x%x%x%x', '' ), 0.55, "bankgothic" ) local NoOneHeight = dxGetFontHeight( 0.55, "bankgothic" ) dxDrawColorText( string.gsub ( "#FFFFFFNo one to spectate", '#%x%x%x%x%x%x', '#000000' ), 1+screenWidth/4-NoOneWidth/6, 1+screenHeight-90+NoOneHeight, 1+screenWidth/2-NoOneWidth/2, 1+screenHeight-120+NoOneHeight, tocolor(0, 0, 0, 255), 0.55, "bankgothic" ) dxDrawColorText( "#FFFFFFNo one to spectate", screenWidth/4-NoOneWidth/6, screenHeight-90+NoOneHeight, screenWidth/2-NoOneWidth/2, screenHeight-120+NoOneHeight, tocolor(255, 255, 255, 255), 0.55, "bankgothic" ) end if Spectate.active and Spectate.savePos then --local JoinWidth = dxGetTextWidth( string.gsub ( "Press 'B' to join", '#%x%x%x%x%x%x', '' ), 0.55, "default-bold" ) --local JoinHeight = dxGetFontHeight( 0.55, "default-bold" ) --dxDrawColorText( string.gsub ("#FFFFFFPress #ffffff'B'#FFFFFF to join", '#%x%x%x%x%x%x', '' ), 1+screenWidth/4-JoinWidth/6, 1+screenHeight-90+JoinHeight*3, 1+screenWidth/2-JoinWidth/2, 1+screenHeight-120+JoinHeight*3, tocolor(0, 0, 0, 255), 0.55, "default-bold" ) --dxDrawColorText( "#FFFFFFPress #ffffff'B'#60f8ff to join", screenWidth/4-JoinWidth/6, screenHeight-90+JoinHeight*3, screenWidth/2-JoinWidth/2, screenHeight-120+JoinHeight*3, tocolor(255, 255, 255, 255), 0.55, "default-bold" ) end end end addEventHandler("onClientRender", g_Root, Spectate.Render) Link to comment
drk Posted February 3, 2012 Author Share Posted February 3, 2012 Now I get no error but dx rectangle don't appear. 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