changos
Member
- Joined
- Feb 13, 2012
- Messages
- 75
- Solutions
- 5
- Reaction score
- 22
Hello im trying to create a event but i have some errors
i want when a player enters to event it tp to "free spots" like the tp of trainers room (tp is teleporting to the same spot)
and when the tp closes i want the players send animated text with countdown
i were trying to fix but im not good enough to do xd
this is the script (sorry for the messy of script) :
Thanks
OTX 2.9 Based on 0.4
i want when a player enters to event it tp to "free spots" like the tp of trainers room (tp is teleporting to the same spot)
and when the tp closes i want the players send animated text with countdown
i were trying to fix but im not good enough to do xd
this is the script (sorry for the messy of script) :
XML:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Push2Death Event" version="1.0" author="" contact="" enabled="yes">
<config name="p2d_config"><![CDATA[
p2d_config = {
delay = 180, -- time to close event
posArena = {{x = 835, y = 858, z = 6},{x = 869, y = 879, z = 6}},
reward = {
{9020, 30},
}, -- ID, count... only 1-100, u can add more rewards.
storage = 6441445, -- dont change..
storages = {6441446, 6441447}, -- n edite
posTp = {x = 1005, y = 1002, z = 6}, -- appear pos tp
timeToStartEvent = 10,
players = {min = 2, max = 20}, -- min, max players on evento
access = 3, -- acesso minimo para ser ignorado pelo evento, e o mesmo acesso para poder inicializa-lo
minLvl = 80
}
push2d_days = {
["Monday"] = {"12:20","19:15"},
["Wednesday"] = {"22:54"},
["Thursday"] = {"22:38","22:43"},
["Friday"] = {"20:10"},
["Sunday"] = {"22:40"}
}
location = {
{x = 836, y = 859, z = 6}, -- FIRST SPOT
{x = 838, y = 861, z = 6}, -- SECOND SPOT
{x = 844, y = 864, z = 6}, -- ...
{x = 850, y = 864, z = 6},
{x = 854, y = 864, z = 6},
{x = 860, y = 864, z = 6},
{x = 866, y = 861, z = 6},
{x = 868, y = 859, z = 6},
{x = 852, y = 866, z = 6},
{x = 844, y = 869, z = 6},
{x = 860, y = 869, z = 6},
{x = 852, y = 872, z = 6},
{x = 836, y = 878, z = 6},
{x = 838, y = 876, z = 6},
{x = 844, y = 874, z = 6},
{x = 850, y = 874, z = 6},
{x = 854, y = 874, z = 6},
{x = 860, y = 874, z = 6},
{x = 866, y = 876, z = 6},
{x = 868, y = 878, z = 6},
}
function removeTp()
local t = getTileItemById(p2d_config.posTp, 1387).uid
return t > 0 and doRemoveItem(t) and doSendMagicEffect(p2d_config.posTp, CONST_ME_POFF)
end
function ZerarStoragesPush()
for _, stor in pairs(p2d_config.storages) do
setGlobalStorageValue(stor, 0)
end
end
function getPlayersInEvent()
local t = {}
for _, pid in pairs(getPlayersOnline()) do
if isInRange(getPlayerPosition(pid), p2d_config.posArena[1], p2d_config.posArena[2]) and getPlayerAccess(pid) < 3 then
t[#t+1] = pid
end
end
return t
end
function getPlayersEnEvent()
players = {}
for _, pid in pairs(getPlayersOnline()) do
if (getCreatureStorage(pid, p2d_config.storage) > 0) then
table.insert(players, pid)
end
end
return true
end
function countdown(tempo)
local pid = getCreaturePosition(getPlayersInEvent())
local pos = getThingPos(pid)
local tempo = p2d_config.timeToStartEvent
--for i=1,#getPlayersInEvent() do
for _, pid in pairs(getPlayersInEvent()) do
doSendAnimatedText(pid,tempo,TEXTCOLOR_RED)
addEvent(countdown,1000,pos,tempo-1)
--table.insert(t, pid)
end
--return t
end
function addReward(cid)
for i=1,#p2d_config.reward do
doPlayerAddItem(cid,p2d_config.reward[i][1],p2d_config.reward[i][2])
end
doPlayerSendTextMessage(cid,22,"Congrats, You win PUSH2DEATH EVENT!")
end
function Unfreezex()
for _, cid in pairs(getPlayersEnEvent()) do
doCreatureSetNoMove(cid,false)
end
end
function Unfreeze()
for _, cid in pairs(getPlayersInEvent()) do
doCreatureSetNoMove(cid,false)
end
end
function toTemple(all)
todos = {}
for _, all in pairs(getPlayersEnEvent()) do
doTeleportThing(all, getTownTemplePosition(getPlayerTown(cid)))
doCreatureSetNoMove(all,false)
table.insert(todos, all)
end
return todos
end
function CheckEvent(delay)
if getGlobalStorageValue(p2d_config.storages[1]) ~= (p2d_config.players.max+1) then
if delay > 0 and getGlobalStorageValue(p2d_config.storages[1]) < p2d_config.players.max then
doBroadcastMessage("[PUSH2DEATH EVENT] starting in " .. delay .. " minutes! The teleport will be closed when the event start!", MESSAGE_STATUS_WARNING)
elseif delay == 0 and getGlobalStorageValue(p2d_config.storages[1]) < p2d_config.players.min then
for _, cid in pairs(getPlayersInEvent()) do
doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
doSendMagicEffect(getPlayerPosition(cid), CONST_ME_TELEPORT)
doCreatureSetNoMove(cid,false)
end
removeTp()
doBroadcastMessage("[PUSH2DEATH EVENT] could not start cause we need more players.\n At least " .. p2d_config.players.min .. " players is needed!", MESSAGE_STATUS_WARNING)
toTemple(all)
ZerarStoragesPush()
elseif delay == 0 and getGlobalStorageValue(p2d_config.storages[1]) >= p2d_config.players.min then
removeTp()
doBroadcastMessage("[PUSH2DEATH EVENT] is now full [" .. getGlobalStorageValue(p2d_config.storages[1]) .. " players]!it will soon start.")
for _, var in pairs(getPlayersInEvent()) do
countdown(tempo)
doPlayerSendTextMessage(var, MESSAGE_EVENT_ADVANCE, "The event will start in " .. p2d_config.timeToStartEvent .. " seconds! Good luck!")
end
addEvent(Unfreeze, p2d_config.timeToStartEvent*1000)
end
addEvent(CheckEvent, 30000, delay-1)
end
return true
end
function getWinner()
if #getPlayersInEvent() == 1 then
local winner = getPlayersInEvent()[1]
doBroadcastMessage(getCreatureName(winner)..' is the winner of PUSH2DEATH!')
doTeleportThing(winner, getTownTemplePosition(getPlayerTown(winner)), true)
setPlayerStorageValue(winner, p2d_config.storage, 0)
addReward(winner)
ZerarStoragesPush()
end
end
function checkSQM()
for _, m in ipairs(p2d_config.positions) do
local f = getTopCreature(m).uid
if not isPlayer(f) then
doTeleportThing(m)
end
return true
end
end
function TpIn()
for z = 1, #p2d_config.location do
--if getTopCreature(location[z]).uid > 0 then
if not isPlayer(getTopCreature(location[z]).uid) then
doTeleportThing(cid, location[z])
end
return true
end
end
function TpEnter()
for z = 1, #location do
local pos = getThingPos(z)
if not isPlayer(getTopCreature(pos).uid) then
doTeleportThing(cid, pos)
end
return true
end
end
]]></config>
<movevent type="StepIn" actionid ="47170" event="script"><![CDATA[
domodlib('p2d_config')
function onStepIn(cid, item, position, fromPosition)
registerCreatureEvent(cid, "DAP2D")
registerCreatureEvent(cid, "DpwhP2D")
if not isPlayer(cid) then return true end
if getPlayerAccess(cid) > 3 then return doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid))) end
if getPlayerLevel(cid) < p2d_config.minLvl then
doTeleportThing(cid, fromPosition, true)
doPlayerSendCancel(cid, "You need to be at least level " .. p2d_config.minLvl .. ".")
doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
return true
end
if getGlobalStorageValue(p2d_config.storages[1]) <= p2d_config.players.max then
--doTeleportThing(p2d_config.positions[1])
--tpEnter()
--TpIn()
--checkSQM()
for i = 1, #location do
--if getTopCreature(location[i]).uid ~= 0 then
--local pos = getThingPos(location[z])
--if getTopCreature(location[i]).uid > 0 then
--if not isPlayer(getTopCreature(pos).uid) then
--if not isPlayer(getTopCreature(location[i]).uid) then
--if not isPlayer(getTopCreature(location[i]).uid) > 0 then
if isPlayer(getTopCreature(location[i]).uid) then
doTeleportThing(cid, location[i])
--doTeleportThing(cid, pos)
doCreatureSetNoMove(cid,true)
setPlayerStorageValue(cid, p2d_config.storage, 1)
setGlobalStorageValue(p2d_config.storages[1], getGlobalStorageValue(p2d_config.storages[1])+1)
doBroadcastMessage(getPlayerName(cid) .. " entered to PUSH2DEATH EVENT! Currently " .. getGlobalStorageValue(p2d_config.storages[1]) .. " players have joined!", MESSAGE_STATUS_CONSOLE_RED)
else
doTeleportThing(cid, location[i])
doCreatureSetNoMove(cid,true)
setPlayerStorageValue(cid, p2d_config.storage, 1)
setGlobalStorageValue(p2d_config.storages[1], getGlobalStorageValue(p2d_config.storages[1])+1)
doBroadcastMessage(getPlayerName(cid) .. " entered to PUSH2DEATH EVENT! Currently " .. getGlobalStorageValue(p2d_config.storages[1]) .. " players have joined!", MESSAGE_STATUS_CONSOLE_RED)
end
return true
end
if getGlobalStorageValue(p2d_config.storages[1]) == p2d_config.players.max then
setGlobalStorageValue(p2d_config.storages[1], getGlobalStorageValue(p2d_config.storages[1])+1)
removeTp()
doCreatureSetNoMove(cid,true)
doBroadcastMessage("[PUSH2DEATH EVENT] is now full [" .. getGlobalStorageValue(p2d_config.storages[1])-1 .. " players]! The event will soon start.")
for _, var in pairs(getPlayersInEvent()) do
--doCreatureSetNoMove(cid,true)
countdown(tempo)
doPlayerSendTextMessage(var, MESSAGE_EVENT_ADVANCE, "The event will start in " .. p2d_config.timeToStartEvent .. " seconds! Good luck!")
end
addEvent(Unfreeze, p2d_config.timeToStartEvent*1000)
end
end
return true
end]]></movevent>
<movevent type="StepIn" itemid="100" event="script"><![CDATA[
domodlib('p2d_config')
function onStepIn(cid, item, fromPosition, itemEx, toPosition)
if isPlayer(cid) and getPlayerAccess(cid) < p2d_config.access then
setPlayerStorageValue(cid, p2d_config.storage, 0)
doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
doPlayerSendTextMessage(cid,22,"[PUSH2DEATH EVENT] You lose, Good Luck to next time.")
getWinner()
end
return true
end
]]></movevent>
<globalevent name="P2D_Start" interval="30000" event="script"><![CDATA[
domodlib('p2d_config')
function onThink(interval, lastExecution)
if push2d_days[os.date("%A")] then
local hrs = tostring(os.date("%X")):sub(1, 5)
if isInArray(push2d_days[os.date("%A")], hrs) and getGlobalStorageValue(p2d_config.storages[2]) <= 0 then
local tp = doCreateItem(1387, 1, p2d_config.posTp)
doItemSetAttribute(tp, "aid", 47170)
CheckEvent(p2d_config.CheckTime)
setGlobalStorageValue(p2d_config.storages[1], 0)
setGlobalStorageValue(p2d_config.storages[2], 0)
end
end
return true
end]]></globalevent>
</mod>
Thanks
OTX 2.9 Based on 0.4
Last edited: