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

CreatureEvent Stamina Training Monk [0.4 / 0.3.7]

Xikini

I whore myself out for likes
Senator
Premium User
Joined
Nov 17, 2010
Messages
6,796
Solutions
581
Reaction score
5,360
If you attack a specific creature for x amount of seconds, gain stamina y.

If you attack a training monk for 180 seconds, gain 1 minute stamina.

Requested by someone here.

Posting in resources so it's easier to find by anyone who needs it.

Not sure if it works in 0.3.6 because I don't think they have os.mtime()

----------------------------

register to the creature only, not login.lua

data/monsters/training_monk.xml [under immunities]
XML:
<script>
    <event name="onStatsChange_staminaTraining"/>
</script>
data/creaturescripts/creaturescripts.xml
XML:
<event type="statschange" name="onStatsChange_staminaTraining" event="script" value="onStatsChange_staminaTraining.lua"/>
data/creaturescripts/scripts/onStatsChange_staminaTraining.lua
Lua:
local creatures = {} -- holds creature data
local config = {
    timer = 180, -- time in seconds, before you gain stamina while hitting monster_name
    monster_name = "training monk",
    stamina_gain = 1, -- amount to gain after time elapse.
    threshold = 1000 -- how tight a timer before script resets counting of timer.
                     -- (2000 + (threshold of 1000) = need to hit blood within 3 seconds)
}


function onStatsChange(cid, attacker, type, combat, value)
    if type ~= STATSCHANGE_HEALTHLOSS then
        return true
    end

    if not isPlayer(attacker) then
        return true
    end
    -- these next two checks are redundant if only registered for a single monster, but there's no real harm in keeping them
    if not isMonster(cid) then
        return true
    end
    if getCreatureName(cid):lower() ~= config.monster_name:lower() then
        return true
    end

    local current_time = os.mtime()
    if not creatures[cid] then
        creatures[cid] = {current_time, current_time} -- {start_time, last_hit_time}
        return true
    end

    -- check if too much time has elasped between last blood hit
    local time_difference = current_time - creatures[cid][2] -- between last hit and current time
    if time_difference > 2000 + config.threshold then
        creatures[cid] = {current_time, current_time} -- reset timers
        return true
    end
    creatures[cid][2] = current_time

    -- check if stamina timer has elasped
    time_difference = current_time - creatures[cid][1] -- time between first attack and current time.
    if time_difference < 1000 * config.timer then
        return true
    end

    -- give stamina and adjust timers for future stamina gain (2520 is max stamina)
    creatures[cid][1] = creatures[cid][1] + (1000 * config.timer)


    local stamina_to_add = getPlayerStamina(attacker) + config.stamina_gain
    if stamina_to_add >= 2520 then
        stamina_to_add = 2520 - getPlayerStamina(attacker)
    end
    if stamina_to_add <= 0 then -- stamina is already full
        return true
    end
    
    doPlayerSetStamina(attacker, stamina_to_add)
    doPlayerAddExperience(attacker, 1) -- neccesary to update client with new stamina information.
    addEvent(doPlayerAddExperience, 0, attacker, -1)
    return true
end
 
you could take the timer out and just grant like 2 seconds of stamina per attack instead?
 
you could take the timer out and just grant like 2 seconds of stamina per attack instead?
minimum we can give is '1', which is 1 minute, but yes, we can do it on every blood hit.
Lua:
local config = {
    monster_name = "training monk",
    stamina_gain = 1 -- amount to gain each blood hit.
}

function onStatsChange(cid, attacker, type, combat, value)
    if type ~= STATSCHANGE_HEALTHLOSS then
        return true
    end

    if not isPlayer(attacker) then
        return true
    end
    -- these next two checks are redundant if only registered for a single monster, but there's no real harm in keeping them
    if not isMonster(cid) then
        return true
    end
    if getCreatureName(cid):lower() ~= config.monster_name:lower() then
        return true
    end

    local stamina_to_add = getPlayerStamina(attacker) + config.stamina_gain
    if stamina_to_add >= 2520 then
        stamina_to_add = 2520 - getPlayerStamina(attacker)
    end
    if stamina_to_add <= 0 then -- stamina is already full
        return true
    end
   
    doPlayerSetStamina(attacker, stamina_to_add)
    doPlayerAddExperience(attacker, 1) -- neccesary to update client with new stamina information.
    addEvent(doPlayerAddExperience, 0, attacker, -1)
    return true
end
 
Sick stuff, 1 minute per blood might be a lot, but you might want a faster regen too. Stamina sucks. Nice stuff.
 
If you attack a specific creature for x amount of seconds, gain stamina y.

If you attack a training monk for 180 seconds, gain 1 minute stamina.

Requested by someone here.

Posting in resources so it's easier to find by anyone who needs it.

Not sure if it works in 0.3.6 because I don't think they have os.mtime()

----------------------------

register to the creature only, not login.lua

data/monsters/training_monk.xml [under immunities]
XML:
<script>
    <event name="onStatsChange_staminaTraining"/>
</script>
data/creaturescripts/creaturescripts.xml
XML:
<event type="statschange" name="onStatsChange_staminaTraining" event="script" value="onStatsChange_staminaTraining.lua"/>
data/creaturescripts/scripts/onStatsChange_staminaTraining.lua
Lua:
local creatures = {} -- holds creature data
local config = {
    timer = 180, -- time in seconds, before you gain stamina while hitting monster_name
    monster_name = "training monk",
    stamina_gain = 1, -- amount to gain after time elapse.
    threshold = 1000 -- how tight a timer before script resets counting of timer.
                     -- (2000 + (threshold of 1000) = need to hit blood within 3 seconds)
}


function onStatsChange(cid, attacker, type, combat, value)
    if type ~= STATSCHANGE_HEALTHLOSS then
        return true
    end

    if not isPlayer(attacker) then
        return true
    end
    -- these next two checks are redundant if only registered for a single monster, but there's no real harm in keeping them
    if not isMonster(cid) then
        return true
    end
    if getCreatureName(cid):lower() ~= config.monster_name:lower() then
        return true
    end

    local current_time = os.mtime()
    if not creatures[cid] then
        creatures[cid] = {current_time, current_time} -- {start_time, last_hit_time}
        return true
    end

    -- check if too much time has elasped between last blood hit
    local time_difference = current_time - creatures[cid][2] -- between last hit and current time
    if time_difference > 2000 + config.threshold then
        creatures[cid] = {current_time, current_time} -- reset timers
        return true
    end
    creatures[cid][2] = current_time

    -- check if stamina timer has elasped
    time_difference = current_time - creatures[cid][1] -- time between first attack and current time.
    if time_difference < 1000 * config.timer then
        return true
    end

    -- give stamina and adjust timers for future stamina gain (2520 is max stamina)
    creatures[cid][1] = creatures[cid][1] + (1000 * config.timer)


    local stamina_to_add = getPlayerStamina(attacker) + config.stamina_gain
    if stamina_to_add >= 2520 then
        stamina_to_add = 2520 - getPlayerStamina(attacker)
    end
    if stamina_to_add <= 0 then -- stamina is already full
        return true
    end
   
    doPlayerSetStamina(attacker, stamina_to_add)
    doPlayerAddExperience(attacker, 1) -- neccesary to update client with new stamina information.
    addEvent(doPlayerAddExperience, 0, attacker, -1)
    return true
end
green stamina regenerates as quickly as orange stamina?
 
what can i do to work on 0.3.6 ? )':
If you attack a specific creature for x amount of seconds, gain stamina y.

If you attack a training monk for 180 seconds, gain 1 minute stamina.

Requested by someone here.

Posting in resources so it's easier to find by anyone who needs it.

Not sure if it works in 0.3.6 because I don't think they have os.mtime()

----------------------------

register to the creature only, not login.lua

data/monsters/training_monk.xml [under immunities]
XML:
<script>
    <event name="onStatsChange_staminaTraining"/>
</script>
data/creaturescripts/creaturescripts.xml
XML:
<event type="statschange" name="onStatsChange_staminaTraining" event="script" value="onStatsChange_staminaTraining.lua"/>
data/creaturescripts/scripts/onStatsChange_staminaTraining.lua
Lua:
local creatures = {} -- holds creature data
local config = {
    timer = 180, -- time in seconds, before you gain stamina while hitting monster_name
    monster_name = "training monk",
    stamina_gain = 1, -- amount to gain after time elapse.
    threshold = 1000 -- how tight a timer before script resets counting of timer.
                     -- (2000 + (threshold of 1000) = need to hit blood within 3 seconds)
}


function onStatsChange(cid, attacker, type, combat, value)
    if type ~= STATSCHANGE_HEALTHLOSS then
        return true
    end

    if not isPlayer(attacker) then
        return true
    end
    -- these next two checks are redundant if only registered for a single monster, but there's no real harm in keeping them
    if not isMonster(cid) then
        return true
    end
    if getCreatureName(cid):lower() ~= config.monster_name:lower() then
        return true
    end

    local current_time = os.mtime()
    if not creatures[cid] then
        creatures[cid] = {current_time, current_time} -- {start_time, last_hit_time}
        return true
    end

    -- check if too much time has elasped between last blood hit
    local time_difference = current_time - creatures[cid][2] -- between last hit and current time
    if time_difference > 2000 + config.threshold then
        creatures[cid] = {current_time, current_time} -- reset timers
        return true
    end
    creatures[cid][2] = current_time

    -- check if stamina timer has elasped
    time_difference = current_time - creatures[cid][1] -- time between first attack and current time.
    if time_difference < 1000 * config.timer then
        return true
    end

    -- give stamina and adjust timers for future stamina gain (2520 is max stamina)
    creatures[cid][1] = creatures[cid][1] + (1000 * config.timer)


    local stamina_to_add = getPlayerStamina(attacker) + config.stamina_gain
    if stamina_to_add >= 2520 then
        stamina_to_add = 2520 - getPlayerStamina(attacker)
    end
    if stamina_to_add <= 0 then -- stamina is already full
        return true
    end
 
    doPlayerSetStamina(attacker, stamina_to_add)
    doPlayerAddExperience(attacker, 1) -- neccesary to update client with new stamina information.
    addEvent(doPlayerAddExperience, 0, attacker, -1)
    return true
end
 
Does it work with 10.98 tfx 1.4.2?

Also is it possible to make this to a rev script?
 
Back
Top