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

Windows Automatic Event

juansanchez

Intermediate OT User
Joined
Apr 2, 2015
Messages
217
Reaction score
130
Hey people from otland, today i need a help improving a mod i have.

So, i need this mod of mine to happen automatically, let's say, it happens twice a week, so every Monday and every Friday for example, a teleport opens in a specific location in the map, and it stays open for 2 minutes so players can go to the Arena.

The mod is this one:

<?xml version="1.0" encoding="ISO-8859-1"?>
<mod name="Arena" version="1.0" author="DrakyLucas" contact="XTibia" enabled="yes">
<config name="arena_config"><![CDATA[
config = {
delay = 60, -- tempo de um level para o outro
posicaoPlayer = {x = 359,y = 178,z = 7}, -- posição q o player vai cair dps de entra no TP
posicaoArena = {{x = 343,y = 167,z = 7},{x = 375,y = 188,z = 7}},
premio = {
{12544,1},
}, -- ID, Quantidade... só aceita de 1 a 100 por vez, e você pode adicionar quantos itens quiser.
storage = 15444, -- não mecha..
posicaoTp = {x = 540, y = 525, z = 6}, -- posicao que o teleporte vai aparecer
acesso = 3, -- acesso minimo para ser ignorado pelo evento, e o mesmo acesso para poder inicializa-lo
}
-- você pode adicionar quantos leveis desejar
-- [NumeroDoLevel] = {{"Nome",Quantidade},{"Nome",Quantidade},{"Nome",Quantidade},{"Nome",Quantidade},{"Nome",Quantidade}},
leveis = {
[1] = {{"Orshabaal",15},{"Demon",25}},
[2] = {{"Tartaruga Mutante",15},{"Tartaruga Mutante Suprema",10}},
[2] = {{"Morgaroth",15},{"Dona Morte",10}},
[3] = {{"Demonio do Sexto Inferno",15},{"Orghus",12}},
[4] = {{"Abominavel",15},{"Lagarto Escolhido",15}},
[5] = {{"Lagarto Escolhido",15},{"Demonio do Sexto Inferno",2}},
[6] = {{"Lagarto Escolhido",15},{"Abominavel",15},{"Apolo",4}},
}
function abrirTeleport(n)
doItemSetAttribute(doCreateItem(1387, config.posicaoTp), "aid", 2941) -- cria o tp e deixa aid 2941
doBroadcastMessage("O Evento Desafio dos Monstros foi aberto. O teleport esta localizado no cu do lipe, sao necessarias ".. n .. " pessoas para iniciar o evento.")
doSetStorage(config.storage, n)
end
function fecharTPeAguardarEvento()
doRemoveItem(getTileItemById(config.posicaoTp, 1387).uid,100)
doBroadcastMessage("O evento atingiu " .. #getPlayersInArena() .. " players e comecara em " .. config.delay .. " segundos!")
addEvent(evento,config.delay*1000,1)
end
function HaveCreatureArena(area, remove, clean) -- função do Vodkart
for x = area[1].x - 1, area[2].x + 1 do
for y = area[1].y - 1, area[2].y + 1 do
local pos = {x=x, y=y, z=area[1].z}
local m = getTopCreature(pos).uid
if remove ~= false and m ~= 0 and isMonster(m) then doRemoveCreature(m) end
if clean ~= false then doCleanTile(pos, false) end
end
end
end
function resetEvento()
doSetStorage(config.storage, -1)
end
function criarMonstros(lv)
local monstro = leveis[lv]
local area = {config.posicaoArena[1],config.posicaoArena[2]}
for i = 1,#monstro do
for k=1,monstro[2]do
pos = {x=math.random(area[1].x,area[2].x), y=math.random(area[1].y,area[2].y), z=area[1].z}
monstrinho = doCreateMonster(monstro[1], pos)
registerCreatureEvent(monstrinho, "removerCorpse")
end
end
end
function evento(i)
if #getPlayersInArena() == 0 then
doBroadcastMessage("Ninguem sobreviveu o Desafio dos Monstros.")
doBroadcastMessage("EVENTO TERMINADO!")
HaveCreatureArena({config.posicaoArena[1],config.posicaoArena[2]}, true, true) -- remove monstros, itens da arena
resetEvento()
return true
end
if i == (#leveis +1) then
HaveCreatureArena({config.posicaoArena[1],config.posicaoArena[2]}, true, true)
doBroadcastMessage("Evento finalizado, " .. #getPlayersInArena() .. " players sobreviveram ao evento!")
for _, pid in ipairs(getPlayersInArena()) do
doPlayerSendTextMessage(pid,22,"Parabens, você sobreviveu ao evento!")
addItens(pid)
doTeleportThing(pid,getTownTemplePosition(getPlayerTown(pid)))
end
resetEvento()
return true
end
for _, pid in ipairs(getPlayersInArena()) do
doPlayerSendTextMessage(pid,22,"GoGo Nivel " .. i .. " !!!")
end
criarMonstros(i)
addEvent(evento,config.delay*1000,i+1)
end
function addItens(pid)
for i=1,#config.premio do
doPlayerAddItem(pid,config.premio[1],config.premio[2])
end
doPlayerSendTextMessage(pid,22,"Parabens, voce recebeu seu premio!")
end
function getPlayersInArena()
local t = {}
for _, pid in pairs(getPlayersOnline()) do
if getPlayerAccess(pid) < config.acesso then
if isInRange(getCreaturePosition(pid), config.posicaoArena[1], config.posicaoArena[2]) then
table.insert(t, pid)
end
end
end
return t
end
]]></config>
<talkaction words="/arena" event="buffer"><![CDATA[
domodlib('arena_config')
if getPlayerAccess(cid) < config.acesso then
return doPlayerSendCancel(cid,"Voce nao tem acesso para esse comando")
end
if tonumber(param) ~= nil then -- se o parametro é numerico
if tonumber(param) > 0 then
doSetStorage(config.storage, param)
abrirTeleport(param)
end
else
doPlayerSendTextMessage(cid,19,"Digite /arena e um numero.. \n exemplo: \n/arena 5")
end

]]></talkaction>

<movevent type="StepIn" actionid="2941" event="script"><![CDATA[
domodlib('arena_config')
if getPlayerAccess(cid) > config.acesso then doTeleportThing(cid, config.posicaoPlayer) return false end -- GM nao conta
doSetStorage(config.storage,getStorage(config.storage) - 1)
doTeleportThing(cid, config.posicaoPlayer)
registerCreatureEvent(cid, "naoAtacarPlayer")
registerCreatureEvent(cid, "morrerNaArena")
if getStorage(config.storage) <= 0 then
fecharTPeAguardarEvento()
end
return true
]]></movevent>
<event type="login" name="VerSeTaNaArenaEExpulsa" event="script"><![CDATA[
domodlib('arena_config')
if isInRange(getCreaturePosition(cid), config.posicaoArena[1], config.posicaoArena[2]) then
doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
end
return true
]]></event>
<event type="combat" name="naoAtacarPlayer" event="script"><![CDATA[
domodlib('arena_config')
if isPlayer(cid) and isPlayer(target) then
if isInRange(getPlayerPosition(cid), config.posicaoArena[1], config.posicaoArena[2]) and isInRange(getPlayerPosition(target), config.posicaoArena[1], config.posicaoArena[2]) then
doPlayerSendCancel(cid, "Nao ataque seus amigos.")
return false
end
end
return true
]]></event>
<event type="statschange" name="morrerNaArena" event="script"><![CDATA[
domodlib('arena_config')
if isInRange(getPlayerPosition(cid), config.posicaoArena[1], config.posicaoArena[2]) then
if type == STATSCHANGE_HEALTHLOSS then
if isPlayer(cid) then
if value >= getCreatureHealth(cid) then
doTeleportThing(cid,getTownTemplePosition(getPlayerTown(cid)))
doPlayerSendTextMessage(pid,22,"Você morreu na arena =/.. veja pelo lado positivo, você nao perdeu nada!")
doCreatureAddHealth(cid,getCreatureMaxHealth(cid) - getCreatureHealth(cid))
return false
end
end
end
end
return true
]]></event>
</mod>


The mod basically works this way: I use the talkaction, /arena X, the X is the amount of players i allow to enter the event, so if i say, /arena 5, only 5 players can enter.
If anyone knows how to make it so in the 2 minutes the teleport stays open, any amount of players can go in. Not a specific amount as the mod requires.

I don't know if i forgot to explain anything, if anyone has any doubts about it, just ask it.

I'm using TFS 0.3.7
 
I had started making something similar for someone in my scripting thread.
Code:
-- <globalevent name="event" time="17:00" event="script" value="event.lua"/>

local config = {
    storage = 45001
    boss_name = "unusually large rat"
    day_of_week = "Saturday" -- you can edit Saturday for: Monday, Tuesday, et cetera
    teleport_position = {x = 1000, y = 1000, z = 7}, -- where teleport spawns
    teleport_to_position = {x = 1111, y = 1111, z = 7}, -- where you will be teleported
}

local boss_positions = {
    [1] = {x = 1111, y = 1111, z = 11},
    [2] = {x = 2222, y = 2222, z = 22},
    [3] = {x = 3333, y = 3333, z = 33}
}

function onTime()
    if(os.date("%A") == config.day_of_week) then
        doCreateTeleport(1387, config.teleport_to_position, config.teleport_position)
        doBroadcastMessage("Event Started!", MESSAGE_EVENT_ADVANCE)
        local rand_pos = boss_positions[math.random(#boss_positions)]
        doCreateMonster(config.boss_name, rand_pos)
    end
    return true
end
-- edited for your purposes
Code:
-- <globalevent name="event" time="17:00" event="script" value="event.lua"/>

function onTime()
    if os.date("%A") == Monday then
        local tp = doCreateTeleport(1387, {x = 1000, y = 1000, z = 7}, {x = 1111, y = 1111, z = 7}) -- teleportID, where_spawn, where_go
        doBroadcastMessage("Event Started!", MESSAGE_EVENT_ADVANCE)
        addEvent(doRemoveItem, 2 * 60 * 1000, tp.uid)
    elseif os.date("%A") == Friday then
        local tp = doCreateTeleport(1387, {x = 1000, y = 1000, z = 7}, {x = 1111, y = 1111, z = 7}) -- teleportID, where_spawn, where_go
        doBroadcastMessage("Event Started!", MESSAGE_EVENT_ADVANCE)
        addEvent(doRemoveItem, 2 * 60 * 1000, tp.uid)
    end
    return true
end
 
I had started making something similar for someone in my scripting thread.
Code:
-- <globalevent name="event" time="17:00" event="script" value="event.lua"/>

local config = {
    storage = 45001
    boss_name = "unusually large rat"
    day_of_week = "Saturday" -- you can edit Saturday for: Monday, Tuesday, et cetera
    teleport_position = {x = 1000, y = 1000, z = 7}, -- where teleport spawns
    teleport_to_position = {x = 1111, y = 1111, z = 7}, -- where you will be teleported
}

local boss_positions = {
    [1] = {x = 1111, y = 1111, z = 11},
    [2] = {x = 2222, y = 2222, z = 22},
    [3] = {x = 3333, y = 3333, z = 33}
}

function onTime()
    if(os.date("%A") == config.day_of_week) then
        doCreateTeleport(1387, config.teleport_to_position, config.teleport_position)
        doBroadcastMessage("Event Started!", MESSAGE_EVENT_ADVANCE)
        local rand_pos = boss_positions[math.random(#boss_positions)]
        doCreateMonster(config.boss_name, rand_pos)
    end
    return true
end
-- edited for your purposes
Code:
-- <globalevent name="event" time="17:00" event="script" value="event.lua"/>

function onTime()
    if os.date("%A") == Monday then
        local tp = doCreateTeleport(1387, {x = 1000, y = 1000, z = 7}, {x = 1111, y = 1111, z = 7}) -- teleportID, where_spawn, where_go
        doBroadcastMessage("Event Started!", MESSAGE_EVENT_ADVANCE)
        addEvent(doRemoveItem, 2 * 60 * 1000, tp.uid)
    elseif os.date("%A") == Friday then
        local tp = doCreateTeleport(1387, {x = 1000, y = 1000, z = 7}, {x = 1111, y = 1111, z = 7}) -- teleportID, where_spawn, where_go
        doBroadcastMessage("Event Started!", MESSAGE_EVENT_ADVANCE)
        addEvent(doRemoveItem, 2 * 60 * 1000, tp.uid)
    end
    return true
end

Xikini, can you add to the second one a function that checks a certain area after the teleport closes and if there's anyone in the area, they'll get kicked out of it?
 
Back
Top Bottom