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

MoveEvent Refill Stamina on PZ for premiums

kito2

www.masteria.net
Joined
Mar 9, 2009
Messages
3,766
Solutions
1
Reaction score
225
Location
Chile, Santiago
Add this to /data/global.lua at the end of the file.
Lua:
function addStamina(id, amountStamina, delay)
    local event = staminaRegen[id]

    local player = Player(id)
    if not player then
        stopEvent(event)
        staminaRegen[id] = nil
        return false
    end

    local actualStamina = player:getStamina()

    if actualStamina > 2400 and actualStamina < 2520 then
        delay = 12 * 60 * 1000 -- Stamina verde 12 mins
    elseif actualStamina == 2520 then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "You are no longer refilling stamina, because your stamina is already full.")
        stopEvent(event)
        staminaRegen[id] = nil
        return false
    end   
   
    player:editStamina(actualStamina + 1)
    player:sendTextMessage(MESSAGE_STATUS_SMALL, "One minute of stamina has been refilled.")

    stopEvent(event)
    staminaRegen[id] = addEvent(addStamina, delay, id, amountStamina, delay)
    return true
end

Go to /data/events/player.lua and find function "Player:eek:nChangeZone(zone)", and replace it with this code:
Lua:
function Player:onChangeZone(zone)
    if not self:isPremium() then
        return false
    end

    local event = staminaRegen[self:getId()]

    if zone == ZONE_PROTECTION then
        if self:getStamina() < 2520 then
            if not event then
                local delay = 2
                if self:getStamina() > 2400 and self:getStamina() <= 2520 then
                    delay = 8
                end

                staminaRegen[self:getId()] = addEvent(addStamina, delay * 60 * 1000, self:getId(), 1, delay * 60 * 1000)   
            end
        end
    else
        if event then
            self:sendTextMessage(MESSAGE_STATUS_SMALL, "You are no longer refilling stamina, since you left a regeneration zone.")
            stopEvent(event)
            staminaRegen[self:getId()] = nil
        end
    end
end

That's all.
 
There is no event called onChangeZone on TFS git so I dont think this is going to work.
 
There's a function for internal source use but not a method for lua usage, so that you have to create a method on events.cpp and call it everytime the function you are pointing is being called.
 
There is a function in sources that can be integrated then, just search for it.
 
There is a function in sources that can be integrated then, just search for it.
you are providing code without support or base either so I think is bad. Maybe post the full working code.
 
I searched at TFS distro the function change zone, saw it and posted. I will update maybe next week for people who doesnt know how to use search function.
 
Instead of posting just shit and criticisms, u could help. Thats why this community sucks cause everyone here has the same attitude as u.
 
Hi, this is a custom thing or have it in tibia global?
and how many stamine this will regen per second?
 
Every 2 mins refill stamina point, and if green stamina will regen every 8 minutes.

This is custom. RL has a system related to Reward Wall Shrine and a bonus there refill stamina on PZ for premium only.
 
Try to edit the post with the event that vankk created and this system is going to work flawless :)
 
I did a small patch to this script work. Not tested/compiled tho. Please few free to fork and fix if has any issue.

Gist link
.

Hi, can you help me? I get some errors:

Code:
[ 27%] Building CXX object CMakeFiles/tfs.dir/src/game.cpp.o
In file included from /home/Otserv/src/events.cpp:22:0:
/home/Otserv/src/events.h:54:48: error: ‘ZoneType_t’ has not been declared
   void eventPlayerOnChangeZone(Player* player, ZoneType_t zone);
                                                ^
[ 29%] Building CXX object CMakeFiles/tfs.dir/src/globalevent.cpp.o
/home/Otserv/src/events.cpp:542:6: error: prototype for ‘void Events::eventPlayerOnChangeZone(Player*, ZoneType_t)’ does not match any in class ‘Events’
void Events::eventPlayerOnChangeZone(Player* player, ZoneType_t zone)
      ^
In file included from /home/Otserv/src/events.cpp:22:0:
/home/Otserv/src/events.h:54:8: error: candidate is: void Events::eventPlayerOnChangeZone(Player*, int)
   void eventPlayerOnChangeZone(Player* player, ZoneType_t zone);
        ^
make[2]: *** [CMakeFiles/tfs.dir/src/events.cpp.o] Error 1
 
It should be there too?
events.cpp
ceGpYuJ.png


@president vankk
 
someone can help? Error:

Lua:
Lua Script Error: [Event Interface]
data/events/scripts/player.lua:Player@onChangeZone
data/events/scripts/player.lua:221: attempt to index global 'staminaRegen' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/events/scripts/player.lua:221: in function <data/events/scripts/player.lua:216>
 
Back
Top