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

Solved [LUA] Highscore script (onThink)

Black Dove

Web-Developer
Joined
Apr 14, 2010
Messages
129
Reaction score
4
Location
Egypt
local function getHighestPlayer()
local result = db.getResult("SELECT `name` FROM `players` ORDER BY `level` DESC, `experience` DESC LIMIT 1")
return result.getDataString(result, "name")
function onThink(interval, lastExecution)
if getPlayerName(cid) == getHighestPlayer() then
doSendMagicEffect(getPlayerPosition(cid), 27)
doSendAnimatedText(getPlayerPosition(cid), "Top Score !!", TEXTCOLOR_RED)
end
return true
end
end

I Dunno What Is Wrong With This Highscore Script :/

Hope Anyone help me
 
Mmmmm So
I Should
Close It First Like That
local function getHighestPlayer()
local result = db.getResult("SELECT `name` FROM `players` ORDER BY `level` DESC, `experience` DESC LIMIT 1")
return result.getDataString(result, "name")
end

And Start From
function onThink(interval, lastExecution)
?
 
local function getHighestPlayer()
local result = db.getResult("SELECT `name` FROM `players` ORDER BY `level` DESC, `experience` DESC LIMIT 1")
return result.getDataString(result, "name")
end

function onThink(interval, lastExecution)
if getPlayerName(cid) == getHighestPlayer() then
doSendMagicEffect(getPlayerPosition(cid), 27)
doSendAnimatedText(getPlayerPosition(cid), "Top Score !!", TEXTCOLOR_RED)
end
return true
end

I Did That
And Got That ~~~

10256476_657021744378055_2394608877906770692_n.jpg

@dominique120
 
try:

local function getHighestPlayer()
local result = db.getResult("SELECT `name` FROM `players` ORDER BY `level` DESC, `experience` DESC LIMIT 1")
return result.getDataString(result, "name")
end

function onThink(interval, lastExecution)
for _, cid in pairs(getPlayersOnline()) do
if getPlayerName(cid) == getHighestPlayer() then
doSendMagicEffect(getPlayerPosition(cid), 27)
doSendAnimatedText(getPlayerPosition(cid), "Top Score !!", TEXTCOLOR_RED)
break
end
end
return true
end
 
Last edited:
Ops, i forgot the 'cid':
local function getHighestPlayer()
local result = db.getResult("SELECT `name` FROM `players` ORDER BY `level` DESC, `experience` DESC LIMIT 1")
return result.getDataString(result, "name")
end

function onThink(interval, lastExecution)
for _, cid in pairs(getPlayersOnline()) do
if getPlayerName(cid) == getHighestPlayer() then
doSendMagicEffect(getPlayerPosition(cid), 27)
doSendAnimatedText(getPlayerPosition(cid), "Top Score !!", TEXTCOLOR_RED)
break
end
end
return true
end
 
I would not recommend running the query n times (where n is amount of players online). Try this one instead, you could also use getCreatureByName depending on your server version.
Code:
local function getHighestPlayer()
  local result = db.getResult("SELECT `name` FROM `players` ORDER BY `level` DESC, `experience` DESC LIMIT 1")
  return result.getDataString(result, "name")
end

function onThink(interval, lastExecution)
  local highscoreName = getHighestPlayer()
  for _, cid in pairs(getPlayersOnline()) do
    if getPlayerName(cid) == highscoreName then
      local position = getPlayerPosition(cid)
      doSendMagicEffect(position, CONST_ME_GIFT_WRAPS)
      doSendAnimatedText(position, "Top Score !!", TEXTCOLOR_RED)
      break
    end
  end

  return true
end
 
Back
Top