Maurize Posted July 3, 2011 Posted July 3, 2011 Hm. I got an error i cant understand. Maybe you can help me, community members. Line 19 : Bad Argument @ dxDrawText function NameTags() local px, py, pz, tx, ty, tz, dist px, py, pz = getCameraMatrix() for k, v in ipairs( getElementsByType( "player" ) ) do tx, ty, tz = getElementPosition( v ) dist = math.sqrt( ( px - tx ) ^ 2 + ( py - ty ) ^ 2 + ( pz - tz ) ^ 2) if dist < 10 then if isLineOfSightClear( px, py, pz, tx, ty, tz, true, false, false, true, false, false, Spieler ) then local sx, sy, sz = getPedBonePosition( v, 5 ) local x,y = getScreenFromWorldPosition( sx, sy, sz + 0.3 ) if ( getPedArmor( v ) <= 100 ) and ( getPedArmor( v ) > 75 ) then dxDrawText( getPlayerName( v ), x, y, x, y, tocolor( 0, 0, 200, 200 ), 0.85 + ( 15 - dist ) * 0.02, "pricedown" ) elseif ( getPedArmor( v ) <= 75 ) and ( getPedArmor( v ) > 50 ) then dxDrawText( getPlayerName( v ), x, y, x, y, tocolor( 0, 0, 150, 200 ), 0.85 + ( 15 - dist ) * 0.02, "pricedown" ) elseif ( getPedArmor( v ) <= 50 ) and ( getPedArmor( v ) > 25 ) then dxDrawText( getPlayerName( v ), x, y, x, y, tocolor( 0, 0, 100, 200 ), 0.85 + ( 15 - dist ) * 0.02, "pricedown" ) elseif ( getPedArmor( v ) <= 25 ) and ( getPedArmor( v ) > 0 ) then dxDrawText( getPlayerName( v ), x, y, x, y, tocolor( 0, 0, 50, 200 ), 0.85 + ( 15 - dist ) * 0.02, "pricedown" ) elseif ( getElementHealth( v ) <= 100 ) and ( getElementHealth( v ) > 90 ) then dxDrawText( getPlayerName( v ), x, y, x, y, tocolor( 0, 250, 0, 200 ), 0.85 + ( 15 - dist ) * 0.02, "pricedown" ) elseif ( getElementHealth( v ) <= 90 ) and ( getElementHealth( v ) > 80 ) then dxDrawText( getPlayerName( v ), x, y, x, y, tocolor( 0, 200, 0, 200 ), 0.85 + ( 15 - dist ) * 0.02, "pricedown" ) elseif ( getElementHealth( v ) <= 80 ) and ( getElementHealth( v ) > 70 ) then dxDrawText( getPlayerName( v ), x, y, x, y, tocolor( 0, 150, 0, 200 ), 0.85 + ( 15 - dist ) * 0.02, "pricedown" ) elseif ( getElementHealth( v ) <= 70 ) and ( getElementHealth( v ) > 60 ) then dxDrawText( getPlayerName( v ), x, y, x, y, tocolor( 0, 100, 0, 200 ), 0.85 + ( 15 - dist ) * 0.02, "pricedown" ) elseif ( getElementHealth( v ) <= 60 ) and ( getElementHealth( v ) > 50 ) then dxDrawText( getPlayerName( v ), x, y, x, y, tocolor( 0, 50, 0, 200 ), 0.85 + ( 15 - dist ) * 0.02, "pricedown" ) elseif ( getElementHealth( v ) <= 50 ) and ( getElementHealth( v ) > 40 ) then dxDrawText( getPlayerName( v ), x, y, x, y, tocolor( 50, 0, 0, 200 ), 0.85 + ( 15 - dist ) * 0.02, "pricedown" ) elseif ( getElementHealth( v ) <= 40 ) and ( getElementHealth( v ) > 30 ) then dxDrawText( getPlayerName( v ), x, y, x, y, tocolor( 100, 0, 0, 200 ), 0.85 + ( 15 - dist ) * 0.02, "pricedown" ) elseif ( getElementHealth( v ) <= 30 ) and ( getElementHealth( v ) > 20 ) then dxDrawText( getPlayerName( v ), x, y, x, y, tocolor( 150, 0, 0, 200 ), 0.85 + ( 15 - dist ) * 0.02, "pricedown" ) elseif ( getElementHealth( v ) <= 20 ) and ( getElementHealth( v ) > 10 ) then dxDrawText( getPlayerName( v ), x, y, x, y, tocolor( 200, 0, 0, 200 ), 0.85 + ( 15 - dist ) * 0.02, "pricedown" ) elseif ( getElementHealth( v ) <= 10 ) then dxDrawText( getPlayerName( v ), x, y, x, y, tocolor( 250, 0, 0, 200 ), 0.85 + ( 15 - dist ) * 0.02, "pricedown" ) end end end end end addEvent( "NameTags", true ) addEventHandler( "NameTags", Spieler, function() addEventHandler( "onClientRender", getRootElement(), NameTags ) end )
SDK Posted July 3, 2011 Posted July 3, 2011 Hm, I don't see an error on first sight, which line is line 19? Maybe the drawing coordinates are off-screen. Also, try reducing your code. Instead of putting an dxDrawText every elseif, make a variable for the color and change it (or store the colors in some table or even better: make some formula for it). That should make you able to spot the error easier.
Maurize Posted July 3, 2011 Author Posted July 3, 2011 ok will do. off-screen.. im useing fps at the same time. i´m trying something right now EDIT: Right. My FPS Script caused all this bugs, ect. I´m not that good in scripting. Can you show me a way to make this whole code smaller? Maybe local color = { ... } ? Thanks alot, mate!
karlis Posted July 4, 2011 Posted July 4, 2011 local players=getElementsByType( "player" ) addEventHandler("onClientPlayerQuit",getRootElement(),refresh) addEventHandler("onClientPlayerJoin",getRootElement(),refresh) function refresh() players=getElementsByType( "player" ) end function NameTags() local px, py, pz, tx, ty, tz, dist px, py, pz = getCameraMatrix() for k, v in ipairs( players) do tx, ty, tz = getElementPosition( v ) dist = ( ( px - tx ) ^ 2 + ( py - ty ) ^ 2 + ( pz - tz ) ^ 2)^0.5 --works too if dist < 10 then if isLineOfSightClear( px, py, pz, tx, ty, tz, true, false, false, true, false, false, Spieler ) then local sx, sy, sz = getPedBonePosition( v, 5 ) local x,y = getScreenFromWorldPosition( sx, sy, sz + 0.3 ) local armor = getPedArmor( v ) local hp = getElementHealth( v ) local color if armor then color=tocolor(0,0,armor*2,200) elseif hp>50 then color=tocolor(o,hp*2,0,200) else color=tocolor(hp*2,0,0,200) end dxDrawText( getPlayerName( v ), x, y, x+200, y+50,color, 0.85 + ( 15 - dist ) * 0.02, "pricedown" ) end end end addEvent( "NameTags", true ) addEventHandler( "NameTags",getRootElement(), function() addEventHandler( "onClientRender", getRootElement(), NameTags ) end ) PS: cba to fix the spacing
Maurize Posted July 4, 2011 Author Posted July 4, 2011 Nice, Nice. Perfect BTW you forgot 1 end and some smaller bugs like "o" .. But you your method is very smart!
karlis Posted July 4, 2011 Posted July 4, 2011 yep, sorry for that, wasn't paying much attention, but no problem for the code.keep in mind that it wont work propertly with bigger hp values(like 200, when you have such stat/skill). to fix: hp=getElementHealth(v)/(1+math.max(getPedStat(v,24)-569,0)/431) --default hp skill for ped is 569, anything with less cant have 100hp, and with bigger values can have up to 200.
Maurize Posted July 4, 2011 Author Posted July 4, 2011 I only don´t understand why the text is only black, but only blue if I got armor equipped...
karlis Posted July 4, 2011 Posted July 4, 2011 I only don´t understand why the text is only black, but only blue if I got armor equipped... any errors?
Maurize Posted July 4, 2011 Author Posted July 4, 2011 No. Seems like that all is okay... I´ve uploaded some screens and the code. Code: local players=getElementsByType( "player" ) function refresh() players = getElementsByType( "player" ) end addEventHandler( "onClientPlayerQuit", getRootElement(), refresh ) addEventHandler( "onClientPlayerJoin", getRootElement(), refresh ) function NameTags() px, py, pz = getCameraMatrix() for k, v in ipairs( players ) do tx, ty, tz = getElementPosition( v ) dist = ( ( px - tx ) ^ 2 + ( py - ty ) ^ 2 + ( pz - tz ) ^ 2) ^ 0.5 if dist < 10 then if isLineOfSightClear( px, py, pz, tx, ty, tz, true, false, false, true, false, false, Spieler ) then sx, sy, sz = getPedBonePosition( v, 5 ) x,y = getScreenFromWorldPosition( sx, sy, sz + 0.3 ) armor = getPedArmor( v ) hp = getElementHealth( v ) / ( 1 + math.max( getPedStat( v, 24) - 569, 0 ) / 431 ) if armor then color = tocolor( 0, 0, armor * 1.5, 150 ) elseif hp > 50 then color = tocolor( 0, hp * 1.5, 0, 150 ) else color = tocolor( hp * 1.5, 0, 0, 150 ) end end dxDrawText( getPlayerName( v ), x, y, x + 200, y + 50, color, 0.85 + ( 15 - dist ) * 0.02, "pricedown" ) end end end addEvent( "NameTags", true ) addEventHandler( "NameTags", getRootElement(), function() addEventHandler( "onClientRender", getRootElement(), NameTags ) end ) Screens:
karlis Posted July 4, 2011 Posted July 4, 2011 got it, lack of armor is not false/nil, its just 0,therefore it always exists. replace "if armor then" with "if armor>0 then" also you forgot to localize variables.
Maurize Posted July 4, 2011 Author Posted July 4, 2011 Excellent. This is it. Thanks you very very very very much, mate I tried this for hours but you know how to do!!
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