• 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 How to add Exhaust Here? 2 min

myalitth

New Member
Joined
Jan 13, 2013
Messages
69
Reaction score
3
function onUse(player, item, position, fromPosition, toPosition)
local position = player:getPosition()
local chance = math.random(1, 30)
if chance <= 28 then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You ransack the pile but fail to find any useful parts.")
item:transform(11253)
item:decay()
Game.createMonster("Guzzlemaw", position)
elseif chance == 29 then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Amidst the pile of various bones you find a large, hollow part, similar to a pipe.")
player:addItem(22389, 1)
item:transform(11253)
item:decay()
elseif chance == 30 then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have found a mouthpiece for a horn.")
player:addItem(22391, 1)
item:transform(11253)
item:decay()
end
return true
end
 
NOT TESTED:
Lua:
function onUse(player, item, position, fromPosition, toPosition)
local storage = 55666
local exhoustedTime = player:getStorageValue(storage)-os.time()
local position = player:getPosition()
local chance = math.random(1, 30)
    if player:getStorageValue(storage) > os.time() then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "You have to wait "..exhoustedTime.." seconds until you can use this again.")
        return true
    end
    if chance <= 28 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You ransack the pile but fail to find any useful parts.")
        item:transform(11253)
        item:decay()
        Game.createMonster("Guzzlemaw", position)
    elseif chance == 29 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Amidst the pile of various bones you find a large, hollow part, similar to a pipe.")
        player:addItem(22389, 1)
        item:transform(11253)
        item:decay()
    elseif chance == 30 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have found a mouthpiece for a horn.")
        player:addItem(22391, 1)
        item:transform(11253)
        item:decay()
    end
        player:setStorageValue(storage, os.time() + 2 * 60)
    return true
end
 
function onUse(player, item, position, fromPosition, toPosition)
local position = player:getPosition()
local chance = math.random(1, 30)
if chance <= 28 then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You ransack the pile but fail to find any useful parts.")
item:transform(11253)
item:decay()
Game.createMonster("Guzzlemaw", position)
elseif chance == 29 then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Amidst the pile of various bones you find a large, hollow part, similar to a pipe.")
player:addItem(22389, 1)
item:transform(11253)
item:decay()
elseif chance == 30 then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have found a mouthpiece for a horn.")
player:addItem(22391, 1)
item:transform(11253)
item:decay()
end
return true
end

Please read the rules; Rules for the Support board
#7

How to display CODE properly in your post


NOT TESTED:
Lua:
function onUse(player, item, position, fromPosition, toPosition)
local storage = 55666
local exhoustedTime = player:getStorageValue(storage)-os.time()
local position = player:getPosition()
local chance = math.random(1, 30)
    if player:getStorageValue(storage) > os.time() then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "You have to wait "..exhoustedTime.." seconds until you can use this again.")
        return true
    end
    if chance <= 28 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You ransack the pile but fail to find any useful parts.")
        item:transform(11253)
        item:decay()
        Game.createMonster("Guzzlemaw", position)
    elseif chance == 29 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Amidst the pile of various bones you find a large, hollow part, similar to a pipe.")
        player:addItem(22389, 1)
        item:transform(11253)
        item:decay()
    elseif chance == 30 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have found a mouthpiece for a horn.")
        player:addItem(22391, 1)
        item:transform(11253)
        item:decay()
    end
        player:setStorageValue(storage, os.time() + 2 * 60)
    return true
end

Looks okay, but try to make the codes cleaner, atleast the edits you do.
And if you add another if statment make sure that you actually need the variables insted of just adding it in there, that way if if statment returns the function we havn't wasted time on loading extra things.
Lua:
function onUse(player, item, position, fromPosition, toPosition)
    local storage = 55666
    local exhoustedTime = player:getStorageValue(storage) - os.time()
    if player:getStorageValue(storage) > os.time() then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "You have to wait " .. exhoustedTime .. " seconds until you can use this again.")
        return true
    end

    local chance = math.random(1, 30)
    if chance <= 28 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You ransack the pile but fail to find any useful parts.")
        item:transform(11253)
        item:decay()
        Game.createMonster("Guzzlemaw", player:getPosition())
    elseif chance == 29 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Amidst the pile of various bones you find a large, hollow part, similar to a pipe.")
        player:addItem(22389, 1)
        item:transform(11253)
        item:decay()
    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have found a mouthpiece for a horn.")
        player:addItem(22391, 1)
        item:transform(11253)
        item:decay()
    end

    player:setStorageValue(storage, os.time() + 2 * 60)

    return true
end
 
Please read the rules; Rules for the Support board
#7

How to display CODE properly in your post




Looks okay, but try to make the codes cleaner, atleast the edits you do.
And if you add another if statment make sure that you actually need the variables insted of just adding it in there, that way if if statment returns the function we havn't wasted time on loading extra things.
Lua:
function onUse(player, item, position, fromPosition, toPosition)
    local storage = 55666
    local exhoustedTime = player:getStorageValue(storage) - os.time()
    if player:getStorageValue(storage) > os.time() then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "You have to wait " .. exhoustedTime .. " seconds until you can use this again.")
        return true
    end

    local chance = math.random(1, 30)
    if chance <= 28 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You ransack the pile but fail to find any useful parts.")
        item:transform(11253)
        item:decay()
        Game.createMonster("Guzzlemaw", player:getPosition())
    elseif chance == 29 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Amidst the pile of various bones you find a large, hollow part, similar to a pipe.")
        player:addItem(22389, 1)
        item:transform(11253)
        item:decay()
    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have found a mouthpiece for a horn.")
        player:addItem(22391, 1)
        item:transform(11253)
        item:decay()
    end

    player:setStorageValue(storage, os.time() + 2 * 60)

    return true
end

Problem is that you shouldnt be able to use the same item again, but you have more around with the same ID that should be triggering different timers.
 
Back
Top