Jump to content

Hud messages


Msypon

Recommended Posts

  • Moderators

Well maybe then I should first check your export.....

("test", root,255,0,1000) 
  
local R,G,B = 255,0,0 
--[[ is it: ]] ("test", root,R,G,B)--? (B can't be higher then 255) 
--or 
local time = 2000 
local Repeated = 1 
local R = 255 
--[[ is it: ]] ("test", root,R,Repeated--[[(0= infinity, 1=1x, 2=2x, etc)]],time)--? 

You can't expect that I know how this hud export fits.

Edited by Guest
Link to comment

this is the code

client

local x, y = guiGetScreenSize() 
local boxes = {} 
local timers = {} 
local id = 1 
  
function showBox(text, r, g, b, t) 
    if not r or not g or not b then r, g, b = 255, 255, 255 end 
    if not t then return end 
    local color = tocolor(r, g, b, 255) or -1 
    if t > 100 then 
        playSoundFrontEnd ( 13 ) 
        boxes[id] = {text, color} 
        timers[id] = setTimer(destroyBox,t,1,id) 
        id = id + 1 
    end   
end 
  
function destroyBox(ids) 
    boxes[ids] = nil 
end 
  
function drawBoxes() 
    local nextx = 0 
    local nexty = 0 
    for i,tab in pairs(boxes) do 
        nextx = x/2 - string.len(tab[1])*7.5/2 
        dxDrawRectangle(nextx, nexty,string.len(tab[1])*8.5, 17, tocolor(0, 0, 0, 85)) 
        dxDrawText(tab[1], nextx + 5, nexty, nextx - 10, nexty, tab[2], 1.0, "sans", "left", "top") 
        nextx = nextx 
        nexty = nexty + 17 
    end 
end 
  
addEvent("showBox", true) 
addEventHandler("showBox", root, showBox) 
addEventHandler("onClientRender", root, drawBoxes) 

server

function showBox(str, player, r, g, b, t) 
    if isElement(player) then 
        triggerClientEvent(player, "showBox", root, str, r, g, b, t) 
    end 
end 

Link to comment
  • Moderators

Did you try to debug your code?

/debugscript 3

and add some outputDebugString("....")

it is much easier to find the bug.

The code looks fine,

try:

function destroyBox(ids)

boxes[ids] = nil

outputDebugString(ids .. " is nil")

end

Link to comment
  • Moderators

This should work...

How many times does this function get executed?

  
function showBox(text, r, g, b, t) 
    if not r or not g or not b then r, g, b = 255, 255, 255 end 
    if not t then return end 
    local color = tocolor(r, g, b, 255) or -1 
    if t > 100 then 
        playSoundFrontEnd ( 13 ) 
        boxes[id] = {text, color} 
        timers[id] = setTimer(destroyBox,t,1,id) 
        id = id + 1 
        outputChatBox("executed!" ) 
    end   
end 

Link to comment
local x, y = guiGetScreenSize() 
local boxes = {} 
local timers = {} 
local texts = { } 
local id = 1 
  
function showBox(text, r, g, b, t) 
    if not r or not g or not b then r, g, b = 255, 255, 255 end 
    if not t then return end 
    if ( texts [ text ] ) then 
        return 
    end 
  
    local color = tocolor(r, g, b, 255) or -1 
    if t > 100 then 
        playSoundFrontEnd ( 13 ) 
        boxes[id] = {text, color} 
        timers[id] = setTimer(destroyBox,t,1,id) 
        texts [ text ] = true 
        id = id + 1 
    end   
end 
  
function destroyBox(ids) 
    local text = boxes[ids] [ 1 ] 
    boxes[ids] = nil 
    texts [ text ] = nil 
end 
  
function drawBoxes() 
    local nextx = 0 
    local nexty = 0 
    for i,tab in pairs(boxes) do 
        nextx = x/2 - string.len(tab[1])*7.5/2 
        dxDrawRectangle(nextx, nexty,string.len(tab[1])*8.5, 17, tocolor(0, 0, 0, 85)) 
        dxDrawText(tab[1], nextx + 5, nexty, nextx - 10, nexty, tab[2], 1.0, "sans", "left", "top") 
        nextx = nextx 
        nexty = nexty + 17 
    end 
end 
  
addEvent("showBox", true) 
addEventHandler("showBox", root, showBox) 
addEventHandler("onClientRender", root, drawBoxes) 

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