Jump to content

[Question] Returning highest level player via sql for quest


Recommended Posts

Hi, i've been working on another system for my server but i'm stuck on this one as it involves SQL query and i don't know much about them.

 

basically, what i need is a function that does the following

 

1) finds the player with the highest level & XP & player name

2)returns the name of the player

 

/// the reason to return the name of the player is so i can do something like this in the quest

"if pc.get_name() == getNameFunction(pc.get_name()) then"



I'd appreicate any help with this, even if you have a simlair code and just paste it and i'll adapt as long as it works along the same lines. i've tried multitple things but when i don't get any errors in it then i can't really debug it, ive tried many ways of just returning a value such as the level of the player then telling it to say it in chat but i couldnt get it to return the value unfortunately :/ any ideas or any help is appreciated ill try any ideas suggested and respond how it goes etc.

 

Thanks!

 

Invictus

 

 

Link to comment
Share on other sites

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

the function, trying to get it to select the name from the player with the highest level/exp then name Z = name and finally return z so it goes into the IF statement on the quest.

function max_level1(z)

mysql_query("SELECT `name` FROM player.player ORDER BY `level`, `exp` LIMIT 1, ".. z .." = WHERE `name`;'")
 
return z
end

QUEST - supposed to just check if you're the highest person on the server and if so it'll start the quest ( haven't written it yet, so I've just put it to alter my level to 30 as i'm on a test server)

quest lvl_max11 begin
	state start begin
		when login or levelup with pc.get_name() begin
				if pc.get_name() == pc.get_name(max_level1(z)) then
					pc2.set_level("30")
				end
		end			

	end
end	

this didn't work, i tried several other ways but no such luck :/ any ideas?

Link to comment
Share on other sites

select name,level from player.player order by level desc,exp desc;
function getHighestLevel() return tonumber(mysql_query("select level from player.player order by level desc,exp desc;")[1][1]) or 0 end
function highestLevelPlayer() return mysql_query("select name from player.player order by level desc,exp desc;")[1][1]) or "" end
Link to comment
Share on other sites

select name,level from player.player order by level desc,exp desc;
function getHighestLevel() return tonumber(mysql_query("select level from player.player order by level desc,exp desc;")[1][1]) or 0 end
function highestLevelPlayer() return mysql_query("select name from player.player order by level desc,exp desc;")[1][1]) or "" end

 

Thanks for the response -

 

upon implementing that i get the following error -

 

 

SYSERR: May  3 12:55:06 :: ChildLoop: AsyncSQL: query failed: Incorrect integer value: 'Y' for column 'is_gm' at row 1 (query: INSERT INTO loginlog2(type, is_gm, login_time, channel, account_id, pid, ip, client_version) VALUES('INVALID', 'Y', NOW(), 1, 52189, 57846, inet_aton('213.104.150.58'), '') errno: 1366)
SYSERR: May  3 12:55:06 :: ChildLoop: MySQL connection was reconnected. querying locale set
SYSERR: May  3 12:55:44 :: RunState: LUA_ERROR: locale/germany/quest/questlib.lua:2518: attempt to call global `mysql_query' (a nil value)
SYSERR: May  3 12:55:44 :: WriteRunningStateToSyserr: LUA_ERROR: quest lvl_max11.start click
SYSERR: May  3 12:55:56 :: RunState: LUA_ERROR: locale/germany/quest/questlib.lua:2518: attempt to call global `mysql_query' (a nil value)
SYSERR: May  3 12:55:56 :: WriteRunningStateToSyserr: LUA_ERROR: quest lvl_max11.start click


I had to alter the function to

 

function highestLevelPlayer() 


z =  mysql_query("select name from player.player order by level desc,exp desc;")[1][1] or "" 

return z

end 

because i got this error and putting the extra end on and trying other stuff wouldnt make it go away -

 

hvMZFDL.png

Edited by Metin2 Dev
Core X - External 2 Internal
Link to comment
Share on other sites

SYSERR: May  3 12:55:06 :: ChildLoop: AsyncSQL: query failed: Incorrect integer value: 'Y' for column 'is_gm' at row 1 (query: INSERT INTO loginlog2(type, is_gm, login_time, channel, account_id, pid, ip, client_version) VALUES('INVALID', 'Y', NOW(), 1, 52189, 57846, inet_aton('213.104.150.58'), '') errno: 1366)
SYSERR: May  3 12:55:06 :: ChildLoop: MySQL connection was reconnected. querying locale set
SYSERR: May  3 12:55:44 :: RunState: LUA_ERROR: locale/germany/quest/questlib.lua:2518: attempt to call global `mysql_query' (a nil value)
SYSERR: May  3 12:55:44 :: WriteRunningStateToSyserr: LUA_ERROR: quest lvl_max11.start click
SYSERR: May  3 12:55:56 :: RunState: LUA_ERROR: locale/germany/quest/questlib.lua:2518: attempt to call global `mysql_query' (a nil value)
SYSERR: May  3 12:55:56 :: WriteRunningStateToSyserr: LUA_ERROR: quest lvl_max11.start click

You didn't implemented the mysql query function

 

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.