• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Rank Statue

luigilc

Lua Learner
Joined
Mar 24, 2010
Messages
863
Reaction score
37
Location
A music box
I need a lil help to make this script work:
LUA:
function onLook(cid, thing, position, lookDistance)
	query = db.getResult("SELECT * FROM `players` ORDER BY `level`")
	doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You see a monument with a plate: 'The highest leveled player in the world is " .. query:getDataString("name") .. "'!")
	query:free()
	return true
end
I need to make it only if you look at the statue with id 9751 you see the top level player on your ot. I'm bad at scripting and I tried something like:
LUA:
 function onLook(cid, thing, position, lookDistance)
                  if (item.id, 9751) then
	query = db.getResult("SELECT * FROM `players` ORDER BY `level`")
	doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You see a monument with a plate: 'The highest leveled player in the world is " .. query:getDataString("name") .. "'!")
	query:free()
	return true
end

but it doesn't work, can anyone help me out?
 
It gives this error on sonsole using you code Santi:
LUA:
 [27/08/2011 19:00:24] [Error - LuaScriptInterface::loadFile] data/creaturescripts/scripts/rankstatue.lua:7: 'end' expected (to close 'function' at line 1) near '<eof>'
[27/08/2011 19:00:24] [Warning - Event::loadScript] Cannot load script (data/creaturescripts/scripts/rankstatue.lua)
[27/08/2011 19:00:24] data/creaturescripts/scripts/rankstatue.lua:7: 'end' expected (to close 'function' at line 1) near '<eof>'
 
Lolo, I didn't code, just wanting to help you :PP
Just add an end yeye.
LUA:
 function onLook(cid, thing, position, lookDistance)
       if (item.itemid == 9751) then
	query = db.getResult("SELECT * FROM `players` ORDER BY `level`")
	doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You see a monument with a plate: 'The highest leveled player in the world is " .. query:getDataString("name") .. "'!")
	query:free()
        end
	return true
end
 
LUA:
[27/08/2011 23:04:04] [Error - CreatureScript Interface] 
[27/08/2011 23:04:04] data/creaturescripts/scripts/rankstatue.lua:onLook
[27/08/2011 23:04:04] Description: 
[27/08/2011 23:04:04] data/creaturescripts/scripts/rankstatue.lua:2: attempt to index global 'item' (a nil value)
[27/08/2011 23:04:04] stack traceback:
[27/08/2011 23:04:04] 	data/creaturescripts/scripts/rankstatue.lua:2: in function <data/creaturescripts/scripts/rankstatue.lua:1>
 
Code:
function onLook(cid, thing, position, lookDistance)
statue = [COLOR="#FF0000"]{x=x, y=y, z=z}[/COLOR]
item = getThingFromPos(statue)
       if (item.itemid == 9751) then
	query = db.getResult("SELECT * FROM `players` ORDER BY `level`")
	doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You see a monument with a plate: 'The highest leveled player in the world is " .. query:getDataString("name") .. "'!")
	query:free()
        end
	return true
end

If there's only one statue you can determine whats "item" by saying it is the thing on the pos.
Statue position
 
Code:
[FONT=Courier New][COLOR=#0000FF][B]local[/B][/COLOR] GROUP_FILTER [COLOR=#FF0000]=[/COLOR] 3 [COLOR=#008000][I]-- this is the highscore cutoff (it's usually 3 for gods and 2 for tutors, so we start at 3)[/I][/COLOR]
[COLOR=#0000FF][B]function[/B][/COLOR] onLook[COLOR=#FF0000]([/COLOR]cid[COLOR=#FF0000],[/COLOR] thing[COLOR=#FF0000],[/COLOR] position[COLOR=#FF0000],[/COLOR] lookDistance[COLOR=#FF0000])[/COLOR]
    [COLOR=#0000FF][B]if[/B][/COLOR][COLOR=#FF0000]([/COLOR]thing[COLOR=#FF0000].[/COLOR]itemid[COLOR=#FF0000])[/COLOR][COLOR=#0000FF][B]then[/B][/COLOR] [COLOR=#008000][I]-- yay it's an item, we won't get a nil error![/I][/COLOR]
        [COLOR=#0000FF][B]if[/B][/COLOR][COLOR=#FF0000]([/COLOR]thing[COLOR=#FF0000].[/COLOR]itemid [COLOR=#FF0000]=[/COLOR][COLOR=#FF0000]=[/COLOR] 9751[COLOR=#FF0000])[/COLOR][COLOR=#0000FF][B]then[/B][/COLOR] [COLOR=#008000][I]-- now that we know its safe to index this value, we can check the itemid[/I][/COLOR]
            [COLOR=#0000FF][B]local[/B][/COLOR] player [COLOR=#FF0000]=[/COLOR] db[COLOR=#FF0000].[/COLOR]getResult[COLOR=#FF0000]([/COLOR][COLOR=#800080][B]"SELECT name, level FROM `players` WHERE group_id < "[/B][/COLOR] [COLOR=#FF0000].[/COLOR][COLOR=#FF0000].[/COLOR] GROUP_FILTER [COLOR=#FF0000].[/COLOR][COLOR=#FF0000].[/COLOR] [COLOR=#800080][B]" ORDER BY `level` DESC LIMIT 1;"[/B][/COLOR][COLOR=#FF0000])[/COLOR]
            [COLOR=#0000FF][B]local[/B][/COLOR] name[COLOR=#FF0000],[/COLOR] level [COLOR=#FF0000]=[/COLOR] player[COLOR=#FF0000]:[/COLOR]getDataString[COLOR=#FF0000]([/COLOR][COLOR=#800080][B]"name"[/B][/COLOR][COLOR=#FF0000])[/COLOR][COLOR=#FF0000],[/COLOR] player[COLOR=#FF0000]:[/COLOR]getDataInt[COLOR=#FF0000]([/COLOR][COLOR=#800080][B]"level"[/B][/COLOR][COLOR=#FF0000])[/COLOR]
            player[COLOR=#FF0000]:[/COLOR]free[COLOR=#FF0000]([/COLOR][COLOR=#FF0000])[/COLOR]
            doPlayerSendTextMessage[COLOR=#FF0000]([/COLOR]cid[COLOR=#FF0000],[/COLOR] MESSAGE_EVENT_ADVANCE[COLOR=#FF0000],[/COLOR] [COLOR=#800080][B]"You see a statue of "[/B][/COLOR] [COLOR=#FF0000].[/COLOR][COLOR=#FF0000].[/COLOR] name [COLOR=#FF0000].[/COLOR][COLOR=#FF0000].[/COLOR] [COLOR=#800080][B]" ("[/B][/COLOR] [COLOR=#FF0000].[/COLOR][COLOR=#FF0000].[/COLOR] level [COLOR=#FF0000].[/COLOR][COLOR=#FF0000].[/COLOR] [COLOR=#800080][B]").\nHighest level on the server."[/B][/COLOR][COLOR=#FF0000])[/COLOR]
            [COLOR=#0000FF][B]return[/B][/COLOR] [COLOR=#0000FF][B]false[/B][/COLOR]
        [COLOR=#0000FF][B]end[/B][/COLOR]
    [COLOR=#0000FF][B]end[/B][/COLOR]
    [COLOR=#0000FF][B]return[/B][/COLOR] [COLOR=#0000FF][B]true[/B][/COLOR]
[COLOR=#0000FF][B]end[/B][/COLOR]
[/FONT]
 
Last edited:
Back
Top