Jump to content

dxDrawText argument


Mefisto_PL

Recommended Posts

Hi, I made code which shows how many players is alive, it was working, but now it doesn't.. Debugscript: "@bad argument 'dxDrawText'' [expected number at argument 16, got boolean]". - but wtf, there is no needed number.. Here is a code:

  
bnt_font = dxCreateFont ( "fonts/bnt.ttf", 20 ) 
  
function aliveplayers ( ) 
local screenWidth, screenHeight = guiGetScreenSize() 
    dxDrawText ( '#006699ALIVE: #FFFFFF' .. tonumber(getRaceAlivePlayers ( )), 2, screenHeight - dxGetFontHeight(0.7, bnt_font)/0.5, 0.5, 1.5, tocolor ( 255, 255, 255, 255 ), 0.9, bnt_font, 'left', 'top', false, false, false, true, false, false) 
end 
addEventHandler ( "onClientRender", getRootElement(), aliveplayers ) 
  
  
function getRaceAlivePlayers ( ) 
    local players = 0 
    for _, player in ipairs ( getElementsByType ( "player" ) ) do 
        if ( getElementData ( player, "state" ) == "alive" ) then 
            players = ( players + 1 ) 
        end 
    end 
  
    return players 
end 

Link to comment

Try

  
bnt_font = dxCreateFont ( "fonts/bnt.ttf", 20 ) 
  
function aliveplayers ( ) 
local screenWidth, screenHeight = guiGetScreenSize() 
    dxDrawText ( '#006699ALIVE: #FFFFFF' .. tonumber(getRaceAlivePlayers ( )), 2, screenHeight - dxGetFontHeight(0.7, bnt_font)/0.5, 0.5, 1.5, tocolor ( 255, 255, 255, 255 ), 0.9, bnt_font, 'left', 'top', false, false, false, true, false) 
end 
addEventHandler ( "onClientRender", getRootElement(), aliveplayers ) 
  
  
function getRaceAlivePlayers ( ) 
    local players = 0 
    for _, player in ipairs ( getElementsByType ( "player" ) ) do 
        if ( getElementData ( player, "state" ) == "alive" ) then 
            players = ( players + 1 ) 
        end 
    end 
  
    return players 
end 

Link to comment
  • Moderators

getRaceAlivePlayers already returns a number. Also, i think you should to use tostring instead.

bnt_font = dxCreateFont ( "fonts/bnt.ttf", 20 ) 
  
function aliveplayers ( ) 
local screenWidth, screenHeight = guiGetScreenSize() 
    dxDrawText ( '#006699ALIVE: #FFFFFF' .. tostring(getRaceAlivePlayers ( )), 2, screenHeight - dxGetFontHeight(0.7, bnt_font)/0.5, 0.5, 1.5, tocolor ( 255, 255, 255, 255 ), 0.9, bnt_font, 'left', 'top', false, false, false, true) 
end 
addEventHandler ( "onClientRender", getRootElement(), aliveplayers ) 
  
  
function getRaceAlivePlayers ( ) 
    local players = 0 
    for _, player in ipairs ( getElementsByType ( "player" ) ) do 
        if ( getElementData ( player, "state" ) == "alive" ) then 
            players = ( players + 1 ) 
        end 
    end 
  
    return players 
end 

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...