• 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 Kill a Monster to Create a Portal (with Optional Countdown)

Did you find this script by searching?


  • Total voters
    27

J.Dre

Unity Games
Joined
May 18, 2011
Messages
2,647
Solutions
3
Reaction score
648
Location
United States
Information:
This is a widely requested script. I decided to make a thread and properly tag it, allowing members to find it more easily while searching.

Tested and working on TFS 0.3.7. May not work for TFS 0.2.

How it works:
You simply add a monster to the table and kill the monster to create a portal.

2lk8eo6.jpg


Update Log:


    • v1.0: Initial Release
      * The initial release of the script.
    • v1.1: Bug Fix
      * Repaired an issue with the teleport not disappearing.
      * Repaired an issue with the timer.
    • v2.0: Script Update
      * Updated the script with new features, including but not limited to a 'doSendAnimatedText' function for a countdown effect.
    • v2.01: Bug Fix
      * Removed an extra "and" on line 27 of the 0.3.6 version.

For TFS 0.3.7:

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

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

data/creaturescripts/scripts/script.lua

Code:
local config = {
    useCountdown = true -- true or false
}

local t = {
    -- Monseter names must be lowercase.
    ["dog"] = {
        toPos = 'Thais', -- enter a position OR a town's name \\ toPos = {x = 100, y = 100, z = 7} //
        createPos = {x = 100, y = 100, z = 7, stackpos = 0},
        time = 10, -- seconds until the TP is removed
        msg = "You have taken my life!" -- the message the monster says upon death
    },
    ["cat"] = {
        toPos = 'Venore',
        createPos = {x = 100, y = 100, z = 7, stackpos = 0},
        time = 10, -- seconds until the TP is removed
        msg = "You have taken my life!" -- the message the monster says upon death
    }
}

local function remove(position)
    local k = getTileItemById(position, 1387).uid
    return k > 0 and doRemoveItem(k), doSendMagicEffect(position, CONST_ME_POFF)
end

local function doSendAnimatedText(pos, text, color, cid) -- by J.Dre
    if tonumber(text) then
        text = tonumber(text)
        if cid and isPlayer(cid) then
            doPlayerSendTextMessage(cid, MESSAGE_EXPERIENCE_OTHERS, "", text, color, pos)
        else
            local t = getSpectators(pos, 7, 5, false)
            if t then
                for _, cid in ipairs(t) do
                    if isPlayer(cid) then
                        doPlayerSendTextMessage(cid, MESSAGE_EXPERIENCE_OTHERS, "", text, color, pos)
                    end
                end
            end
        end
    else
        if cid and isCreature(cid) then
            doCreatureSay(cid, text, TALKTYPE_MONSTER)
        else
            local t = getSpectators(pos, 7, 5, false)
            if t then
                for _, cid in ipairs(t) do
                    if isPlayer(cid) then
                        doCreatureSay(cid, text, TALKTYPE_MONSTER, false, cid, pos)
                    end
                end
            end
        end
    end
end

function onKill(cid, target, damage, flags)
    local v = t[string.lower(getCreatureName(target))]
    if(v and (damage == true or bit.band(flags, 1) == 1) and isMonster(target)) then
        doCreatureSay(cid, v.msg, TALKTYPE_MONSTER, nil, nil, getCreaturePosition(target))
        doSendMagicEffect(v.createPos, CONST_ME_ENERGYAREA)
        doCreateTeleport(1387, type(v.toPos) == 'table' and v.toPos or getTownTemplePosition(getTownId(v.toPos)), v.createPos)
        if(config.useCountdown) then
            for j = 0, v.time do
                local i = v.time - j
                addEvent(doSendAnimatedText, j * 1000, v.createPos, i > 0 and tostring(i), MESSAGE_EVENT_DEFAULT)
            end
        end
        addEvent(remove, v.time * 1000, v.createPos)
    end

    return true
end
For TFS 0.3.6:

Warning: You may need to change "TALKTYPE_MONSTER" to "TALKTYPE_ORANGE_1".

Code:
local config = {
    useCountdown = true -- true or false
}

local t = {
    ["dog"] = {
        toPos = 'Thais', -- enter a position OR a town's name \\ toPos = {x = 100, y = 100, z = 7} //
        createPos = {x = 100, y = 100, z = 7, stackpos = 0},
        time = 10, -- seconds until the TP is removed
        msg = "You have taken my life!" -- the message the monster says upon death
    },
    ["cat"] = {
        toPos = 'Venore',
        createPos = {x = 100, y = 100, z = 7, stackpos = 0},
        time = 10, -- seconds until the TP is removed
        msg = "You have taken my life!" -- the message the monster says upon death
    },
}

local function remove(position)
    local k = getTileItemById(position, 1387).uid
    return k > 0 and doRemoveItem(k), doSendMagicEffect(position, CONST_ME_POFF)
end

function onKill(cid, target)
    local v = t[string.lower(getCreatureName(target))]
    if(v and isMonster(target)) then
        doCreatureSay(cid, v.msg, TALKTYPE_MONSTER, nil, nil, getCreaturePosition(target))
        doSendMagicEffect(v.createPos, CONST_ME_ENERGYAREA)
        doCreateTeleport(1387, type(v.toPos) == 'table' and v.toPos or getTownTemplePosition(getTownId(v.toPos)), v.createPos)
        if(config.useCountdown) then
            for j = 0, v.time do -- By J.Dre
                local i = v.time - j
                addEvent(doSendAnimatedText, j * 1000, v.createPos, i > 0 and tostring(i), TEXTCOLOR_WHITE)
            end
        end
        addEvent(remove, v.time * 1000, v.createPos)
    end

    return true
end
 
Last edited:
heey i'm using otx, same as tfs latest revs aaand..
[25/5/2013 22:3:40] [Error - CreatureScript Interface]
[25/5/2013 22:3:40] In a timer event called from:
[25/5/2013 22:3:40] data/creaturescripts/scripts/portal.lua:eek:nKill
[25/5/2013 22:3:40] Description:
[25/5/2013 22:3:40] attempt to index a nil value
[25/5/2013 22:3:40] stack traceback:
[25/5/2013 22:3:40] [C]: in function 'getTileItemById'
[25/5/2013 22:3:40] data/creaturescripts/scripts/portal.lua:17: in function <data/creaturescripts/scripts/portal.lua:16>
 
i get this error always when i kill the boss but it works, ps using tfs 0.4
[27/5/2013 14:34:47] [C]: in function 'getTileItemById'
[27/5/2013 14:34:47] data/creaturescripts/scripts/inq.lua:41: in function <data/creaturescripts/scripts/inq.lua:40>
 
Under local v, add
Lua:
local pos = v.createPos
 
aah u should replace
Code:
addEvent(remove, v.timeToRemove * 1000)
with
Code:
addEvent(remove, v.timeToRemove * 1000, position)

other monsters aren't dying..

edit..

i've added an array and worked ^^
Code:
local t = {
creatures = {"pythius the rotten", "ferumbras"
},
Code:
function onKill(cid, target, damage, flags)
if not isInArray(t.creatures, getCreatureName(target):lower()) then return true end  
	local v = t[string.lower(getCreatureName(target))]
 
Last edited:
Yeah, I hope it becomes of use for many. Especially for those with custom servers!
 
I see the thread and then I say: "should be a cool script", but now I see the script and congratulations! I really like it, it's simple and clean, useful and good written.

freeBump to this code :)
Good job, gl&hf
 
[25/06/2013 15:50:00] [Error - CreatureScript Interface]
[25/06/2013 15:50:00] In a timer event called from:
[25/06/2013 15:50:00] data/creaturescripts/scripts/underwater.lua:eek:nKill
[25/06/2013 15:50:00] Description:
[25/06/2013 15:50:00] (luaDoPlayerSendTextMessage) Player not found
 
[29/6/2013 16:51:29] >>> Loading Scripts en General MOD.xml ...[Error - LuaInterface::loadFile] ...s en General/Azzkaban Creaturescripts Respaldo/Teleport Countdown 01.lua:27: unexpected symbol near 'and'
[29/6/2013 16:51:30] [Error - Event::checkScript] Cannot load script (mods/scripts/Scripts en General/Azzkaban Creaturescripts Respaldo/Teleport Countdown 01.lua)
[29/6/2013 16:51:30] ...s en General/Azzkaban Creaturescripts Respaldo/Teleport Countdown 01.lua:27: unexpected symbol near 'and'


Lua:
local config = {
	useCountdown = true -- true or false
}
 
local t = {
	["Voldemort Ilusion"] = {
		toPos = {x = 257, y = 140, z = 3}, -- enter a position OR a town's name \\ toPos = {x = 100, y = 100, z = 7} //
		createPos = {x = 253, y = 133, z = 4, stackpos = 0},
		time = 10, -- seconds until the TP is removed
		msg = "You have taken my life!" -- the message the monster says upon death
	},
	["cat"] = {
		toPos = 'Venore',
		createPos = {x = 100, y = 100, z = 7, stackpos = 0},
		time = 10, -- seconds until the TP is removed
		msg = "You have taken my life!" -- the message the monster says upon death
	},
}
 
local function remove(position)
    local k = getTileItemById(position, 1387).uid
    return k > 0 and doRemoveItem(k), doSendMagicEffect(position, CONST_ME_POFF)
end
 
function onKill(cid, target)
	local v = t[string.lower(getCreatureName(target))]
	if(v and and isMonster(target)) then
		doCreatureSay(cid, v.msg, TALKTYPE_MONSTER, nil, nil, getCreaturePosition(target))
		doSendMagicEffect(v.createPos, CONST_ME_ENERGYAREA)
		doCreateTeleport(1387, type(v.toPos) == 'table' and v.toPos or getTownTemplePosition(getTownId(v.toPos)), v.createPos)
		if(config.useCountdown) then
			for j = 0, v.time do
				local i = v.time - j
				addEvent(doSendAnimatedText, j * 1000, v.createPos, i > 0 and tostring(i), TEXTCOLOR_WHITE)
			end
		end
		addEvent(remove, v.time * 1000, v.createPos)
	end
	return true
end
 
Back
Top