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

Lua quests

Hrsha

Member
Joined
May 30, 2010
Messages
450
Reaction score
21
Location
Egypt
hi otlanders

i wana make boss monster spawns after 6 hours from its death
and if it still alive it does not spawn other one

Code:
function onThink(interval)
 
local start = {x = 1033, y = 882, z = 5} -- the start of the area
local endd = {x = 1037, y = 886, z = 5} -- the end of the area
local monsterpos = {x = 1035, y = 884, z = 5} -- the monster spawn point
 
	for x = start.x, endd.x do
		for y = start.y, endd.y do
			if getTopCreature({x=x, y=y, z=start.z}).type == 2 then
				return true
			end
		end
	end	
 
	local m = math.random(1,3)
 
	if m == 1 then
		doSummonCreature("Frost Dragon", monsterpos) -- change to your bosses
	elseif m == 2 then
		doSummonCreature("Ghastly Dragon", monsterpos) -- change to your bosses
	elseif m == 3 then
		doSummonCreature("Dragon Lord", monsterpos) -- change to your bosses
	end
	return true
end
-- sizaro(at)otland.net

i have tried this script but it does not what i want it spawns automatic
and does not care about if monster still alive or not so its area full of that boss lol

2- also i wana make when that x boss in x area die creat magic force immediately
which will teleport u to x position and gonna disappear in 3 minutes

sorry for my bad english , gonna rep +
 
LUA:
local t = {
	['bauss'] = {
		fromPos = {x,y,z}, --top left corner of the boss area
		toPos = {x,y,z}, --bottm right corner of the boss area
		tpPos = {x,y,z}, --where will the teleport be created aftert the boss dies? 
		tpToPos = {x,y,z},  --where will the teleport take you to?
		teleportTime = 3, -- how much minutes the teleport is going to be aviable
		respPos = {x,y,z}, --where to create the monster
		respTime = 6 --respawning time in hours.
	},
	['superman'] = {
		fromPos = {x,y,z},
		toPos = {x,y,z},
		tpPos = {x,y,z},
		tpToPos = {x,y,z},
		teleportTime = 10,
		respPos = {x,y,z},
		respTime = 3
	}
}
function onDeath(cid, corpse, deathList)
local k = t[getCreatureName(cid):lower()]
	if isMonster(cid) then
		if k then
			if isInRange(cid, k.fromPos, k.toPos) then
				doCreateTeleport(1387, k.tpToPos, k.tpPos)
				addEvent(doRemoveItem, ((k.teleportTime*1000)*60), getTileItemById(1387, k.tpPos).uid, 1)
				addEvent(doCreateMonster, (((k.teleportTime*1000)*60)*60), getCreatureName(cid), k.respPos)
			end
		end
	end
return true
end

Register it in login.lua
 
Last edited:
i added this

Code:
local t = {
	['morgaroth'] = {
		fromPos = {1132,865,14}, --top left corner of the boss area
		toPos = {1155,889,14}, --bottm right corner of the boss area
		tpPos = {1152,874,14}, --where will the teleport be created aftert the boss dies? 
		tpToPos = {1167,862,14}, --where will the teleport take you to?
		teleportTime = 1, -- how much minutes the teleport is going to be aviable
		respPos = {1142,876,14}, --where to create the monster
		respTime = 6 --respawning time in hours.
	},
	['superman'] = {
		fromPos = {x,y,z},
		toPos = {x,y,z},
		tpPos = {x,y,z},
		tpToPos = {x,y,z},
		teleportTime = 10,
		respPos = {x,y,z},
		respTime = 3
	}
}
function onDeath(cid, corpse, deathList)
local k = t[getCreatureName(cid):lower()]
	if isMonster(cid) then
		if k then
			if isInRange(cid, k.fromPos, k.toPos) then
				doCreateTeleport(1387, k.tpToPos, k.tpPos)
				addEvent(doRemoveItem, ((k.teleportTime*1000)*60), getTileItemById(1387, k.tpPos).uid, 1)
				addEvent(doCreateMonster, (((k.teleportTime*1000)*60)), getCreatureName(cid), k.respPos)
			end
		end
	end
return true
end

Code:
<event type="Death" name="bossdeath" event="script" value="bossdeath.lua"/>

but its not working there is no monster and when i summon it and kill the magic force does not appear
nothing happen :S
 
LUA:
local t = {
	['morgaroth'] = {
		fromPos = {x = 1132 , y = 865 , z = 14 }, --top left corner of the boss area
		toPos = {x = 1155 , y = 889 , z = 14 }, --bottm right corner of the boss area
		tpPos = {x = 1152, y = 874 , z =14 }, --where will the teleport be created aftert the boss dies? 
		tpToPos = {x = 1167, y = 862 , z =14 }, --where will the teleport take you to?
		teleportTime = 1, -- how much minutes the teleport is going to be aviable
		respPos = {x = 1142 , y = 876 , z = 14 }, --where to create the monster
		respTime = 6 --respawning time in hours.
	}
}
function onKill(cid, target, lastHitKiller)
local k = t[getCreatureName(target):lower()]
	if isMonster(target) then
		if k then
			if isInRange(getCreaturePosition(target), k.fromPos, k.toPos) then
				doCreateTeleport(1387, k.tpToPos, k.tpPos)
				addEvent(doRemoveItem, ((k.teleportTime*1000)*60), getTileItemById(k.tpPos, 1387).uid, 1)
				addEvent(doCreateMonster, (((k.teleportTime*1000)*60)), getCreatureName(target), k.respPos)
			end
		end
	end
return true
end
Also, register it in login.lua
 
Last edited:
becouse it is onDeath you must register it in monster.xml

example open morgaroth.xml in monsters.

before <loot> add

Code:
<script>
<event name="bossdeath"/>
</script>
Final example would 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="bossdeath"/>
    </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>


Register it in login.lua

You not must to register it in login.lua becouse it not works for player it is for monster death.
 
becouse it is onDeath you must register it in monster.xml

example open morgaroth.xml in monsters.

before <loot> add

Code:
<script>
<event name="bossdeath"/>
</script>
Final example would 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>




You not must to register it in login.lua becouse it not works for player it is for monster death.

Ah, that's what I got confused about.
OP, if you don't want to register it in monsters.xml, I edited the script, it's onKill now. http://otland.net/f132/lua-quests-156039/#post1502694
 
when i use bogart edited script something did not see it before happen lol
monster die but not really dead lol no deadbody and the monster still exist with no hp hmmm cant explain xD

and this error comes on console

Code:
[13:57:09.921] [Error - CreatureScript Interface]
[13:57:09.921] data/creaturescripts/scripts/bossdeath.lua:onKill
[13:57:09.921] Description:
[13:57:09.921] data/lib/032-position.lua:2: attempt to index local 'position' (a
 number value)
[13:57:09.921] stack traceback:
[13:57:09.921]  data/lib/032-position.lua:2: in function 'isInRange'
[13:57:09.921]  data/creaturescripts/scripts/bossdeath.lua:16: in function <data
/creaturescripts/scripts/bossdeath.lua:12>

when i use ondeath script and edit morgaroth nothing happens not tp shows
and this error comes on console

Code:
[13:59:49.328] [Error - CreatureScript Interface]
[13:59:49.328] data/creaturescripts/scripts/bossdeath.lua:onDeath
[13:59:49.328] Description:
[13:59:49.328] (luaGetCreatureName) Creature not found

[13:59:49.328] [Error - CreatureScript Interface]
[13:59:49.328] data/creaturescripts/scripts/bossdeath.lua:onDeath
[13:59:49.328] Description:
[13:59:49.328] data/creaturescripts/scripts/bossdeath.lua:13: attempt to index a
 boolean value
[13:59:49.328] stack traceback:
[13:59:49.328]  data/creaturescripts/scripts/bossdeath.lua:13: in function <data
/creaturescripts/scripts/bossdeath.lua:12>

and both of them does not creat the morgaroth when server up
i tested them by summon one
 
the same error :S

[14:16:12.968] [Error - CreatureScript Interface]
[14:16:12.968] data/creaturescripts/scripts/bossdeath.lua:onKill
[14:16:12.968] Description:
[14:16:12.968] data/lib/032-position.lua:2: attempt to index local 'position' (a
number value)
[14:16:12.968] stack traceback:
[14:16:12.968] data/lib/032-position.lua:2: in function 'isInRange'
[14:16:12.968] data/creaturescripts/scripts/bossdeath.lua:16: in function <data
/creaturescripts/scripts/bossdeath.lua:12>
 
LUA:
local t = {
	['morgaroth'] = {
		fromPos = {x = 1132 , y = 865 , z = 14 }, --top left corner of the boss area
		toPos = {x = 1155 , y = 889 , z = 14 }, --bottm right corner of the boss area
		tpPos = {x = 1152, y = 874 , z =14 }, --where will the teleport be created aftert the boss dies? 
		tpToPos = {x = 1167, y = 862 , z =14 }, --where will the teleport take you to?
		teleportTime = 1, -- how much minutes the teleport is going to be aviable
		respPos = {x = 1142 , y = 876 , z = 14 }, --where to create the monster
		respTime = 6 --respawning time in hours.
	}
}
function onKill(cid, target, lastHitKiller)
local k = t[getCreatureName(target):lower()]
	if isMonster(target) then
		if k then
			if isInRange(getCreaturePosition(target), k.fromPos, k.toPos) then
				doCreateTeleport(1387, k.tpToPos, k.tpPos)
				addEvent(doRemoveItem, ((k.teleportTime*1000)*60), getTileItemById(1387, k.tpPos).uid, 1)
				addEvent(doCreateMonster, (((k.teleportTime*1000)*60)), getCreatureName(target), k.respPos)
			end
		end
	end
return true
end
Also, register it in login.lua

Your script is ok now, you know the base of scripting its good. but you used wrong way function getTileItemByID.

it is not used this way

Code:
getTileItemById(1387, k.tpPos).uid

it is supposed first to be item position and then item id so it should look like this.

Code:
addEvent(doRemoveItem, ((k.teleportTime*1000)*60), getTileItemById(k.tpPos, 1387).uid, 1)
 
[14:47:19.640] [Error - CreatureScript Interface]
[14:47:19.656] data/creaturescripts/scripts/bossdeath.lua:onKill
[14:47:19.656] Description:
[14:47:19.671] attempt to index a number value
[14:47:19.671] stack traceback:
[14:47:19.671] [C]: in function 'getTileItemById'
[14:47:19.671] data/creaturescripts/scripts/bossdeath.lua:18: in function <data
/creaturescripts/scripts/bossdeath.lua:12>

check this Error boss Room - YouTube
 
Back
Top