• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Regeneration mana if we have X storage

vexler222

Active Member
Joined
Apr 22, 2012
Messages
714
Solutions
15
Reaction score
47
Hi, i make amulet, she give me mana per second if i have X storage, and it work 100% but if player dont have amulet in necle slot but he have storage, i got many errors like null value, cuz he dont have X amulet in slot

Code:
function onThink(cid, interval)

local time = 1
local player = Player(cid)
if last_interval == nil then last_interval = os.clock() end

if player:getStorageValue(12346) == 1 and player:getSlotItem(CONST_SLOT_NECKLACE).itemid == 12683 then
    local mp = player:getMaxMana() * (1.0 / 100)
    if (os.clock() - last_interval) > time then
        if player:getMana() < player:getMaxMana() then
            if mp >= 1 then
                player:addMana(mp)
            end
        end
            last_interval = os.clock()
        end
    end
    return true
end
Post automatically merged:

Nvm i fix it
 
Last edited:
For future forum users, the answer to this issue is to confirm that an item actually exists in the slot, before attempting to compare it to something.

something like this.. should work
LUA:
local necklaceId = 12683
local storageRequired = 12346
local time = 1
local last_interval = nil

function onThink(cid, interval)
    local player = Player(cid)
    if last_interval == nil then
        last_interval = os.clock()
    end
    
    if player:getStorageValue(storageRequired) ~= 1 then
        return true
    end
    
    local necklace = player:getSlotItem(CONST_SLOT_NECKLACE)
    if not necklace then
        return true
    end
    
    if necklace:getId() ~= necklaceId then
        return true
    end
    
    local mp = player:getMaxMana() * (1.0 / 100)
    if (os.clock() - last_interval) > time then
        if player:getMana() < player:getMaxMana() then
            if mp >= 1 then
                player:addMana(mp)
            end
        end
        last_interval = os.clock()
    end
    return true
end
 
For future forum users, the answer to this issue is to confirm that an item actually exists in the slot, before attempting to compare it to something.

something like this.. should work
LUA:
local necklaceId = 12683
local storageRequired = 12346
local time = 1
local last_interval = nil

function onThink(cid, interval)
    local player = Player(cid)
    if last_interval == nil then
        last_interval = os.clock()
    end
   
    if player:getStorageValue(storageRequired) ~= 1 then
        return true
    end
   
    local necklace = player:getSlotItem(CONST_SLOT_NECKLACE)
    if not necklace then
        return true
    end
   
    if necklace:getId() ~= necklaceId then
        return true
    end
   
    local mp = player:getMaxMana() * (1.0 / 100)
    if (os.clock() - last_interval) > time then
        if player:getMana() < player:getMaxMana() then
            if mp >= 1 then
                player:addMana(mp)
            end
        end
        last_interval = os.clock()
    end
    return true
end


i fixed it like that:


Code:
function onThink(cid, interval)

local time = 3
local player = Player(cid)
local position = player:getPosition()

local item = player:getSlotItem(CONST_SLOT_NECKLACE)
        if not item then
            return false
        end
if last_interval == nil then last_interval = os.clock() end
if player:getStorageValue(12346) == 1 and item.itemid == 12683 then
    local mp = 200
    if (os.clock() - last_interval) > time then
        if player:getMana() < player:getMaxMana() then
            if mp >= 1 then
                player:addMana(mp)
                position:sendMagicEffect(1)
            end
        end
        if player:getHealth() < player:getMaxHealth() then
            if mp >= 1 then
                player:addHealth(mp)
                position:sendMagicEffect(1)
            end
        end
            last_interval = os.clock()
        end
    end
    return true
end
 
Back
Top