Jump to content

top wins


Fury

Recommended Posts

server:

function topmap( player, command ) 
local map = getResourceName ( exports['mapmanager']:getRunningGamemodeMap ( ) )  
local tableOrder = { } 
    for i, v in ipairs ( getAccounts ( ) ) do 
    table.insert ( 
        tableOrder, 
        { 
            name = getAccountData ( v, "nick" ) or getAccountName ( v ), 
            data = getAccountData ( v, map ) or 0 
        } 
            ) 
    end 
    table.sort ( 
        tableOrder, 
        function ( a, b ) 
            return ( tonumber ( a.data ) or 0 ) > ( tonumber ( b.data ) or 0 ) 
        end 
                ) 
    outputChatBox ( "#c0c0c0* Top 5 #abcdefwins #c0c0c0on this map:", root, 255, 255, 255, true ) 
    for i = 1, 5 do 
        outputChatBox ( "#c0c0c0* #abcdef".. i .."#c0c0c0. #abcdef".. tostring ( tableOrder [ i ].name ) .." #c0c0c0- #abcdef".. tostring ( tableOrder [ i ].data ).. "#c0c0c0x", root, 255, 255, 255, true ) 
    end 
end  
addEventHandler ( 'onMapStarting', root, topmap) 

hi i have this code. but i want to send top 5 to client side. ex:

cdxhq.png

how can i do it?

Link to comment
-- client side:
topTable = { } 
  
addEvent ( "returnTable", true ) 
addEventHandler ( "returnTable", root, 
    function ( newTable ) 
        topTable = newTable 
    end 
) 

And for the server side you trigger 'returnTable' event with the table.

server:

function topmap( player, command ) 
local map = getResourceName ( exports['mapmanager']:getRunningGamemodeMap ( ) )  
local tableOrder = { } 
    for i, v in ipairs ( getAccounts ( ) ) do 
    table.insert ( 
        tableOrder, 
        { 
            name = getAccountData ( v, "nick" ) or getAccountName ( v ), 
            data = getAccountData ( v, map ) or 0 
        } 
            ) 
    end 
    table.sort ( 
        tableOrder, 
        function ( a, b ) 
            return ( tonumber ( a.data ) or 0 ) > ( tonumber ( b.data ) or 0 ) 
        end 
                ) 
    for i = 1, 5 do 
        newTable = { "#c0c0c0"..i.." - #abcdef"..tostring ( tableOrder [ i ].name ).." #c0c0c0- #abcdef"..tostring ( tableOrder [ i ].data )..""} 
        triggerClientEvent ( "returnTable", newTable ) 
    end 
end  
addEventHandler ( 'onMapStarting', root, topmap) 

client:

topTable = { } 
  
  
addEvent ( "returnTable", true ) 
addEventHandler ( "returnTable", getRootElement(), 
    function ( newTable ) 
        topTable = newTable 
        setTimer(removeEventHandler,5000,1,"onClientRender", getRootElement(), yazdir) 
    end 
) 
local font = dxCreateFont("font.ttf") 
local fontsize = 1.7 
local x,y = guiGetScreenSize() 
function yazdir () 
    dxDrawImage(x-340, 20, 320, 200, "bgr.png") 
    dxDrawColoredText(topTable, x-320, 60, 360, 40, tocolor(255,140,0), fontsize, font) 
end 
addEventHandler("onClientRender", getRootElement(), yazdir) 
function dxDrawColoredText(str, ax, ay, bx, by, color, scale, font,left,top) 
  local pat = "(.-)#(%x%x%x%x%x%x)" 
  local s, e, cap, col = str:find(pat, 1) 
  local last = 1 
  while s do 
    if cap == "" and col then color = tocolor(tonumber("0x"..col:sub(1, 2)), tonumber("0x"..col:sub(3, 4)), tonumber("0x"..col:sub(5, 6)), 255) end 
    if s ~= 1 or cap ~= "" then 
      local w = dxGetTextWidth(cap, scale, font) 
      dxDrawText(cap, ax, ay, ax + w, by, color, scale, font,left,top,true) 
      ax = ax + w 
      color = tocolor(tonumber("0x"..col:sub(1, 2)), tonumber("0x"..col:sub(3, 4)), tonumber("0x"..col:sub(5, 6)), 255) 
    end 
    last = e + 1 
    s, e, cap, col = str:find(pat, last) 
  end 
  if last <= #str then 
    cap = str:sub(last) 
    local w = dxGetTextWidth(cap, scale, font) 
    dxDrawText(cap, ax, ay, ax + w, by, color, scale, font,left,top,true) 
  --end 
  end 
end 

cf50t.png

:/

Link to comment
Because you forgot to fill the "sendTo" argument at triggerClientEvent.

server:

function topmap( player, command ) 
local map = getResourceName ( exports['mapmanager']:getRunningGamemodeMap ( ) )  
local tableOrder = { } 
    for i, v in ipairs ( getAccounts ( ) ) do 
    table.insert ( 
        tableOrder, 
        { 
            name = getAccountData ( v, "nick" ) or getAccountName ( v ), 
            data = getAccountData ( v, map ) or 0 
        } 
            ) 
    end 
    table.sort ( 
        tableOrder, 
        function ( a, b ) 
            return ( tonumber ( a.data ) or 0 ) > ( tonumber ( b.data ) or 0 ) 
        end 
                ) 
    for i = 1, 5 do 
        newTable = { "#c0c0c0"..i.." - #abcdef"..tostring ( tableOrder [ i ].name ).." #c0c0c0- #abcdef"..tostring ( tableOrder [ i ].data )..""} 
        triggerClientEvent ( "returnTable", getRootElement(),newTable ) 
    end 
end  
addEventHandler ( 'onMapStarting', root, topmap) 

client:

topTable = { } 
addEvent ( "returnTable", true ) 
addEventHandler ( "returnTable", getRootElement(), 
    function ( newTable ) 
        topTable = newTable 
        setTimer(removeEventHandler,5000,1,"onClientRender", getRootElement(), yazdir) 
    end 
) 
local font = dxCreateFont("font.ttf") 
local fontsize = 1.7 
local x,y = guiGetScreenSize() 
function yazdir () 
    dxDrawImage(x-340, 20, 320, 200, "bgr.png") 
    dxDrawText (topTable, x-320, 60, 360, 40, tocolor(255,140,0), fontsize, font ) 
end 
addEventHandler("onClientRender", getRootElement(), yazdir) 

cf5jf.png

:/

Link to comment
topTable = { } 
  
addEvent ( "returnTable", true ) 
addEventHandler ( "returnTable", getRootElement(), 
    function ( newTable ) 
        topTable = newTable 
        setTimer(removeEventHandler,5000,1,"onClientRender", getRootElement(), yazdir) 
    end 
) 
  
local font = dxCreateFont ( "font.ttf" ) 
local fontsize = 1.7 
local x,y = guiGetScreenSize ( ) 
  
function yazdir ( ) 
    dxDrawImage( x-340, 20, 320, 200, "bgr.png" ) 
    for index, top in ipairs ( topTable ) do 
        dxDrawText ( tostring ( index ) .." - ".. top.name .." - ".. tostring ( top.data ), x-320, 60, 360, 40, tocolor(255,140,0), fontsize, font ) 
    end 
end 
addEventHandler ( "onClientRender", getRootElement(), yazdir ) 

You'll have to make so all the texts are created one after other by editing the "Y" position.

Link to comment

server:

function topmap( player, command ) 
local map = getResourceName ( exports['mapmanager']:getRunningGamemodeMap ( ) )  
local tableOrder = { } 
    for i, v in ipairs ( getAccounts ( ) ) do 
    table.insert ( 
        tableOrder, 
        { 
            name = getAccountData ( v, "nick" ) or getAccountName ( v ), 
            data = getAccountData ( v, map ) or 0 
        } 
            ) 
    end 
    table.sort ( 
        tableOrder, 
        function ( a, b ) 
            return ( tonumber ( a.data ) or 0 ) > ( tonumber ( b.data ) or 0 ) 
        end 
                ) 
    for i = 1, 5 do 
        newTable = { "#c0c0c0"..i.." - #abcdef"..tostring ( tableOrder [ i ].name ).." #c0c0c0- #abcdef"..tostring ( tableOrder [ i ].data )..""} 
        triggerClientEvent ( "returnTable", getRootElement(),newTable ) 
    end 
end  
addEventHandler ( 'onMapStarting', root, topmap) 

client:

topTable = { } 
  
addEvent ( "returnTable", true ) 
addEventHandler ( "returnTable", getRootElement(), 
    function ( newTable ) 
        topTable = newTable 
        setTimer(removeEventHandler,5000,1,"onClientRender", getRootElement(), yazdir) 
    end 
) 
  
local font = dxCreateFont ( "font.ttf" ) 
local fontsize = 1.7 
local x,y = guiGetScreenSize ( ) 
  
function yazdir ( ) 
    dxDrawImage( x-340, 20, 320, 200, "bgr.png" ) 
    for index, top in ipairs ( topTable ) do 
        dxDrawText ( tostring ( index ) .." - ".. top.name .." - ".. tostring ( top.data ), x-320, 60, 360, 40, tocolor(255,140,0), fontsize, font ) 
        dxDrawText ( tostring ( index ) .." - ".. top.name .." - ".. tostring ( top.data ), x-320, 120, 360, 40, tocolor(255,140,0), fontsize, font ) 
        dxDrawText ( tostring ( index ) .." - ".. top.name .." - ".. tostring ( top.data ), x-320, 180, 360, 40, tocolor(255,140,0), fontsize, font ) 
        dxDrawText ( tostring ( index ) .." - ".. top.name .." - ".. tostring ( top.data ), x-320, 240, 360, 40, tocolor(255,140,0), fontsize, font ) 
        dxDrawText ( tostring ( index ) .." - ".. top.name .." - ".. tostring ( top.data ), x-320, 300, 360, 40, tocolor(255,140,0), fontsize, font ) 
    end 
end 
addEventHandler ( "onClientRender", getRootElement(), yazdir ) 

cf5ut.png

is trigger is right? im not sure about that. it has to worked :/

Link to comment

Is wrong.

function topmap( player, command ) 
local map = getResourceName ( exports['mapmanager']:getRunningGamemodeMap ( ) ) 
local tableOrder = { } 
    for i, v in ipairs ( getAccounts ( ) ) do 
    table.insert ( 
        tableOrder, 
        { 
            name = getAccountData ( v, "nick" ) or getAccountName ( v ), 
            data = getAccountData ( v, map ) or 0 
        } 
            ) 
    end 
    table.sort ( 
        tableOrder, 
        function ( a, b ) 
            return ( tonumber ( a.data ) or 0 ) > ( tonumber ( b.data ) or 0 ) 
        end 
                ) 
     triggerClientEvent ( "returnTable", getRootElement(), tableOrder ) 
end 
addEventHandler ( 'onMapStarting', root, topmap) 

Link to comment
Is wrong.
function topmap( player, command ) 
local map = getResourceName ( exports['mapmanager']:getRunningGamemodeMap ( ) ) 
local tableOrder = { } 
    for i, v in ipairs ( getAccounts ( ) ) do 
    table.insert ( 
        tableOrder, 
        { 
            name = getAccountData ( v, "nick" ) or getAccountName ( v ), 
            data = getAccountData ( v, map ) or 0 
        } 
            ) 
    end 
    table.sort ( 
        tableOrder, 
        function ( a, b ) 
            return ( tonumber ( a.data ) or 0 ) > ( tonumber ( b.data ) or 0 ) 
        end 
                ) 
    for i = 1, 5 do 
        triggerClientEvent ( "returnTable", getRootElement(), tableOrder ) 
    end 
end 
addEventHandler ( 'onMapStarting', root, topmap) 

cf6hb.png

its weird :/

Link to comment
topTable = { } 
  
addEvent ( "returnTable", true ) 
addEventHandler ( "returnTable", getRootElement(), 
    function ( newTable ) 
        topTable = newTable 
        setTimer(removeEventHandler,5000,1,"onClientRender", getRootElement(), yazdir) 
    end 
) 
  
local font = dxCreateFont ( "font.ttf" ) 
local fontsize = 1.7 
local x,y = guiGetScreenSize ( ) 
  
function yazdir ( ) 
    dxDrawImage( x-340, 20, 320, 200, "bgr.png" ) 
    for index = 1, 5 do 
        local top = topTable [ index ] 
        dxDrawText ( tostring ( index ) .." - ".. top.name .." - ".. tostring ( top.data ), x-320, ( 60 * index ), 360, 40, tocolor ( 255, 140 ,0 ), fontsize, font ) 
    end 
end 
addEventHandler ( "onClientRender", getRootElement(), yazdir ) 

Link to comment
topTable = { } 
  
addEvent ( "returnTable", true ) 
addEventHandler ( "returnTable", getRootElement(), 
    function ( newTable ) 
        topTable = newTable 
        setTimer(removeEventHandler,5000,1,"onClientRender", getRootElement(), yazdir) 
    end 
) 
  
local font = dxCreateFont ( "font.ttf" ) 
local fontsize = 1.7 
local x,y = guiGetScreenSize ( ) 
  
function yazdir ( ) 
    dxDrawImage( x-340, 20, 320, 200, "bgr.png" ) 
    for index = 1, 5 do 
        local top = topTable [ index ] 
        dxDrawText ( tostring ( index ) .." - ".. top.name .." - ".. tostring ( top.data ), x-320, ( 60 * index ), 360, 40, tocolor ( 255, 140 ,0 ), fontsize, font ) 
    end 
end 
addEventHandler ( "onClientRender", getRootElement(), yazdir ) 

thank you so much :)

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