Wisin Posted October 26, 2010 Share Posted October 26, 2010 hi everyone, im trying to make a script that will get the 2 players who have more hours, but i have no clue how to make it, if anyone can give me a start. addCommandHandler("toptime", function (thePlayer) outputChatBox ("Top time online", thePlayer, 153, 51, 255, true) for k,v in ipairs(players) do local account = getPlayerAccount(v) local accountname = getAccountName(account) local hours = executeSQLSelect ( "rol_time", "H","Player = '" .. accountname .. "'") local h = hours[1]["H"] local nick = getPlayerName(v) outputChatBox(nick.." ".. tostring(h) .." hours", getRootElement (), 255, 255, 0, false) end end) Link to comment
dzek (varez) Posted October 26, 2010 Share Posted October 26, 2010 2 players who have more hours i dont get what you mean Link to comment
12p Posted October 26, 2010 Share Posted October 26, 2010 I guess he wants to get the 2 players that have played more hours than others. Link to comment
Wisin Posted October 27, 2010 Author Share Posted October 27, 2010 Yes thats what i want ! Link to comment
[DMC] Posted October 27, 2010 Share Posted October 27, 2010 2 players who have more hours i dont get what you mean i think he means a table with Wisin 2 player 1 Link to comment
dzek (varez) Posted October 27, 2010 Share Posted October 27, 2010 executeSQLQuery("SELECT * FROM your_table ORDER BY play_time LIMIT 2") replace * if you need to select only columns you need (like: playername) replace your_table with table name replace play_time with play time column name edit: i see you want to get two best times from online players.. something like that function getTop2() local top = { "times" = { 0, 0 }, "accs" = { nil, nil } } for key,val in ipairs(getElementsByType("player") do local time = replace_this_with_your_query if tonumber(time) > top['times'][1] then top['times'][2] = top['times'][1] top['accs'][2] = top['accs'][1] top['times'][1] = tonumber(time) top['accs'][1] = getPlayerAccount(val) elseif tonumber(time) > top['times'][1] then top['times'][2] = tonumber(time) top['accs'][2] = getPlayerAccount(val) end end end Link to comment
Wisin Posted October 28, 2010 Author Share Posted October 28, 2010 dont work this code, function getTop2() outputChatBox ("Top time online", getRootElement(), 153, 51, 255, true) local top = { "times" = { 0, 0 }, "accs" = { nil, nil } } for key,val in ipairs(getElementsByType("player") do local account = getPlayerAccount(val) local accountname = getAccountName(account) local time = executeSQLSelect ( "rol_time", "H","Player = '" .. accountname .. "'") if tonumber(time) > top['times'][1] then top['times'][2] = top['times'][1] top['accs'][2] = top['accs'][1] top['times'][1] = tonumber(time) top['accs'][1] = getPlayerAccount(val) local nick = getPlayerName(val) elseif tonumber(time) > top['times'][1] then top['times'][2] = tonumber(time) top['accs'][2] = getPlayerAccount(val) local nick = getPlayerName(val) end outputChatBox(nick.." ".. tostring(h) .." hours", getRootElement (), 255, 255, 0, false) end end addCommandHandler("toptime",getTop2) error: 498: '}' expected (to close '{' at line 497) near '=' Link to comment
CowTurbo Posted October 28, 2010 Share Posted October 28, 2010 there isnt 498 line. please give correct line, show us the code from 495-500 please. Link to comment
dzek (varez) Posted October 28, 2010 Share Posted October 28, 2010 omg guys, you cant read? syntax errors are perfectly easy to spot and fix, as you can read WHAT is wrong, and WHERE (and most times: HOW TO FIX).. probably the problem is here: local top = { "times" = { 0, 0 }, "accs" = { nil, nil } } local top = { ["times"] = { 0, 0 }, ["accs"] = { nil, nil } } Link to comment
Wisin Posted October 28, 2010 Author Share Posted October 28, 2010 there isnt 498 line.please give correct line, show us the code from 495-500 please. i cant post that part its not from this function, that worked varez but now when i put /toptime says 1 errors attempt to compare number with nil at line: if tonumber(time) > top['times'][1] then Link to comment
dzek (varez) Posted October 28, 2010 Share Posted October 28, 2010 THINK A LITTLE .. I'm trying to HELP you, and you are waiting for ready-to-go script.. stare at those lines until you will find your error: local time = executeSQLSelect ( "rol_time", "H","Player = '" .. accountname .. "'") if tonumber(time) > top['times'][1] then hint for you: viewtopic.php?f=91&t=29725#p324915 Link to comment
Wisin Posted October 28, 2010 Author Share Posted October 28, 2010 ok i fixed that but now works but my friend have 3 hours and me 2 and he is down, why? function getTop2() outputChatBox ("Top time online", getRootElement(), 153, 51, 255, true) local top = { ["times"] = { 0, 0 }, ["accs"] = { nil, nil } } for key,val in ipairs(getElementsByType("player")) do local account = getPlayerAccount(val) local accountname = getAccountName(account) local time = executeSQLSelect ( "rol_time", "H","Player = '" .. accountname .. "'") local h = time[1]["H"] if tonumber(h) > top['times'][1] then top['times'][2] = top['times'][1] top['accs'][2] = top['accs'][1] top['times'][1] = tonumber(h) top['accs'][1] = getPlayerAccount(val) local nick = getPlayerName(val) outputChatBox(nick.." ".. tostring(h) .." hours", getRootElement (), 255, 255, 0, false) elseif tonumber(h) > top['times'][1] then top['times'][2] = tonumber(h) top['accs'][2] = getPlayerAccount(val) local nick = getPlayerName(val) outputChatBox(nick.." ".. tostring(h) .." hours", getRootElement (), 255, 255, 0, false) end end end addCommandHandler("toptime",getTop2) Link to comment
dzek (varez) Posted October 28, 2010 Share Posted October 28, 2010 because you didnt try to understand how its working. these outputChatBox'es are inside the loop! after loop (just before function end) you can access these values: top["times"][1] - time of player on top 1 top["accs"][1] - account element of player on top 1 same for 2 if you need players elements in table - simply add it like the "accs" values are assigned. with a little trying you can do it Link to comment
[DMC] Posted October 30, 2010 Share Posted October 30, 2010 ok i fixed that but now works but my friend have 3 hours and me 2 and he is down, why? function getTop2() outputChatBox ("Top time online", getRootElement(), 153, 51, 255, true) local top = { ["times"] = { 0, 0 }, ["accs"] = { nil, nil } } for key,val in ipairs(getElementsByType("player")) do local account = getPlayerAccount(val) local accountname = getAccountName(account) local time = executeSQLSelect ( "rol_time", "H","Player = '" .. accountname .. "'") local h = time[1]["H"] if tonumber(h) > top['times'][1] then top['accs'][1] = getPlayerAccount(val) local nick = getPlayerName(val) outputChatBox(nick.." ".. tostring(h) .." hours", getRootElement (), 255, 255, 0, false) top['times'][1] = tonumber(h) top['accs'][1] = getPlayerAccount(val) elseif tonumber(h) > top['times'][1] then local nick = getPlayerName(val) outputChatBox(nick.." ".. tostring(h) .." hours", getRootElement (), 255, 255, 0, false) top['times'][1] = top['times'][1] top['accs'][1] = top['accs'][1] top['times'][1] = tonumber(h) end end end addCommandHandler("toptime",getTop2) i think he means this Link to comment
Wisin Posted October 30, 2010 Author Share Posted October 30, 2010 because you didnt try to understand how its working. these outputChatBox'es are inside the loop!after loop (just before function end) you can access these values: top["times"][1] - time of player on top 1 top["accs"][1] - account element of player on top 1 same for 2 if you need players elements in table - simply add it like the "accs" values are assigned. with a little trying you can do it i dont understand what you mean Link to comment
dzek (varez) Posted October 30, 2010 Share Posted October 30, 2010 oh my ..... function getTop2() outputChatBox ("Top time online", getRootElement(), 153, 51, 255, true) local top = { ["times"] = { 0, 0 }, ["accs"] = { nil, nil } ["pls"] = { nil, nil } } for key,val in ipairs(getElementsByType("player")) do local account = getPlayerAccount(val) local accountname = getAccountName(account) local time = executeSQLSelect ( "rol_time", "H","Player = '" .. accountname .. "'") local h = time[1]["H"] if tonumber(h) > top['times'][1] then top['times'][2] = top['times'][1] top['accs'][2] = top['accs'][1] top['pls'][2] = top['pls'][1] top['times'][1] = tonumber(h) top['accs'][1] = getPlayerAccount(val) top['pls'][1] = val elseif tonumber(h) > top['times'][1] then top['times'][2] = tonumber(h) top['accs'][2] = getPlayerAccount(val) top['pls'][2] = val end end outputChatBox("top1: player: "..getPlayerName(top['pls'][1])..", account: "..getAccountName(top['accs'][1])..", time: ".. top['times'][1]) outputChatBox("top2: player: "..getPlayerName(top['pls'][2])..", account: "..getAccountName(top['accs'][2])..", time: ".. top['times'][2]) end addCommandHandler("toptime",getTop2) and i hope before copying-pasting it you will try to read it, until you understand it, as i give you ready solution .. Link to comment
Albinix Posted November 3, 2010 Share Posted November 3, 2010 executeSQLQuery("SELECT * FROM your_table ORDER BY play_time LIMIT 2") replace * if you need to select only columns you need (like: playername) replace your_table with table name replace play_time with play time column name addCommandHandler ("Top", function(player,command) top = executeSQLQuery("SELECT Name, Points FROM Money ORDER BY Points LIMIT 5") for i, playerdata in ipairs(top) do outputChatBox(playerdata.Name .. ": " .. playerdata.Points, player) end end) I'm not so good at this SQL things so i wonder what is wrong? they are no errors Link to comment
Wisin Posted November 3, 2010 Author Share Posted November 3, 2010 all works with varez code but when a player dont has account it says errors and not works Link to comment
dzek (varez) Posted November 3, 2010 Share Posted November 3, 2010 is it too hard to you to add one "if"..? Link to comment
Wisin Posted November 3, 2010 Author Share Posted November 3, 2010 no is not, i have added "if account then" now i go test. Edit: not working it says error in line: local h = time[1]["H"] attempt to index field '?' (a nil value) function getTop3() outputChatBox ("Top time online", getRootElement(), 153, 51, 255, true) local top = { ["times"] = { 0, 0, 0 }, ["accs"] = { nil, nil, nil }, ["pls"] = { nil, nil, nil }, } for key,val in ipairs(getElementsByType("player")) do local account = getPlayerAccount(val) if account then local accountname = getAccountName(account) local time = executeSQLSelect ( "rol_time", "H","Player = '" .. accountname .. "'") local h = time[1]["H"] if tonumber(h) > top['times'][1] then top['times'][2] = top['times'][1] top['accs'][2] = top['accs'][1] top['pls'][2] = top['pls'][1] top['times'][1] = tonumber(h) top['accs'][1] = getPlayerAccount(val) top['pls'][1] = val elseif tonumber(h) > top['times'][1] then top['times'][2] = tonumber(h) top['accs'][2] = getPlayerAccount(val) top['pls'][2] = val end end end outputChatBox("top1: player: "..getPlayerName(top['pls'][1])..", hours: ".. top['times'][1],getRootElement(),255,0,0) outputChatBox("top2: player: "..getPlayerName(top['pls'][2])..", hours: ".. top['times'][2],getRootElement(),0,255,0) outputChatBox("top3: player: "..getPlayerName(top['pls'][3])..", hours: ".. top['times'][3],getRootElement(),0,0,255) end addCommandHandler("toptime",getTop3) Link to comment
dzek (varez) Posted November 3, 2010 Share Posted November 3, 2010 because your query returns nothing local time = executeSQLSelect ( "rol_time", "H","Player = '" .. accountname .. "'") if time~=nil and #time>0 then Link to comment
Wisin Posted November 3, 2010 Author Share Posted November 3, 2010 nop still not working error: attempt to compare number with nil line: if tonumber(h) > top['times'][1] then Link to comment
dzek (varez) Posted November 3, 2010 Share Posted November 3, 2010 post current script Link to comment
Wisin Posted November 3, 2010 Author Share Posted November 3, 2010 function getTop3() outputChatBox ("Top time online", getRootElement(), 153, 51, 255, true) local top = { ["times"] = { 0, 0, 0 }, ["accs"] = { nil, nil, nil }, ["pls"] = { nil, nil, nil }, } for key,val in ipairs(getElementsByType("player")) do local account = getPlayerAccount(val) if account then local accountname = getAccountName(account) local time = executeSQLSelect ( "rol_time", "H","Player = '" .. accountname .. "'") if time~=nil and #time>0 then if tonumber(h) > top['times'][1] then top['times'][2] = top['times'][1] top['accs'][2] = top['accs'][1] top['pls'][2] = top['pls'][1] top['times'][1] = tonumber(h) top['accs'][1] = getPlayerAccount(val) top['pls'][1] = val elseif tonumber(h) > top['times'][1] then top['times'][2] = tonumber(h) top['accs'][2] = getPlayerAccount(val) top['pls'][2] = val end end end end outputChatBox("top1: player: "..getPlayerName(top['pls'][1])..", hours: ".. top['times'][1],getRootElement(),255,0,0) outputChatBox("top2: player: "..getPlayerName(top['pls'][2])..", hours: ".. top['times'][2],getRootElement(),0,255,0) outputChatBox("top3: player: "..getPlayerName(top['pls'][3])..", hours: ".. top['times'][3],getRootElement(),0,0,255) end addCommandHandler("toptime",getTop3) thats it Link to comment
dzek (varez) Posted November 3, 2010 Share Posted November 3, 2010 there was no need of removing this line local h = time[1]["H"] 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