-- this script is built to be 'globally used'.
-- So all players on the server work towards the goal of unlocking the teleport.
--[[
<event type="kill" name="onKillGlobalTeleportCreation" event="script" value="onKillGlobalTeleportCreation.lua"/>
registerCreatureEvent(cid, "onKillGlobalTeleportCreation")
--]]
local teleport_itemid = 1387
local t = {
[{"rat", "cave rat"}] = { -- one or more creatures
storage = 45001, -- global storage value. Change to something currently not in use.
amount = 10, -- amount of monsters that need to be killed, in order to activate the teleporter
teleport_position = {x = 1000, y = 1000, z = 7}, -- position that the teleporter will be spawned.
teleport_destination = {x = 1000, y = 1000, z = 7}, -- position that the teleporter will take you to.
time_until_remove = 10, -- time in SECONDS until teleport is removed.
delay_between_activations = 10 -- time in MINUTES before the teleport can be re-activated again. (aka: reset)
},
[{"rat"}] = {
storage = 45002,
amount = 10,
teleport_position = {x = 1000, y = 1000, z = 7},
teleport_destination = {x = 1000, y = 1000, z = 7},
time_until_remove = 10,
delay_between_activations = 10
},
-- can put it like above, or 'condensed' like below.
[{"rat", "cave rat"}] = {storage = 45003, amount = 10, teleport_position = {x = 1000, y = 1000, z = 7}, teleport_destination = {x = 1000, y = 1000, z = 7}, time_until_remove = 10, delay_between_activations = 10},
[{"cave rat"}] = {storage = 45004, amount = 10, teleport_position = {x = 1000, y = 1000, z = 7}, teleport_destination = {x = 1000, y = 1000, z = 7}, time_until_remove = 10, delay_between_activations = 10},
[{"rat"}] = {storage = 45005, amount = 10, teleport_position = {x = 1000, y = 1000, z = 7}, teleport_destination = {x = 1000, y = 1000, z = 7}, time_until_remove = 10, delay_between_activations = 10}
}
local function delayedTeleportRemoval(position)
local teleport = getTileItemById(position, teleport_itemid).uid
if teleport > 0 then
doRemoveItem(teleport)
doSendMagicEffect(position, CONST_ME_POFF)
end
return true
end
function onKill(cid, target, damage, flags)
for v, k in pairs(t) do
local master = getCreatureMaster(target)
if master and master ~= target then
return true
end
if bit.band(flags, 1) == 1 and isMonster(target) and isInArray(v, getCreatureName(target):lower()) then
local g_storage, cur_time = getGlobalStorageValue(k.storage), os.time()
if g_storage == -1 or g_storage > k.amount and cur_time > g_storage then
setGlobalStorageValue(k.storage, 0)
g_storage = 0
end
if g_storage <= k.amount then
setGlobalStorageValue(k.storage, g_storage + 1)
g_storage = g_storage + 1
end
if g_storage == k.amount then
setGlobalStorageValue(k.storage, cur_time + (60 * k.delay_between_activations))
doCreateTeleport(teleport_itemid, k.teleport_destination, k.teleport_position)
addEvent(delayedTeleportRemoval, 1000 * k.time_until_remove, k.teleport_position)
end
end
end
return true
end