• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

CreatureEvent Kill Monster & Create Portal

Status
Not open for further replies.

JDB

OtLand Veteran
Joined
Jun 1, 2009
Messages
4,145
Solutions
2
Reaction score
115
Credits:
v1.0 - JDB - 0.3.6pl1+
v1.1 - JDB - 0.3.6pl1+
v2.0 - JDB - Not Tested


Notice
You must restart your server after adding these in because if you do not, there is a chance that it may crash.
Please report any errors you may have and I will try to assist you.

data/creaturescripts/scripts/login.lua
Code:
registerCreatureEvent(cid, "MonsterPortal")

data/creaturescripts/creaturescripts.xml
Code:
<event type="kill" name="MonsterPortal" event="script" value="portals.lua"/>

Version 1.0
data/creaturescripts/scripts/portals.lua
Code:
function onKill(cid, target)
	local m = {
		["Morgaroth"] = {
			message = "Escape through the teleport quickly before it closes!",
			cfg = {
				{
					time = 10, -- Seconds until tp closes.
					to = { x = 95, y = 117, z = 7 }, -- Where the tp takes you.
					tp = { x = 95, y = 112, z = 7 } -- Where the tp creates.
				},
			}
		}
	}
	if isPlayer(target) then
		return true
	end
	local monster = m[getCreatureName(target)]
	if monster then
		for i = 1, #monster.cfg do
			local c = monster.cfg[i]
				local function deleteTeleport()
				local teleport = getTileItemById(c.tp, 1387).uid
					if(teleport > 0) then
						doRemoveItem(teleport)
						doSendMagicEffect(c.tp, CONST_ME_POFF)
					end
					return true
				end
			doCreateTeleport(1387, c.to, c.tp)
			doSendMagicEffect(c.tp, CONST_ME_ENERGYAREA)
			addEvent(deleteTeleport, c.time * 1000)
		end
		doCreatureSay(cid, monster.message, TALKTYPE_ORANGE_1)
	end
	return true
end

Version 1.1
data/creaturescripts/scripts/portals.lua
Code:
function onKill(cid, target)
	local m = {
		["Morgaroth"] = {
			message = "Escape through the teleport quickly before it closes!",
			cfg = {
				{
					time = 10, -- Seconds until tp closes.
					to = { x = 95, y = 117, z = 7 }, -- Where the tp takes you.
					tp = { x = 95, y = 112, z = 7 } -- Where the tp creates.
				},
			}
		}
	}
	if isPlayer(target) then
		return true
	end
	local monster = m[getCreatureName(target)]
	if monster then
		for i = 1, #monster.cfg do
			local c = monster.cfg[i]
			return doCreateTeleport(c.to, c.tp) and doSendMagicEffect(c.tp, CONST_ME_TELEPORT) and doCreatureSay(cid, monster.message, TALKTYPE_ORANGE_1) and addEvent(function() doRemoveItem(getTileItemById(c.tp, 1387).uid) end, c.time * 1000)
		end
	end
	return true
end

Version 2.0
This version has not been tested, but it's supposed to give creatures multiple lives.
data/creaturescripts/scripts/portals.lua
Code:
function onKill(cid, target)
	local m = {
		["Morgaroth"] = {
			message = "Escape through the teleport quickly before it closes!",
			teaser = { "You can't kill me!", "I am invincible!" }
			cfg = {
				{
					deaths = 1, -- How many times the monster must die.
					time = 10, -- Seconds until tp closes.
					to = { x = 95, y = 117, z = 7 }, -- Where the tp takes you.
					tp = { x = 95, y = 112, z = 7 } -- Where the tp creates.
				},
			}
		}
	}
	if isPlayer(target) then
		return true
	end
	local monster = m[getCreatureName(target)]
	local check = getGlobalStorageValue(monster)
	if monster then
		for i = 1, #monster.cfg do
			local c = monster.cfg[i]
			return check >= c.deaths and c.deaths ~= 0 and setGlobalStorageValue(monster, ((c.deaths ~= nil and (check == -1 and 1) or check + 1) or -1)) and doCreatureAddHealth(monster, getCreatureMaxHealth(monster), true) and doCreatureSay(monster, monster.teaser[math.random(1, #monster.teaser)], TALKTYPE_ORANGE_1) and doCreateTeleport(c.to, c.tp) and doSendMagicEffect(c.tp, CONST_ME_TELEPORT) and addEvent(function() doRemoveItem(getTileItemById(c.tp, 1387).uid) end, c.time * 1000) or c.deaths <= 1 and doCreatureSay(cid, monster.message, TALKTYPE_ORANGE_1) and doCreateTeleport(c.to, c.tp) and doSendMagicEffect(c.tp, CONST_ME_TELEPORT) and addEvent(function() doRemoveItem(getTileItemById(c.tp, 1387).uid) end, c.time * 1000)
		end
	end
	return true
end

Comments are always appreciated, but if you feel like flaming, just leave.
If you feel this script needs to be improved, feel free to private message me with suggestions.

Kind Regards,
JDB.
 
Last edited:
this part is not really necesary

Lua:
	if (not monster) then
		return true
	end
and already told you is not necesary return anything in added events
 
@Nahruto,

I will test it without and see if it works just fine. Thanks for that tip.

Edit: It works, thanks again.

Regards,
JDB.
 
and what is new in v2.0 ?

and where you got the idea from? :eek: i mean the config tabbing.
 
i was kinda confused why you used the loop and then i noticed that your array its kinda _confusing_, could be more simple, btw nice script (y)
 
@Cykotitan,
I thought it might execute faster, if the code was more organized, like the delayed script you made.

@Nahruto,
Thanks :thumbup:

Regards.
 
http://otland.net/f132/2min-delay-then-create-teleport-how-71048/#post728295
more tabs = more bytes = a few nanoseconds slower execution time

Edit: Loop Feature - Cykotitan
ok

this way look cleaner, atleast for me 8) less confusing

Lua:
local t =
	{
	["azerus"] = 
		{
			message = "Azerus ran into teleporter! It will disappear in 2 minutes. Enter It!",
			delay = {120, 240},
			destination = {{x=32784, y=31169, z=9}, {x=32784, y=31169, z=9}},
			create = {{x=32783, y=31177, z=9}, {x=32783, y=31177, z=9}}
		}
	}
	
function onDeath(cid, corpse, deathList)
	local k = t[getCreatureName(cid):lower()]
	if k then
		for i, p in ipairs(k.delay) do
			addEvent(doCreateTeleport, p * 1000, 1387, k.destination[i], k.create[i])
		end
		doCreatureSay(cid, k.message, TALKTYPE_ORANGE_1)
	end
	return true
end

edit: changed a var name 8)
 
@Nahruto, actually it looks more confusing like that (atleast to me)
Ahh, okay, so if you minimize the size it will execute faster? I suppose that's why you write a code in one line?

Regards.
It's just nanoseconds/miliseconds.
Code:
[13:54:34] <@7Talaturen> 12:56:59 <+idk> local v, w, h = "", 0, true
[13:54:36] <@Talaturen> elf style
[14:09:20] <+idk> oww
[14:09:23] <+idk> yes
[14:09:26] <+idk> :S
[14:09:52] <+idk> less cpu usage :D
[14:09:56] <+idk> new line = mass lagg
[14:11:46] <7Barker2> what does idk mean
...
[14:38:12] <@7Talaturen> idk: no, not less cpu usage
[14:38:15] <@Talaturen> no different at all :s
[14:38:16] <+idk> xD
[14:38:18] <+idk> i know -.-
[14:38:28] <+idk> but i always use logical operators
[14:38:35] <+idk> but it's limited in c++ -.- c++ suks
[14:38:46] <+idk> cant make 999999999 of them in 1 line
[14:38:47] <+idk> :C
[14:38:58] <+idk> ahm
[14:39:02] <+idk> this has nothing to do
[14:39:06] <+idk> with logical operators
[14:39:09] <+idk> fcuk
 
Me too :wub:
 
Thanks, working with Azerus, but doesn't work with Pythius The Rotten

Code:
local m = {
	["Azerus"] = {
		message = "Escape through the teleport quickly before it closes!",
		cfg = {
			{
				time = 15,
				to = {x = 1023, y = 1122, z = 8},
				tp = {x = 1006, y = 1120, z = 10}
			},
		}
	},
	["Pythius The Rotten"] = {
		message = "Escape through the teleport quickly before it closes!",
		cfg = {
			{
				time = 10,
				to = {x = 1003, y = 912, z = 8},
				tp = {x = 1019, y = 908, z = 8}
			},
		}
	}
}

function onKill(cid, target)
	if isPlayer(target) then
		return true
	end
	local monster = m[getCreatureName(target)]
	if monster then
		for i = 1, #monster.cfg do
			local c = monster.cfg[i]
				local function deleteTeleport()
				local teleport = getTileItemById(c.tp, 1387).uid
					if(teleport > 0) then
						doRemoveItem(teleport)
						doSendMagicEffect(c.tp, CONST_ME_POFF)
					end
					return true
				end
			doCreateTeleport(1387, c.to, c.tp)
			doSendMagicEffect(c.tp, CONST_ME_ENERGYAREA)
			addEvent(deleteTeleport, c.time * 1000)
		end
		doCreatureSay(cid, monster.message, TALKTYPE_ORANGE_1)
	end
	return true
end


EDIT: Found the problem! In monsters.xml, Pythius The Rotten was added like "Pythius the Rotten ... working now.
 
Last edited:
Thanks, working with Azerus, but doesn't work with Pythius The Rotten

EDIT: Found the problem! In monsters.xml, Pythius The Rotten was added like "Pythius the Rotten ... working now.

Simple mistake, glad it's helping you out. :)
 
Been a while since anyone posted here. :wub:
 
I haven't tested and won't because 0.4 does not run well on vista, and sadly, I have vista.
 
In This Thread: IRC fails and messy arrays
 
Status
Not open for further replies.
Back
Top