mtamaster97 Posted November 15, 2014 Share Posted November 15, 2014 Can someone tell me whats wrong with this code?? Client.lua: topTable = { } addEvent ( "returnTable", true ) addEventHandler ( "returnTable", getRootElement(), function ( newTable ) topTable = newTable setTimer(removeEventHandler,5000,1,"onClientRender", getRootElement(), renderMapWins) end ) local winners = { } local localData = { } local mapName = "" local state = false local sx, sy = guiGetScreenSize ( ) local x,y = guiGetScreenSize ( ) function renderMapWins ( ) if ( state ) then dxDrawRectangle ( x-250, 60, 240, 200, tocolor(0,0,0,180), false ) dxDrawRectangle ( x-250, 60, 240, 26, tocolor(255, 0, 0, 200), false ) dxDrawText ( tostring ( mapName ), x-245, 80, 250, 60, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "center", false, false, true, false, false ) for index = 1, 8 do local top = topTable [ index ] dxDrawText ( "\n\n\n\n\n#FF0000".. tostring ( index ) ..". #FFFFFF".. tostring( top.name ), x-245, ( 20 * index ), 250, 120, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, true, false ) dxDrawText ( "\n\n\n\n\n"..tostring ( top.data ).." #ff0000wins", x-50, ( 20 * index ), x-15, 40, tocolor(255, 255, 255, 255), 1.00, "default-bold", "right", "top", false, false, true, true, false ) end else removeEventHandler ( "onClientRender", root, renderMapWins ) end end addEvent ( "onClientMapStarting", true ) addEventHandler ( "onClientMapStarting", root, function ( mapInfo ) mapName = mapInfo.name addEventHandler ( "onClientRender", root, renderMapWins ) bindKey ( "F5", "down", showMapWins ) state = true --triggerServerEvent ( "mapWins:requestList", localPlayer ) hideTimer = setTimer ( function ( ) if ( state ) then showMapWins ( ) end end ,10000, 1 ) end ) addEvent ( "mapWins:returnList", true ) addEventHandler ( "mapWins:returnList", root, function ( winners_ ) winners = { } localData = { } for index, winner in ipairs ( winners_ ) do if ( index < 11 ) then table.insert ( winners, { serial = winner.serial, nick = top.name, wins = top.kill } ) end if ( winner.serial == getPlayerSerial ( ) ) then localData = { rank = index, nick = winner.nick, wins = winner.wins } end end end ) addEvent ( "onClientMapStopping", true ) addEventHandler ( "onClientMapStopping", root, function ( ) removeEventHandler ( "onClientRender", root, renderMapWins ) winners = { } localData = { } unbindKey ( "F5", "down", showMapWins ) state = false mapName = "" if ( isTimer ( hideTimer ) ) then killTimer ( hideTimer ) end end ) function showMapWins ( ) state = ( not state ) removeEventHandler ( "onClientRender", root, renderMapWins ) if ( state ) then --triggerServerEvent ( "mapWins:requestList", localPlayer ) addEventHandler ( "onClientRender", root, renderMapWins ) else if ( isTimer ( hideTimer ) ) then killTimer ( hideTimer ) end end end addEvent ( "mapWins:show", true ) addEventHandler ( "mapWins:show", root, function ( ) if ( not state ) then showMapWins ( ) end end ) Server.lua: 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) function refresh(thePlayer) local account = getPlayerAccount(source) setAccountData(account, "nick", getPlayerName(source) ) end addEventHandler("onPlayerConnect", getRootElement(), refresh) addEventHandler("onPlayerWasted", getRootElement(), refresh) addEventHandler("onPlayerChangeNick", getRootElement(), refresh) addEventHandler("onPlayerLogin", getRootElement(), refresh) Link to comment
Mr_Moose Posted November 16, 2014 Share Posted November 16, 2014 Try '/debugscript 3' and post the output. Link to comment
mtamaster97 Posted December 1, 2014 Author Share Posted December 1, 2014 ERROR: topwins/topc.lua:28: attempt to index local 'top' (a nill value) Link to comment
Hex547 Posted December 1, 2014 Share Posted December 1, 2014 for index = 1, 8 do local top = topTable [ index ] dxDrawText ( "\n\n\n\n\n#FF0000".. tostring ( index ) ..". #FFFFFF".. tostring( top.name ), x-245, ( 20 * index ), 250, 120, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, true, false ) dxDrawText ( "\n\n\n\n\n"..tostring ( top.data ).." #ff0000wins", x-50, ( 20 * index ), x-15, 40, tocolor(255, 255, 255, 255), 1.00, "default-bold", "right", "top", false, false, true, true, false ) end Here you aren't checking to see if topTable is actually populated with results before trying to find index's. Also you should check to make sure each index garners a result as well before attempting to get the .data and .name from it. Also I don't see the events you're creating every being triggered in the scripts, which is obviously your own deal, but topTable is only populated through the first event, so if you're never triggering it, you'll never be able to get anything from it. Other than that it looks OK, good luck! Link to comment
mtamaster97 Posted December 1, 2014 Author Share Posted December 1, 2014 can u fix the code above? cuz I bought this resource and it doesn't work. guy that sold me that deleted me on skype and I don't understand what u mean by checking each index. If anyone have bit of time to fix it I 'd appreciate that Link to comment
Moderators IIYAMA Posted December 1, 2014 Moderators Share Posted December 1, 2014 That you forgot to check this guy is your problem. You should ask him to show the result before you paid him. This section is not for requesters like you. Link to comment
Mr_Moose Posted December 1, 2014 Share Posted December 1, 2014 can u fix the code above? cuz I bought this resource and it doesn't work. guy that sold me that deleted me on skype and I don't understand what u mean by checking each index. If anyone have bit of time to fix it I 'd appreciate that Well I guess you just got scammed by this guy, however indexes are easy to check, just check if a certain index returns nil like this: theTable = { } if theTable[theIndex] then -- theTable has a value at theIndex else -- theTable is empty at theIndex end Multi dimensional arrays is a bit tricky thought but here 's one way you could solve it: theTable = {{ }} if theTable[theIndex] then -- theTable has a value at theIndex else theTable[theIndex] = { } -- Make a new array if empty end We're here to help, not to do your job. 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