• 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 Add storage time onUse script 1.2

gubbo123

New Member
Joined
Aug 15, 2017
Messages
151
Solutions
1
Reaction score
3
Lua:
function onUse(player, item, fromPosition, target, toPosition)
    if math.random(1, 100) <= 1 and math.random(1, 100) <= 10 then
        item:transform(2975, 0)
        item:decay()
    else
        item:getPosition():sendMagicEffect(22)
    end
    return true
end

how can i add a storage 1001,5 onUse and start a regressive count after 5 seconds change the storage to 1001,4?
 
Solution
Lua:
local function resetStorage(cid)
    local player = Player(cid)
    if not player then
        return
    end
    player:setStorageValue(1001, 4) -- reset storage back to 4 if player is online
end

function onUse(player, item, fromPosition, target, toPosition)
    if math.random(1, 100) <= 1 and math.random(1, 100) <= 10 then
        item:transform(2975, 0)
        item:decay()
        player:setStorageValue(1001, 5) -- set new storage value
        addEvent(resetStorage, 5000, player:getId()) -- after 5 seconds, execute this
    else
        item:getPosition():sendMagicEffect(22)
    end
    return true
end

You'll also have to register an onDeath event to set storage value to 4 as well, in case the player dies when it...
Lua:
local function resetStorage(cid)
    local player = Player(cid)
    if not player then
        return
    end
    player:setStorageValue(1001, 4) -- reset storage back to 4 if player is online
end

function onUse(player, item, fromPosition, target, toPosition)
    if math.random(1, 100) <= 1 and math.random(1, 100) <= 10 then
        item:transform(2975, 0)
        item:decay()
        player:setStorageValue(1001, 5) -- set new storage value
        addEvent(resetStorage, 5000, player:getId()) -- after 5 seconds, execute this
    else
        item:getPosition():sendMagicEffect(22)
    end
    return true
end

You'll also have to register an onDeath event to set storage value to 4 as well, in case the player dies when it tries to reset.
Lua:
function onDeath(creature)
    if creature:getStorageValue(1001) == 5 then
        creature:setStorageValue(1001, 4)
    end
    return true
end

creaturescripts.xml:
XML:
<event type="death" name="your death event name" script="reset storage.lua"/>

login.lua:
Lua:
player:registerEvent("your death event name")
 
Solution
Back
Top