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

Lua Top level effect tfs 1.x

danalex07

New Member
Joined
Aug 29, 2010
Messages
14
Reaction score
2
hi, need some help here cuz i'm too amateur in scripting.....im trying to convert to tfs 1.x the top level effect posted here:
http://www.tibiaking.com/forum/topic/49367-toplevel-effect/

and this is what i have so far..

Code:
local config = {
   tempo = 5, --time in secs
   mensagem = {
      texto = "[TOP]",
      efeito = TEXTCOLOR_LIGHTBLUE --efect doSendAnimatedText
   },
   efeito = 30, --efect doSendMagicEffect
   globalstr = 150202 -- global storage
}
function TopEffect(player)
   local var = tostring(Game.getStorageValue(config.globalstr)):gsub(':', ''):explode(',')
   if not isCreature(player) or player:getName() ~= var[1] then return LUA_ERROR end
   --doSendAnimatedText(getCreaturePosition(cid), config.mensagem.texto, config.mensagem.efeito)
   player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_RED)
   addEvent(TopEffect, config.tempo*1000, player)
end
function onLogin(player)
   if tonumber(Game.getStorageValue(config.globalstr)) then -- virgin
      local query = db.storeQuery("SELECT `name`, `level` FROM `players` WHERE `group_id` < 2 ORDER BY `level` DESC LIMIT 1")
      if (query:getID() ~= -1) then
         Game.setStorageValue(config.globalstr, ":"..query:getDataString("name")..",:"..query:getDataInt("level"))
         TopEffect(player)
      end
   else
      TopEffect(player)
   end
   registerCreatureEvent(player, "CheckTop")
   return true
end
function onAdvance(player, skill, oldLevel, newLevel)
   if skill ~= SKILL__LEVEL then return true end
   local var = tostring(Game.getStorageValue(config.globalstr)):gsub(':', ''):explode(',')
   if newLevel > tonumber(var[2]) then
      Game.broadcastMessage("The Player " .. player:getName() .. " its the new Top Level. Grats!", 22)
      Game.setStorageValue(config.globalstr, ":"..player:getName()..",:"..newLevel)
      TopEffect(player)
   end        
   return true
end

and as you can imagine i doesnt work.....can you help me??

also i know in tfs 1.x there is no function --doSendAnimatedText but any idea how to make it work? and any chance to change the name of the top level to [TOP]xxxxx???
 
I don't like this script at all, but in TFS 1.x you can't use text in storages (at least on player storage, I'm not sure about global storage tho)

Can you show us the error?
 
I don't like this script at all, but in TFS 1.x you can't use text in storages (at least on player storage, I'm not sure about global storage tho)

Can you show us the error?

You can use strings and integers for a global storage value - https://github.com/otland/forgottenserver/blob/master/data/lib/core/game.lua#L58-L68
But IMO it's bad practice since a player stroage can only be in integers (might be changed dunno).

Topic:
Depending on interval you can use Creature:say(), do as no one does - use the serach function.
 
there is no error in console.....
hmmm if the player storage con only be integers then i can use data from de db like order players per level then get the top level?
 
there is no error in console.....
hmmm if the player storage con only be integers then i can use data from de db like order players per level then get the top level?

Yes you can, haven't checked the script since it's so messy..
But depending on how you fetch the player there should not be any problems, try to print out the name or something like that.
If you get nil, then there either are no players in the database or you aren't loading them correctly.
 
im tying this code..more simple but cant manage to make it work....dunno if its wrong writed (im begginner in scripting things), becuse i tryied to translate it from tfs 0.x to tfs 1.x

Code:
    local tiempo = 10

    function onLogin(player)
       query = db.storeQuery("SELECT `name`, `level` FROM `players` WHERE `group_id` == 1 ORDER BY `level` DESC LIMIT 1")
       if (query:getID() ~= -1) then
          name = query:getDataString("name")
          if player:getName(player) == name then
             TopEffect(player)
          end
       end
       return true
    end

    function TopEffect(player)
       if isPlayer(player) then
          player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_RED)
          addEvent(TopEffect, tiempo*1000, player)
       end
       return true
    end

also, any ideas about de [TOP] tag addition to the player name in game?

ps: i run this code and shows no error in console
 
Code:
local function getHighestPlayer()
    local resultId = db.storeQuery("SELECT `name` FROM `players` ORDER BY `level` DESC, `experience` DESC LIMIT 1")
    if not resultId then
        return false
    end

    result.free(resultId)
    return result.getDataString(resultId, "name")
end

local config = {
    interval = 5,
    effect = CONST_ME_FIREWORK_RED
}

local function sendEffectTopPlayer(cid)
    local player = Player(cid)
    if not player then
        return true
    end

    player:getPosition():sendMagicEffect(config.effect)
    addEvent(sendEffectTopPlayer, config.interval * 1000, cid)
    return true
end

function onLogin(player)
    if player:getName() ~= getHighestPlayer() then
        return true
    end

    sendEffectTopPlayer(player:getId())
    return true
end
 
It doesn't works for me, I'm using as creature script, is that right?
change
Code:
local function getHighestPlayer()
    local resultId = db.storeQuery("SELECT `name` FROM `players` ORDER BY `level` DESC, `experience` DESC LIMIT 1")
    if not resultId then
        return false
    end

    result.free(resultId)
    return result.getDataString(resultId, "name")
end

to
Code:
local function getHighestPlayer()
    local resultId = db.storeQuery("SELECT `name` FROM `players` ORDER BY `level` DESC, `experience` DESC LIMIT 1")
    if not resultId then
        return false
    end

    return result.getDataString(resultId, "name")
end
in the script
 
Back
Top