• 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 Special bonus loot with storage

Erikas Kontenis

Board Moderator
Staff member
Board Moderator
Joined
Jul 3, 2009
Messages
1,863
Reaction score
563
Location
Lithuania
*This script will add to monster container special item named in config and works only if a player have special storage to obdain that item.

for 0.3.6~ and 0.4.~ use this code

creaturescripts.xml

Code:
<event type="kill" name="bubu" event="script" value="bubu.lua"/>

register it to login.lua

Code:
registerCreatureEvent(cid, "bubu")

create lua file named bubu.lua

Lua:
local monsters = {
["demon"] = {item = 2160, count = 2, chance = 70},
["rat"] = {item = 2160, count = 2, chance = 80}
}	
 
function onKill(cid, target, lastHit)

local storage = 7474
local v = getMonsterInfo(getCreatureName(target)).lookCorpse
local chance = math.random(1, 100)
if getPlayerStorageValue(cid, storage) == 1 then
	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
					doAddContainerItem(corpse, a.item, math.random(1, a.count))
				end			
				addEvent(dropLoot, 0, getThingPos(target), v,cid)
			end
		end
	end
end
return true
end

for 0.2.~ users this code

creaturescripts.xml

Code:
<event type="death" name="bubu" script="bubu.lua"/>

create lua file named bubu.lua

Lua:
local monsters = {
["demon"] = {item = 2160, cant = 2, chance = 70},
["rat"] = {item = 2160, cant = 2, chance = 100}
}
 
local storage = 7474
 
function onDeath(cid, corpse)
local chance = math.random(1, 100)
if getPlayerStorageValue(getPlayerByName(getPlayerName(getCreatureTarget(cid))), storage) == 1 then
	for k, v in pairs(monsters) do
		if (isMonster(cid) and ((string.lower(getCreatureName(cid))) == k)) then
			if v.chance >= chance then
				doAddContainerItem(corpse.uid, v.item, math.random(1, v.cant))
			end
		end
	end
end
return true
end

Also for everyMonster you write in config register event example:

monsters/rat.xml

before <loot> add

Code:
<script>
<event name="bubu"/>
</script>

final edit will look like this

Code:
<?xml version="1.0" encoding="UTF-8"?>
<monster name="rat" nameDescription="a rat" race="blood" experience="5" speed="140" manacost="200">
  <health now="20" max="20"/>
  <look type="21" head="20" body="30" legs="40" feet="50" corpse="5964"/>
  <targetchange interval="2000" chance="0"/>
  <strategy attack="100" defense="0"/>
  <flags>
    <flag summonable="1"/>
    <flag attackable="1"/>
    <flag hostile="1"/>
    <flag illusionable="1"/>
    <flag convinceable="1"/>
    <flag pushable="1"/>
    <flag canpushitems="0"/>
    <flag canpushcreatures="0"/>
    <flag targetdistance="1"/>
    <flag staticattack="90"/>
    <flag runonhealth="5"/>
  </flags>
  <attacks>
    <attack name="melee" interval="2000" skill="8" attack="9"/>
  </attacks>
  <defenses armor="7" defense="5"/>
  <immunities/>
   <script>
	<event name="bubu"/>
    </script>
  <loot>
    <item id="3976" countmax="6" chance1="50000" chancemax="0"/>
    <item id="2148" countmax="7" chance1="80000" chancemax="0"/>
    <item id="2696" chance="20000"/>
  </loot>
</monster>

Feel free to ask questions or report bugs.

Thank for this thread creator to fire my spirit http://otland.net/f132/bring-head-script-based-world-warcraft-155781/#post1501665 and also for dantarrix
 
Just what I'm looking for but getCreatureTarget(cid) keeps returning 0 :/, I also tried using killer and getCreatureName(killer) still returns 0 any ideas?
Using latest 0.2

Code:
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/killitem.lua:onDeath
luaGetPlayerStorageValue(). Player not found
stack traceback:
        [C]: in function 'getPlayerStorageValue'
        data/creaturescripts/scripts/killitem.lua:9: in function <data/creaturescripts/scripts/killitem.lua:7>
 
Last edited:
Just what I'm looking for but getCreatureTarget(cid) keeps returning 0 :/, I also tried using killer and getCreatureName(killer) still returns 0 any ideas?
Using latest 0.2

Code:
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/killitem.lua:onDeath
luaGetPlayerStorageValue(). Player not found
stack traceback:
        [C]: in function 'getPlayerStorageValue'
        data/creaturescripts/scripts/killitem.lua:9: in function <data/creaturescripts/scripts/killitem.lua:7>

In 0.2 you must be with normal character, becouse creatures dont see gods, this means script checking player by creature target list so if player is in creature target list then he will be ok. Try with not god/gm character and say me if for you was ok.

btw, if still not try replace your scripts again, maybe you self did mistake by adding something.
 
its not working to me in tfs 0.2 i did at and it says Warning: [Monster::Monster]. Unknown event name - demodras
 
its not working to me in tfs 0.2 i did at and it says Warning: [Monster::Monster]. Unknown event name - demodras

monster <event name="demodras"/> must be same as in creaturescripts.xml

<event type="death" name="demodras" script="bubu.lua"/>
 
Very cool code. The only thing it doesn't do is add the item to the loot list, bu I can't think of a way to manage that.

Repped!
Red
 
[12/03/2013 05:13:43] Lua Script Error: [CreatureScript Interface]
[12/03/2013 05:13:43] data/creaturescripts/scripts/bubu.lua:eek:nDeath
[12/03/2013 05:13:43] LuaScriptInterface::luaGetPlayerStorageValue(). Player not found
[12/03/2013 05:13:43] stack traceback:
[12/03/2013 05:13:43] [C]: in function 'getPlayerStorageValue'
[12/03/2013 05:13:43] data/creaturescripts/scripts/bubu.lua:10: in function <data/creaturescripts/scripts/bubu.lua:8>

TFS 0.2 Mystic Spirit 9.6

I cannot figure it out.
 
Yea I used the bottem one. And I am on a normal character.

- - - Updated - - -

Its this line specificly that is not working with the distro:
if getPlayerStorageValue(getPlayerByName(getPlayerName(getCreatureTarget(cid))), storage) == -1 then

- - - Updated - - -

Edit: I made my own version of this script. It works a bit differently but in the end has the same outcome.
 
Is there any chance go get it work on TFS 1.2 or is there a similar system for it?
 
Back
Top