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

[onKill] Adding loot to a corpse.

xNMExReject

Member
Joined
Oct 31, 2009
Messages
33
Reaction score
11
I added a few custom items that I want to make all monsters drop, considering the fact that I don't want to go through and add these items to every single monster I made an event script, however it doesn't work because it doesn't acknowledge that the corpse is a container, or perhaps it checks for the corpse too soon, either way I need some assistance:

Script:

Code:
function onKill(cid, target)

if(100 >= math.random(1, 100)) then
if(1 == math.random(1, 4)) then
 doAddContainerItem(corpse, 11389)
 return true
elseif(2 == math.random(1, 4)) then
 doAddContainerItem(corpse, 11390)
 return true
elseif(3 == math.random(1, 4)) then
 doAddContainerItem(corpse, 11391)
 return true
elseif(4 == math.random(1, 4)) then
 doAddContainerItem(corpse, 11392)
 return true
 
 end
 end
 return false
 end

Error:
Code:
[29/01/2010 21:40:43] [Error - CreatureScript Interface] 
[29/01/2010 21:40:43] data/creaturescripts/scripts/enchantdrop.lua:onKill
[29/01/2010 21:40:43] Description: 
[29/01/2010 21:40:44] (luaDoAddContainerItem) Container not found
 
I added a few custom items that I want to make all monsters drop, considering the fact that I don't want to go through and add these items to every single monster I made an event script, however it doesn't work because it doesn't acknowledge that the corpse is a container, or perhaps it checks for the corpse too soon, either way I need some assistance:

Script:

Code:
function onKill(cid, target)

if(100 >= math.random(1, 100)) then
if(1 == math.random(1, 4)) then
 doAddContainerItem(corpse, 11389)
 return true
elseif(2 == math.random(1, 4)) then
 doAddContainerItem(corpse, 11390)
 return true
elseif(3 == math.random(1, 4)) then
 doAddContainerItem(corpse, 11391)
 return true
elseif(4 == math.random(1, 4)) then
 doAddContainerItem(corpse, 11392)
 return true
 
 end
 end
 return false
 end

Error:
Code:
[29/01/2010 21:40:43] [Error - CreatureScript Interface] 
[29/01/2010 21:40:43] data/creaturescripts/scripts/enchantdrop.lua:onKill
[29/01/2010 21:40:43] Description: 
[29/01/2010 21:40:44] (luaDoAddContainerItem) Container not found

Corpse isn't declared in onKill, use onDeath..
 
Corpse isn't declared in onKill, use onDeath..

It got rid of the error, however it isn't doing what its supposed to be doing, I am not getting any errors so I am not sure what I did wrong:

Code:
function onDeath(cid, corpse, killer)

if isMonster(cid) == TRUE then 

if(100 >= math.random(1, 100)) then
if(1 == math.random(1, 4)) then
 doAddContainerItem(corpse.uid, 11389)
 return true
elseif(2 == math.random(1, 4)) then
 doAddContainerItem(corpse.uid, 11390)
 return true
elseif(3 == math.random(1, 4)) then
 doAddContainerItem(corpse.uid, 11391)
 return true
elseif(4 == math.random(1, 4)) then
 doAddContainerItem(corpse.uid, 11392)
 return true
 
 end
 end
 end
 return false
 end
 
onDeath isn't executed for monsters by default, you would have to add this into the monster's xml file;
HTML:
<script>
	<event name="EventName"/>
</script>
 
onDeath isn't executed for monsters by default, you would have to add this into the monster's xml file;
HTML:
<script>
	<event name="EventName"/>
</script>

That would probably make what I am trying to do useless then, I don't want to have to go into each monster's xml file and add data, I made the script to avoid that, is there any way around this?
 
Not that I know of, but you could make a hack in onKill, something like getting top item from the target's (victim's) position.
It probably wouldn't work well, but that's the best I can think of right now.
 
Could you give me an example? If worse comes to worse I'll probably just add the item to the players inventory when they kill the monster.
 
tested, working
Code:
local t = {
	[1] = 11389,
	[2] = 11390,
	[3] = 11391,
	[4] = 11392
}
local function event(pos)
	local corpse = getTileItemByType(pos, ITEM_TYPE_CONTAINER).uid
	if math.random(100) == 100 and corpse > 0 then
		local val = math.random(#t)
		doAddContainerItem(corpse, t[val])
	end
end
function onKill(cid, target, lastHit)
	addEvent(event, 0, getThingPos(target))
	return true
end
Had to use event because the script is executed before the corpse is created
 
My client crashes when I go to open the corpse, but other then that it looks like it should work.. :(

Edit:

Changing the item ID stops the crashes from occurring, it has something to do with my custom items.

Its not like they are anything special really, they use default rune sprites, and are usable/pickupable items that work like enchanted gems do.
 
Last edited:
Back
Top