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

GlobalEvent [0.4] Click Up event

Lurk

Active Member
Joined
Dec 4, 2017
Messages
336
Reaction score
48
Hello everyone, I love tibia and this community has given me a lot and I finally feel like I have something to give back, this code can be improved a lot (if you do improve it please comment here so we can all improve together). The idea behind this event is that I head the name Click up in a conversation, apparently it was a popular event in another server. I didn't see the original but I made what I thought would be the ideal thing, this event is a good break from hunting non stop and it also free the players to chat during its duration! (tho most people set a bot and go eat or something)

During this event (duration which you can choose) if a player clicks on a pre-determined crystal with a determined action, he'll gain a few levels each x seconds (an exhaust is necessary to prevent abuses from players using bots/auto clicks) and on my version, each 2 clicks will also give an item (event coin) but you can remove that completely or choose a new item. I'll be also providing the elfbot hotkey your players can use to automatically click.

on globalevents.xml add
XML:
<globalevent name="clickupstart" time="19:00" event="script" value="clickupstart.lua"/>
<globalevent name="clickupclose" time="19:15" event="script" value="clickupend.lua"/>

on globalevents/scripts, create a new file and name it clickupend.lua
Lua:
local storage = 64242 -- storage
function onTime()

    setGlobalStorageValue (storage, -1)
    doBroadcastMessage("THE CLICK UP EVENT HAS ENDED")
    return true

end

on globalevents/scripts, create a new file and name it clickupstart.lua
Lua:
local storage = 64242 -- storage que você quer zerar.
function onTime()

    setGlobalStorageValue (storage, 1)
    doBroadcastMessage("THE CLICK UP EVENT HAS STARTED")
    return true

end

now on actions.xml add this tag
XML:
<action actionid="42113" script="clickup.lua"/>

and on actions/scripts create a new file and name it clickup.lua and put this inside
Lua:
local tempo = 2 -- exhaust to click again and get levels

function onUse(cid, item, frompos, item2, topos)
if getGlobalStorageValue(64242) == 1 then

if getPlayerStorageValue(cid, 45890) > os.time() or getPlayerLevel(cid) >= 717217 then -- if the player is on cooldown or has already reached max level
        return doPlayerSendCancel(cid, "You must wait "..(getPlayerStorageValue(cid, 45890) - os.time()).. " seconds to use again or you have already reached maximum level.")
end

if getPlayerStorageValue(cid, 45891) < 1 then
doPlayerAddLevel(cid, 32)
doCreatureSay(cid, "LEVEL UP", TALKTYPE_ORANGE_1, true, cid)
setPlayerStorageValue(cid, 45890, 2 + os.time())
local bah = getPlayerStorageValue(cid, 45891)
doPlayerSetStorageValue(cid, 45891, bah+1)
return true
else
doPlayerAddLevel(cid, 32)
doCreatureSay(cid, "LEVEL UP + EVENT COIN", TALKTYPE_ORANGE_1, true, cid)
doPlayerAddItem(cid,10558,1) -- if you don't want players to get items you can remove this line, or change the item id to a new one
setPlayerStorageValue(cid, 45890, 2 + os.time())
doPlayerSetStorageValue(cid, 45891, -1)
return true
end

else -- msg when the event isn't happening
    return doPlayerSendCancel(cid, "The event haven't started yet.")
end
end

now you need to open your world.otbm and create an area for the event, be sure to add the action 42113 to the item your players have to click to gain levels, I recommend some imovable crystal/statue/stone (I'm using 9779)

elfbot hotkey IF you're using the crystal with the same id as me (9779)
Code:
auto 200 listas 'Evento' | usegrounditem 8865
 
Hello everyone, I love tibia and this community has given me a lot and I finally feel like I have something to give back, this code can be improved a lot (if you do improve it please comment here so we can all improve together). The idea behind this event is that I head the name Click up in a conversation, apparently it was a popular event in another server. I didn't see the original but I made what I thought would be the ideal thing, this event is a good break from hunting non stop and it also free the players to chat during its duration! (tho most people set a bot and go eat or something)

During this event (duration which you can choose) if a player clicks on a pre-determined crystal with a determined action, he'll gain a few levels each x seconds (an exhaust is necessary to prevent abuses from players using bots/auto clicks) and on my version, each 2 clicks will also give an item (event coin) but you can remove that completely or choose a new item. I'll be also providing the elfbot hotkey your players can use to automatically click.

on globalevents.xml add
XML:
<globalevent name="clickupstart" time="19:00" event="script" value="clickupstart.lua"/>
<globalevent name="clickupclose" time="19:15" event="script" value="clickupend.lua"/>

on globalevents/scripts, create a new file and name it clickupend.lua
Lua:
local storage = 64242 -- storage
function onTime()

    setGlobalStorageValue (storage, -1)
    doBroadcastMessage("THE CLICK UP EVENT HAS ENDED")
    return true

end

on globalevents/scripts, create a new file and name it clickupstart.lua
Lua:
local storage = 64242 -- storage que você quer zerar.
function onTime()

    setGlobalStorageValue (storage, 1)
    doBroadcastMessage("THE CLICK UP EVENT HAS STARTED")
    return true

end

now on actions.xml add this tag
XML:
<action actionid="42113" script="clickup.lua"/>

and on actions/scripts create a new file and name it clickup.lua and put this inside
Lua:
local tempo = 2 -- exhaust to click again and get levels

function onUse(cid, item, frompos, item2, topos)
if getGlobalStorageValue(64242) == 1 then

if getPlayerStorageValue(cid, 45890) > os.time() or getPlayerLevel(cid) >= 717217 then -- if the player is on cooldown or has already reached max level
        return doPlayerSendCancel(cid, "You must wait "..(getPlayerStorageValue(cid, 45890) - os.time()).. " seconds to use again or you have already reached maximum level.")
end

if getPlayerStorageValue(cid, 45891) < 1 then
doPlayerAddLevel(cid, 32)
doCreatureSay(cid, "LEVEL UP", TALKTYPE_ORANGE_1, true, cid)
setPlayerStorageValue(cid, 45890, 2 + os.time())
local bah = getPlayerStorageValue(cid, 45891)
doPlayerSetStorageValue(cid, 45891, bah+1)
return true
else
doPlayerAddLevel(cid, 32)
doCreatureSay(cid, "LEVEL UP + EVENT COIN", TALKTYPE_ORANGE_1, true, cid)
doPlayerAddItem(cid,10558,1) -- if you don't want players to get items you can remove this line, or change the item id to a new one
setPlayerStorageValue(cid, 45890, 2 + os.time())
doPlayerSetStorageValue(cid, 45891, -1)
return true
end

else -- msg when the event isn't happening
    return doPlayerSendCancel(cid, "The event haven't started yet.")
end
end

now you need to open your world.otbm and create an area for the event, be sure to add the action 42113 to the item your players have to click to gain levels, I recommend some imovable crystal/statue/stone (I'm using 9779)

elfbot hotkey IF you're using the crystal with the same id as me (9779)
Code:
auto 200 listas 'Evento' | usegrounditem 8865
Untested, but here's your action script without requiring the storage values.
Lua:
local players = {}
local tempo = 2 -- exhaust to click again and get levels
local level_gain = 32
local event_coin = {10558, 1} -- itemid, amount

function onUse(cid, item, frompos, item2, topos)
    if getGlobalStorageValue(64242) ~= 1 then
        doPlayerSendCancel(cid, "The event haven't started yet.")
        return true
    end
   
    local cur_time = os.time()
    if players[cid] and players[cid][1] > cur_time or getPlayerLevel(cid) >= 717217 then -- if the player is on cooldown or has already reached max level
        doPlayerSendCancel(cid, "You must wait " .. (players[cid][1] - cur_time) .. " seconds to use again or you have already reached maximum level.")
        return true
    end
   
    local text = "LEVEL UP"
    if players[cid] and players[cid][2] == 2 then
        text = text .. " + EVENT COIN"
        doPlayerAddItem(cid, event_coin[1], event_coin[2])
    end
   
    doPlayerAddLevel(cid, level_gain)
    doCreatureSay(cid, text, TALKTYPE_ORANGE_1, true, cid)
    players[cid] = {cur_time + tempo, players[cid] and players[cid][2] == 1 and 2 or 1}
    return true
end
 
Just tested your version, it works perfectly! I didn't know of cur_time or players[cid] so it's nice to learn new stuff
Thank you
 
Just tested your version, it works perfectly! I didn't know of cur_time or players[cid] so it's nice to learn new stuff
Thank you
local cur_time = os.time() -- Since it's being used multiple times in the script, we put it into a local to save resources.

local players = {} -- at the top of the script is to hold the player data.

players[cid] = {time, 1 or 2} -- (bottom of script) we use this to update the table.

Since everyone has a different creatureid, we use 'cid' as the index in the table.

So this is what the table looks like, after 3 people use the item.

Lua:
local players = {
  --[cid] = {time+delay, 1 or 2} -- 1 = level reward | 2 = level reward + item reward
    [7483547534] = {981723897293, 2},
    [9832749327] = {981723897283, 2},
    [9874982374] = {981723897265, 1},
}
 
Yeah I think I expressed myself wrong, I didn't knew you could use variables like this, I'm still a newbie so that was eye opening, I can simplify stuff better in the future
but thank you for the explanation, I can see things clearer now. You might not remember but you also helped me on a script like 1 year ago, you're very helpful 😊

cid can change if the player relog right? guid wouldn't be better? dunno I had a crash happening a few years ago because of a pointer wrongly pointing to a player that was no longer online

edit: oh well I guess the same would be true for cid so just ignore what I said lmao
 
Yeah I think I expressed myself wrong, I didn't knew you could use variables like this, I'm still a newbie so that was eye opening, I can simplify stuff better in the future
but thank you for the explanation, I can see things clearer now. You might not remember but you also helped me on a script like 1 year ago, you're very helpful 😊

cid can change if the player relog right? guid wouldn't be better? dunno I had a crash happening a few years ago because of a pointer wrongly pointing to a player that was no longer online

edit: oh well I guess the same would be true for cid so just ignore what I said lmao
Since we aren't using addEvents, the use of cid in the table is fine.
even using addEvents, you just check to confirm if the player exists before attempting to use functions containing cid if isPlayer(cid) then

Even in the unlikely event that a player used the action script, and 2 billion monsters died, and a different player logged in, and re-used the creatureid and then used the action script.. they would only have a 50% chance of getting an event_coin 2 seconds early. xD

That's the only caveat of using a creatureid, where if the server never goes offline, the server will eventually 'loop' it's numbers back to the beginning and start re-using creatureids.

But most servers have a daily restart, so there's a basically 0% chance of that happening.
 
Back
Top