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

onKill Monster loot change

desalib

New Member
Joined
Jul 4, 2010
Messages
30
Reaction score
0
So I've found some piece of code from Erikas Kontenis : http://otland.net/f82/special-bonus-loot-storage-155952/
That will let us add loot to body. Tested it work.
What I want is to add custom attributes to the items ( that include changing the base attack, base defence, base armor and description )

I tried by using this code

Code:
local monsters = {
["demon"] = {item = 2160, count = 2, chance = 70},
["rat"] = {item = 2396, count = 1, chance = 100}
}	
 
function onKill(cid, target, lastHit)
 
local v = getMonsterInfo(getCreatureName(target)).lookCorpse
local chance = math.random(1, 100)
	for k, a in pairs(monsters) do
		if (isMonster(target) and ((string.lower(getCreatureName(target))) == k)) then
			if a.chance >= chance then
				local function dropLoot(pos, v, cid)
					local corpse = getTileItemById(pos, v).uid
					local newStats = (math.random(10, 20))
					local item = doCreateItemEx(a.item)
					doItemSetAttribute(item, 'attack', newStats)
					doAddContainerItem(corpse, item)
				end			
				addEvent(dropLoot, 0, getThingPos(target), v,cid)
			end
		end
	end
return true
end

It's supposed to make rat drop an Ice Rapier that have between 10 and 20 base attack but with this code I don't receive any item... no error code at all.
 
Thanks it work for basic stats :) now i need to chance the description depending on the monster name : )

- - - Updated - - -

ingame, the rats name is "Rat", with an big "r".
this code is case-sensitive and therefor "rat" and "Rat" is not the same thing :)

In fact the string.lower function transform the "Rat" to "rat" to compare it so this is not a problem : )
 
Back
Top