Jump to content
×
×
  • Create New...
  • 0

[Question] Returning highest level player via sql for quest


Invictus

Question

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

  • Answers 5
  • Created
  • Last Reply

Top Posters For This Question

Popular Days

Top Posters For This Question

5 answers to this question

Recommended Posts

  • 0

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

  • 0
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

  • 0

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

Link to comment
Share on other sites

  • 0
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

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


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.