• 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!

RevScripts nil value

alcapone

Member
Joined
Jan 13, 2021
Messages
246
Reaction score
19
Lua:
local config = {
    chance = 100,
    tiers = {
 
        [{  1,  5000}] = { tier = {"Upgrade Stone!", true}, effect = {CONST_ME_TUTORIALARROW, true}, itemList = {
                {32641, 1, 1, 100}
      
            }
        }
 
    }
}


local lootstone = CreatureEvent("lootstone")
function lootstone.onKill(player, target, lastHit)
    if not target:isMonster() or target:getMaster() then
        return true
    end
    
    
       target:registerEvent('onDeath_lootstoneItemDrops')
    
    return true
end
 lootstone:register()
 
local onDeath_lootstoneItemDrop = CreatureEvent("onDeath_lootstoneItemDrops")
function onDeath_lootstoneItemDrop.onDeath(creature, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
 -- check if corpse item has available space to receive an additional item.
    if corpse:getEmptySlots() > 0 then
        -- check if an additional item will drop.
        if math.random(10000) > config.chance then
            return true
        end
        -- choose a tier.
        local rand = math.random(10000)
        for chance, index in pairs(config.tiers) do
            if chance[1] <= rand and chance[2] >= rand then
                -- create loot list.
                local rewardItems = {}
                for i = 1, #index.itemList do
                    if math.random(10000) <= index.itemList[i][4] then
                        rewardItems[#rewardItems + 1] = i
                    end
                end
                -- give a random item, if there are any to give.
                if rewardItems[1] then
                    rand = math.random(#rewardItems)
                    corpse:addItem(index.itemList[rand][1], math.random(index.itemList[rand][2], index.itemList[rand][3]))
                    if index.tier[2] == true then
                        creature:say(index.tier[1], TALKTYPE_MONSTER_SAY, false, nil, creature:getPosition())
                    end
                    if index.effect[2] == true then
                        local position = creature:getPosition()
                        for i = 1, 4 do
                            addEvent(function() position:sendMagicEffect(index.effect[1]) end, (i - 1) * 500)
                        end
                    end
                end
                return true
            end
        end
    end
    return true
end


onDeath_lootstoneItemDrop:register()


error :54: attempt to call method 'getEmptySlots' (a nil value)
 
🤷‍♂️

Tested it on 1.3 and couldn't find any issue with it.
View attachment bandicam 2021-08-28 13-24-19-296.mp4
Lua:
local config = {
    chance = 10000,
    tiers = {
 
        [{  1,  10000}] = { tier = {"Upgrade Stone!", true}, effect = {CONST_ME_TUTORIALARROW, true}, itemList = {
                {2494, 1, 1, 10000}
     
            }
        }
 
    }
}


local lootstone = CreatureEvent("lootstone")
function lootstone.onKill(player, target, lastHit)
    print("onKill")
    if not target:isMonster() or target:getMaster() then
        print("not registered")
        return true
    end
   
    print("registered")
       target:registerEvent('onDeath_lootstoneItemDrops')
   
    return true
end
 lootstone:register()
 
local onDeath_lootstoneItemDrop = CreatureEvent("onDeath_lootstoneItemDrops")
function onDeath_lootstoneItemDrop.onDeath(creature, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
    print("onDeath working")
 -- check if corpse item has available space to receive an additional item.
    if corpse:getEmptySlots() > 0 then
        print("space found")
        -- check if an additional item will drop.
        if math.random(10000) > config.chance then
            print("random failed")
            return true
        end
        -- choose a tier.
        local rand = math.random(10000)
        print("tier rand = " .. rand .. "")
        for chance, index in pairs(config.tiers) do
            if chance[1] <= rand and chance[2] >= rand then
                print("tier chosen")
                -- create loot list.
                local rewardItems = {}
                for i = 1, #index.itemList do
                    if math.random(10000) <= index.itemList[i][4] then
                        rewardItems[#rewardItems + 1] = i
                    end
                end
                -- give a random item, if there are any to give.
                if rewardItems[1] then
                    print("reward given")
                    rand = math.random(#rewardItems)
                    corpse:addItem(index.itemList[rand][1], math.random(index.itemList[rand][2], index.itemList[rand][3]))
                    if index.tier[2] == true then
                        creature:say(index.tier[1], TALKTYPE_MONSTER_SAY, false, nil, creature:getPosition())
                    end
                    if index.effect[2] == true then
                        local position = creature:getPosition()
                        for i = 1, 4 do
                            addEvent(function() position:sendMagicEffect(index.effect[1]) end, (i - 1) * 500)
                        end
                    end
                end
                return true
            end
        end
    end
    return true
end


onDeath_lootstoneItemDrop:register()


local loginEvent = CreatureEvent("onLogin_EventName")
loginEvent:type("login")

function loginEvent.onLogin(player)
    player:registerEvent("lootstone")
    return true
end

loginEvent:register()
 
🤷‍♂️

Tested it on 1.3 and couldn't find any issue with it.
View attachment 61618
Lua:
local config = {
    chance = 10000,
    tiers = {
 
        [{  1,  10000}] = { tier = {"Upgrade Stone!", true}, effect = {CONST_ME_TUTORIALARROW, true}, itemList = {
                {2494, 1, 1, 10000}
    
            }
        }
 
    }
}


local lootstone = CreatureEvent("lootstone")
function lootstone.onKill(player, target, lastHit)
    print("onKill")
    if not target:isMonster() or target:getMaster() then
        print("not registered")
        return true
    end
  
    print("registered")
       target:registerEvent('onDeath_lootstoneItemDrops')
  
    return true
end
 lootstone:register()
 
local onDeath_lootstoneItemDrop = CreatureEvent("onDeath_lootstoneItemDrops")
function onDeath_lootstoneItemDrop.onDeath(creature, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
    print("onDeath working")
 -- check if corpse item has available space to receive an additional item.
    if corpse:getEmptySlots() > 0 then
        print("space found")
        -- check if an additional item will drop.
        if math.random(10000) > config.chance then
            print("random failed")
            return true
        end
        -- choose a tier.
        local rand = math.random(10000)
        print("tier rand = " .. rand .. "")
        for chance, index in pairs(config.tiers) do
            if chance[1] <= rand and chance[2] >= rand then
                print("tier chosen")
                -- create loot list.
                local rewardItems = {}
                for i = 1, #index.itemList do
                    if math.random(10000) <= index.itemList[i][4] then
                        rewardItems[#rewardItems + 1] = i
                    end
                end
                -- give a random item, if there are any to give.
                if rewardItems[1] then
                    print("reward given")
                    rand = math.random(#rewardItems)
                    corpse:addItem(index.itemList[rand][1], math.random(index.itemList[rand][2], index.itemList[rand][3]))
                    if index.tier[2] == true then
                        creature:say(index.tier[1], TALKTYPE_MONSTER_SAY, false, nil, creature:getPosition())
                    end
                    if index.effect[2] == true then
                        local position = creature:getPosition()
                        for i = 1, 4 do
                            addEvent(function() position:sendMagicEffect(index.effect[1]) end, (i - 1) * 500)
                        end
                    end
                end
                return true
            end
        end
    end
    return true
end


onDeath_lootstoneItemDrop:register()


local loginEvent = CreatureEvent("onLogin_EventName")
loginEvent:type("login")

function loginEvent.onLogin(player)
    player:registerEvent("lootstone")
    return true
end

loginEvent:register()
I thought I had not registered in the login but it is .. yes the code is correct now the reason is giving the error I don't know. tested in 1.3 and as it has a large number on I tested it alone like you had no error something else is giving the error now is you know what.
 
I thought I had not registered in the login but it is .. yes the code is correct now the reason is giving the error I don't know. tested in 1.3 and as it has a large number on I tested it alone like you had no error something else is giving the error now is you know what.
I wonder if it's a monster with no corpse...?
Might have to add a check to confirm the corpse exists before attempting to use the function
 
I wonder if it's a monster with no corpse...?
Might have to add a check to confirm the corpse exists before attempting to use the function
can if that

Lua:
    if not creature then
        return true
    end
    if not creature:getType():getLoot() then
        return true


or

   if not corpse or not corpse:isContainer() then
        return
    end
    end

I thought of something like this but the error remains
 
Last edited:
Back
Top