Fury Posted August 29, 2012 Share Posted August 29, 2012 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: how can i do it? Link to comment
MIKI785 Posted August 29, 2012 Share Posted August 29, 2012 triggerClientEvent and use dxDrawing to show that? Link to comment
Fury Posted August 29, 2012 Author Share Posted August 29, 2012 triggerClientEvent and use dxDrawing to show that? can you give me a example to send all table to client side and dxdraw it? Link to comment
Castillo Posted August 29, 2012 Share Posted August 29, 2012 You should make a table client side, and trigger a event from server with the new table, so you can update client side one. Link to comment
Fury Posted August 29, 2012 Author Share Posted August 29, 2012 You should make a table client side, and trigger a event from server with the new table, so you can update client side one. can you give me a example please? Link to comment
Castillo Posted August 29, 2012 Share Posted August 29, 2012 -- 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. Link to comment
Fury Posted August 29, 2012 Author Share Posted August 29, 2012 -- 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 Link to comment
Castillo Posted August 29, 2012 Share Posted August 29, 2012 Because you forgot to fill the "sendTo" argument at triggerClientEvent. Link to comment
Fury Posted August 29, 2012 Author Share Posted August 29, 2012 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) Link to comment
Castillo Posted August 29, 2012 Share Posted August 29, 2012 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
Fury Posted August 29, 2012 Author Share Posted August 29, 2012 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 ) is trigger is right? im not sure about that. it has to worked Link to comment
Castillo Posted August 29, 2012 Share Posted August 29, 2012 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
Fury Posted August 29, 2012 Author Share Posted August 29, 2012 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) its weird Link to comment
Fury Posted August 30, 2012 Author Share Posted August 30, 2012 Copy my code again. same problem. is there a way to make "dxTable"? its drawing all in same line. and its shows all accounts not for 5. Link to comment
Castillo Posted August 30, 2012 Share Posted August 30, 2012 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
Fury Posted August 30, 2012 Author Share Posted August 30, 2012 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now