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

CreatureEvent Lua+SQL - Monster Loot System

Azi

Banned User
Joined
Aug 12, 2007
Messages
1,167
Reaction score
53
Location
Włocławek
Hello all! : )
I made this Lua+SQL code because it is much easier in the editing of C++ when someone don't know c++ (like me). Easy system - easy addons. : ) Everybody who know base of Lua can make addons to this system (like loot effect's, items special options). Furthermore you can loot now runes, potions etc. :)
And items drop rate is set in percent like (50% chance for drop item)
Script made by creaturescripts (Lua) and ots database (new table, SQL).

for the proper operation of the script should be clear Loot from monsters (in the XML scripts)

in data/creaturescripts/scripts/login.lua add:
under:
PHP:
 function onLogin(cid)
add:
PHP:
 registerCreatureEvent(cid, "MonsterLoot")
now in data/creaturescripts/creaturescripts.xml
under:
PHP:
<creaturescripts>
add:
PHP:
<event type="kill" name="MonsterLoot" script="lootsystem.lua"/>
and last code which you must add is in:
data/creaturescripts/scripts make lootsystem.lua
and paste this code:
PHP:
function getLoot(monstername)
local loocik = {}
local loot = db.getResult("SELECT * FROM `monsters_loot` WHERE `monster_name`='" .. monstername .. "';")
	if loot:getID() ~= -1 then
		while(true) do
		table.insert(loocik, {loot:getDataInt("item_id"), loot:getDataInt("item_count"), loot:getDataInt("drop_percent"), loot:getDataInt("in_container")})
			if not(loot:next())then
				break
			end
		end
		loot:free()
	else
		print("No loot in database for: "..monstername.."!")
	end
	return loocik
end
function addLoot(x)
pos = x["pos"]
	for i=0,255 do
	pos.stackpos = 255-i
	gpos = getThingfromPos(pos)
		if isCorpse(gpos.uid) == 1 then
		corp = 255-i
		end
	end
pos.stackpos = corp
corpse = getThingfromPos(pos)
local container = 0
	for i=1,#x.loot do
		if x.loot[i][3] >= math.random(1,100) then
			if x.loot[i][4] == 0 or container == nil then
				local la = doAddContainerItem(corpse.uid, x.loot[i][1], math.random(1, x.loot[i][2]))
				if isContainer(la) then 
				container = la 
				end
			elseif x.loot[i][4] == 1 and container ~= nil then
				doAddContainerItem(container, x.loot[i][1], math.random(1, x.loot[i][2]))
			end
		end
	end
end
 
function onKill(cid, target)
	if isMonster(target) then
	local pos = getCreaturePosition(target)
	local monsterloot = getLoot(getCreatureName(target))
	x = {
	["pos"] = pos,
	["loot"] = monsterloot
	}
	addEvent(addLoot, 1, x)
	end
	return TRUE
end

now only import it in phpmyadmin to ots database:
RapidShare: Easy Filehosting <-- its database of items loot.

and replace your old monster with this without loot set in xml (base 0.3b2 monsters without loot)
RapidShare: Easy Filehosting


and it's all! ; )

azi.
 
Hello, script nice. Work great. I don't know why u make this system, system loot already done in c++ - this same ofc...

EDIT
@DOWN:
Say me what is new ?
 
Last edited:
#elf efl fle fel lef lfe ;D
most easy addding new functions to loot, like upgraded items from monsters, items with special description/name etc. :D
 
Back
Top