Jump to content

what's worng with this


Best-Killer

Recommended Posts

addEvent( 'setData', true ) 
addEventHandler ( 'setData', root,
 function (data) 
    table.sort ( data, function (a,b) return ( tonumber(a.clan_kills) or 0 ) > ( tonumber(b.clan_kills) or 0 )end)
    for k,v in ipairs ( data ) do 
    function drawtext ()
        test = tostring(v.clan_name).." - "..tostring(v.clan_kills).."kills"
        dxDrawText(test, x*1110, (y*552)+(y*(20*k)), x*1280, y*570, tocolor(255, 255, 255, 255), x*1.00, "default-bold", "left", "top", false, false, false, false, false)
       end
    addEventHandler("onClientPreRender", root, drawtext)
       if k == 10 then break end 
    end 
end)



function onButtonClick(button, buttonState)
    if (button == "left" and buttonState == "up") then
        if isMouseSetColor (x*1242, y*611, x*38, y*77) then
        removeEventHandler("onClientPreRender", root, drawshow)
        addEventHandler("onClientPreRender", root, drawlist)    
        triggerServerEvent( 'getData', localPlayer ) 
    elseif isMouseSetColor (x*1064, y*611, x*38, y*77) then
    removeEventHandler("onClientPreRender", root, drawtext)
    removeEventHandler("onClientPreRender", root, drawlist)
    addEventHandler("onClientPreRender", root, drawshow)
    end
end
end
addEventHandler("onClientClick", getRootElement(), onButtonClick)

0 errors but the dxrawtext not removed why ?? help 

Link to comment

if isMouseSetColor (x*1064, y*611, x*38, y*77) then

probably returns false

 

Also this is a BIG problem 

for k,v in ipairs ( data ) do 
	function drawtext ()
		...
	end
	addEventHandler("onClientPreRender", root, drawtext)
	...
end

 

Edited by LoPollo
Link to comment
function drawlist()
dxDrawImage(x*1102, y*531, x*178, y*237, "list.png",0,0,0,tocolor(255,255,255,255)) 
dxDrawImage(x*1064, y*611, x*38, y*77, "hide.png",0,0,0,tocolor(255,255,255,255))
dxDrawRectangle(x*1064, y*611, x*38, y*77, tocolor(0, 0, 0, 0), false)
 
end
function drawshow()
dxDrawRectangle(x*1242, y*611, x*38, y*77, tocolor(0, 0, 0, 0), false)
dxDrawImage(x*1242, y*611, x*38, y*77, "show.png",0,0,0,tocolor(255,255,255,255))  
end
addEventHandler("onClientPreRender", root, drawshow)

 

Link to comment
1 hour ago, LoPollo said:

something handled in drawlist

yes it is :/

 

Still remove the addEventHandler from the loop, it that function is added, added, added and added again then i don't know if one removeEventHandler will remove only 1 handler or all. But i can guess. And guessing makes me think that only one is removed, leaving the others doing their job

Short version: recode that part so there are no more X handlers drawing 1 text each, make only 1 handler that draw them all

addEventHandler ( 'setData', root,
 function (data) 
    table.sort ( data, function (a,b) return ( tonumber(a.clan_kills) or 0 ) > ( tonumber(b.clan_kills) or 0 )end)
    for k,v in ipairs ( data ) do 
    function drawtext ()
        test = tostring(v.clan_name).." - "..tostring(v.clan_kills).."kills"
        dxDrawText(test, x*1110, (y*552)+(y*(20*k)), x*1280, y*570, tocolor(255, 255, 255, 255), x*1.00, "default-bold", "left", "top", false, false, false, false, false)
       end
    addEventHandler("onClientPreRender", root, drawtext)
       if k == 10 then break end 
    end 
end)

 

 

EDIT: another faster solution is to remove all the handlers

Edited by LoPollo
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...