- Joined
- Nov 17, 2010
- Messages
- 6,832
- Solutions
- 586
- Reaction score
- 5,414
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
----------------------------
register to the creature only, not login.lua
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