Jump to content

PlayerTag - dxDrawText ( Error?! )


Maurize

Recommended Posts

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 ) 

Link to comment

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.

Link to comment

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! ;)

Link to comment
  
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

Link to comment

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. 
  

Link to comment

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:

mtascreen20110704131504.png

mtascreen20110704131521.png

mtascreen20110704131533.png

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...