• 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 Problem with storage and party

FilipeJF

New Member
Joined
Jan 9, 2012
Messages
124
Reaction score
4
Looks like there's a bug in this script where you have to kill 10 trolls. But theres a bug in the storages there.

Let me explain.

I was with the storage value in "18". My friend was with it in 19 (where you are supposed to start killing the trolls). I needed to talk with an NPC to receive value 19, but as my friend killed a Troll in front of me, my storage value leveled to 19, and I lost the chance to talk with the NPC. Is there a way to make the kill count ONLY for those who have value 19 even if they're in a party?

Lua:
function onDeath(cid, corpse, killer)

local monstName = "Troll"
local Storage = 102501
local valor1 = 19    
local valor2 = 28

    if isMonster(cid) and string.lower(getCreatureName(cid)) == string.lower(monstName) and getPlayerStorageValue(killer[1], Storage) >= valor1 and getPlayerStorageValue(killer[1], Storage) <= valor2 then
        doPlayerSendTextMessage(killer[1], 22, "Your questlog has been updated.")
        if isInParty(killer[1]) == TRUE then
            local players = getPartyMembers(getPartyLeader(killer[1]))
            for i, k in ipairs(players) do
                setPlayerStorageValue(k, Storage, (getPlayerStorageValue(k, Storage)+1))
            end
        else
            setPlayerStorageValue(killer[1], Storage, (getPlayerStorageValue(killer[1], Storage)+1))
        end
    end
    return true
end
 
Try to change:
Lua:
            for i, k in ipairs(players) do
                setPlayerStorageValue(k, Storage, (getPlayerStorageValue(k, Storage)+1))
            end

To:
Lua:
            for i, k in ipairs(players) do
                if getPlayerStorageValue(k, Storage) >= valor1 and getPlayerStorageValue(k, Storage) <= valor2 then
                    setPlayerStorageValue(k, Storage, (getPlayerStorageValue(k, Storage)+1))
                end
            end


Lua:
local monstName = "Troll"
local Storage = 102501
local valor1 = 19   
local valor2 = 28

-- our small function to check the storage range
local function isInValidStorageValueRange(player, storageValue)
    if (getPlayerStorageValue(player, storageValue) >= valor1 and getPlayerStorageValue(player, storageValue) <= valor2) then
        return true
    end
return false
end

function onDeath(cid, corpse, killer)
    if isMonster(cid) and string.lower(getCreatureName(cid)) == string.lower(monstName) and isInValidStorageValueRange(killer[1], Storage) then
        doPlayerSendTextMessage(killer[1], 22, "Your questlog has been updated.")
        if isInParty(killer[1]) == TRUE then
            local players = getPartyMembers(getPartyLeader(killer[1]))
            for i, k in ipairs(players) do
                if isInValidStorageValueRange(k, Storage) then
                    setPlayerStorageValue(k, Storage, (getPlayerStorageValue(k, Storage)+1))
                end
            end
        else
            setPlayerStorageValue(killer[1], Storage, (getPlayerStorageValue(killer[1], Storage)+1))
        end
    end
    return true
end
 
Last edited:
Try to change:
Lua:
            for i, k in ipairs(players) do
                setPlayerStorageValue(k, Storage, (getPlayerStorageValue(k, Storage)+1))
            end

To:
Lua:
            for i, k in ipairs(players) do
                if getPlayerStorageValue(k, Storage) >= valor1 and getPlayerStorageValue(k, Storage) <= valor2 then
                    setPlayerStorageValue(k, Storage, (getPlayerStorageValue(k, Storage)+1))
                end
            end


Lua:
local monstName = "Troll"
local Storage = 102501
local valor1 = 19  
local valor2 = 28

-- our small function to check the storage range
local function isInValidStorageValueRange(player, storageValue)
    if (getPlayerStorageValue(player, storageValue) >= valor1 and getPlayerStorageValue(player, storageValue) <= valor2) then
        return true
    end
return false
end

function onDeath(cid, corpse, killer)
    if isMonster(cid) and string.lower(getCreatureName(cid)) == string.lower(monstName) and isInValidStorageValueRange(killer[1], Storage) then
        doPlayerSendTextMessage(killer[1], 22, "Your questlog has been updated.")
        if isInParty(killer[1]) == TRUE then
            local players = getPartyMembers(getPartyLeader(killer[1]))
            for i, k in ipairs(players) do
                if isInValidStorageValueRange(k, Storage) then
                    setPlayerStorageValue(k, Storage, (getPlayerStorageValue(k, Storage)+1))
                end
            end
        else
            setPlayerStorageValue(killer[1], Storage, (getPlayerStorageValue(killer[1], Storage)+1))
        end
    end
    return true
end

Hey! Thank you so much, it works like a charm. Thanks! Script is perfect now!!
 
Try to change:
Lua:
            for i, k in ipairs(players) do
                setPlayerStorageValue(k, Storage, (getPlayerStorageValue(k, Storage)+1))
            end

To:
Lua:
            for i, k in ipairs(players) do
                if getPlayerStorageValue(k, Storage) >= valor1 and getPlayerStorageValue(k, Storage) <= valor2 then
                    setPlayerStorageValue(k, Storage, (getPlayerStorageValue(k, Storage)+1))
                end
            end


Lua:
local monstName = "Troll"
local Storage = 102501
local valor1 = 19  
local valor2 = 28

-- our small function to check the storage range
local function isInValidStorageValueRange(player, storageValue)
    if (getPlayerStorageValue(player, storageValue) >= valor1 and getPlayerStorageValue(player, storageValue) <= valor2) then
        return true
    end
return false
end

function onDeath(cid, corpse, killer)
    if isMonster(cid) and string.lower(getCreatureName(cid)) == string.lower(monstName) and isInValidStorageValueRange(killer[1], Storage) then
        doPlayerSendTextMessage(killer[1], 22, "Your questlog has been updated.")
        if isInParty(killer[1]) == TRUE then
            local players = getPartyMembers(getPartyLeader(killer[1]))
            for i, k in ipairs(players) do
                if isInValidStorageValueRange(k, Storage) then
                    setPlayerStorageValue(k, Storage, (getPlayerStorageValue(k, Storage)+1))
                end
            end
        else
            setPlayerStorageValue(killer[1], Storage, (getPlayerStorageValue(killer[1], Storage)+1))
        end
    end
    return true
end

Is there a way to make it not not to work when a player is too far distant of his party companion?
 
Back
Top