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

leituni

New Member
Joined
Jun 12, 2010
Messages
14
Reaction score
0
Hi people. I'm trying to run a script onDeath, but it is not running properly. Could anyone help, please?

When I run this, it works fine: (verifies complete loot of monster)
LUA:
function onSay(cid, words, param, channel)
         str = "Loot:\n"
         local lootList = getMonsterLootList(param)
         for i, _ in pairs(lootList) do
		     str = str .. getItemNameById(lootList[i].id) .. " (ID: " .. lootList[i].id .. ")\n"
         end
       	 doPlayerPopupFYI(cid, str)
end

When I run this, the for i, ..... doen't work...
LUA:
function onDeath(cid, corpse)
    doCreatureSay(cid, "hi", 1)
    local lootList = getMonsterLootList(getCreatureName(cid))
    for i, _ in pairs(lootList) do
        if lootList[i].count > 1 then
            local numb = math.random(1, lootList[i].count)
            doCreateItem(lootList[i].id, numb, corpse.pos)
            doCreatureSay(cid, getItemNameById(lootList[i].id), 1)
        else
            if math.random(1,100000) <= lootList[i].chance then
                doCreateItem(lootList[i].id, 1, corpse.pos)
                doCreatureSay(cid, getItemNameById(lootList[i].id), 1)
            end
        end
    end
    return TRUE
end

Note: The monster say hi when die, but don't say any ID.

Thanks!

Edit: How can I put the itens inside corpse??
 
Last edited:
Code:
[31/08/2011 04:21:08] [Error - CreatureScript Interface] 
[31/08/2011 04:21:08] data/creaturescripts/scripts/pokedeath.lua:onDeath
[31/08/2011 04:21:08] Description: 
[31/08/2011 04:21:08] (luaDoAddContainerItem) Container not found

Any other idea? :p

Anything about for i, _ in pairs........?
 
if you use 0.3.6pl1 i think is should be:

LUA:
getMonsterLootList(cid)

getMonsterLootList() is used with name, not creature... When i use my first code, that i posted, it works fine, but in second code it doesn't work... it just don't start the for loop.
 
With a little help of you, I finally got it to work!!

Thanks!!

LUA:
function onDeath(cid, corpse)
    local lootList = getMonsterLootList(getCreatureName(cid) .. " s")
    for i, _ in pairs(lootList) do
        if lootList[i].count > 1 then
            local numb = math.random(1, lootList[i].count)
            doAddContainerItem(corpse.uid, lootList[i].id, numb)
        else
            if math.random(1,100000) <= lootList[i].chance then
                doAddContainerItem(corpse.uid, lootList[i].id, 1)
            end
        end
    end
    return TRUE
end

the " s" in name is because the creature's name of file is diferent of the name in game. =]
 
Back
Top