• 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 Convert Revscripts

adrenyslopez

Member
Joined
Dec 22, 2015
Messages
201
Reaction score
15
Can someone do me a favor to pass this scripts to revscriptsys?

Lua:
<event type="statschange" name="onStatsChange_staminaTraining" event="script" value="onStatsChange_staminaTraining.lua"/>

Code:
local creatures = {}
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 cancels counting of timer. (2000 + (threshold of 1000) = need to hit blood every 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
    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}
        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
 
Back
Top