"Zombie Event + Talkaction"
Créditos:
PhoOwned (criação do script)
GuizitoG (Tradução e explicação)
Em breve, imagens!

Importante
(testado em tfs 0.3) - Versão 8.6 (testes)
Bom, como o título já diz, venho aqui vos trazer, esse sistema Zombie Event, com uma inovação:
A função de realizar o evento a qualquer hora do dia (apenas por comandos in-game)
Mãos à obra:
» Instalando o Evento
Bom, o primeiro passo é instalar o evento:
Vá na pasta 'data/creaturescripts/scripts/' e crie uma pasta chamada zombie. Em seguida crie um arquivo chamado onattack.lua (dentro da pasta zombie). Coloque o seguinte conteúdo no 'onattack.lua':
function loseOnZombieArena(cid)
kickPlayerFromZombiesArea(cid)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "BOOM! You are dead.")
local players = getZombiesEventPlayers()
if(#players <= 1) then
local winner = players[1]
if(winner) then
doPlayerAddItem(winner, 2157, 5, true)
doPlayerAddItem(winner, 6119, 1, true)
doPlayerSendTextMessage(winner, MESSAGE_STATUS_CONSOLE_BLUE, "You won zombies arena event.")
doBroadcastMessage("After " .. os.time() - getPlayerZombiesEventStatus(winner) .. " seconds of fight " .. getCreatureName(winner) .. " won Zombie Arena Event in game versus " .. getStorage(ZE_ZOMBIES_SPAWNED) .. " zombies!")
kickPlayerFromZombiesArea(winner)
else
doBroadcastMessage("Zombie arena event finished! No one win?!?!?! WTF!")
end
doSetStorage(ZE_STATUS, 0)
doSetStorage(ZE_PLAYERS_NUMBER, ZE_DEFAULT_NUMBER_OF_PLAYERS)
doSetStorage(ZE_ZOMBIES_TO_SPAWN, 0)
doSetStorage(ZE_ZOMBIES_SPAWNED, 0)
local width = (math.max(ZE_spawnFromPosition.x, ZE_spawnToPosition.x) - math.min(ZE_spawnFromPosition.x, ZE_spawnToPosition.x)) / 2 + 1
local height = (math.max(ZE_spawnFromPosition.y, ZE_spawnToPosition.y) - math.min(ZE_spawnFromPosition.y, ZE_spawnToPosition.y)) / 2 + 1
local centerPos = {x=math.min(ZE_spawnFromPosition.x, ZE_spawnToPosition.x)+width,y=math.min(ZE_spawnFromPosition.y, ZE_spawnToPosition.y)+height,z=ZE_spawnFromPosition.z}
for z = math.min(ZE_spawnFromPosition.z, ZE_spawnToPosition.z), math.max(ZE_spawnFromPosition.z, ZE_spawnToPosition.z) do
centerPos.z = z
for i, uid in pairs(getSpectators(centerPos, width, height, false)) do
if(isMonster(uid)) then
doRemoveCreature(uid)
end
end
end
end
end
function onStatsChange(target, cid, changetype, combat, value)
if((cid and isMonster(cid) and getCreatureName(cid) == "Zombie Event") or (isInRange(getThingPosition(target), ZE_spawnFromPosition, ZE_spawnToPosition) and changetype == STATSCHANGE_HEALTHLOSS and math.abs(value) >= getCreatureHealth(target))) then
doCreatureAddHealth(target, getCreatureMaxHealth(target))
loseOnZombieArena(target)
return false
end
return true
end
(A mensagem em negrito é a mensagem que irá apareçer pro player quando ele morrer no evento)
Logo em seguida, crie um arquivo chamado ondeath.lua (na mesma pasta zombie) e coloque isso:
function onDeath(cid)
setZombiesToSpawnCount(getZombiesToSpawnCount() + 2)
doCreatureSay(cid, "I'll be back!", 19)
return true
end
(neste não mecha em nada)
E agora, na mesma pasta, crie um arquivo chamado onthink.lua Coloque o seguinte conteudo dentro:
function onThink(cid)
local target = getCreatureTarget(cid)
if(target ~= 0 and not isPlayer(target)) then
doRemoveCreature(target)
end
return true
end
(também não mecha em nada)
__+''+__
Agora em creaturescripts/scripts/login.lua adicione essa tagzinha:
registerCreatureEvent(cid, "ZombieAttack")
E logo após, adicione estas tags em creaturescripts.xml
<event type="think" name="ZombieThink" event="script" value="zombie/onthink.lua"/>
<event type="statschange" name="ZombieAttack" event="script" value="zombie/onattack.lua"/>
<event type="death" name="ZombieDeath" event="script" value="zombie/ondeath.lua"/>
Prontinho, agra va pra pasta globalevents e crie uma pasta chamada Zombie. Nela crie um arquivo chamado onthink.lua e coloque o seguinte conteudo:
function onThink(interval, lastExecution, thinkInterval)
if(getStorage(ZE_STATUS) == 2) then
setZombiesToSpawnCount(getZombiesToSpawnCount()+1)
local players = getZombiesEventPlayers()
for i=1, getZombiesToSpawnCount() * 2 do
if(getZombiesToSpawnCount() > 0 and spawnNewZombie()) then
setZombiesToSpawnCount(getZombiesToSpawnCount()-1)
end
end
end
return true
end
E em globalevents.xml adicione a tag:
<globalevent name="ZombieGlobalThink" interval="5" event="script" value="zombie/onthink.lua"/>
Agora, em data/lib crie um arquivo chamado zombie_event, e coloque isso dentro:
-- CONFIG
ZE_DEFAULT_NUMBER_OF_PLAYERS = 5
ZE_ACCESS_TO_IGNORE_ARENA = 1
-- POSITIONS
ZE_blockEnterItemPosition = {x= 163, y=56, z=8}
ZE_enterPosition = {x = 401, y = 163, z = 7}
ZE_kickPosition = {x=161, y=55, z=7}
ZE_spawnFromPosition = {x = 388, y = 155, z = 7}
ZE_spawnToPosition = {x = 409, y = 171, z = 7}
-- ITEM IDS
ZE_blockEnterItemID = 12344
-- STORAGES
-- - player
ZE_isOnZombieArea = 34370
-- - global
ZE_STATUS = 34370 -- =< 0 - off, 1 - waiting for players, 2 - is running
ZE_PLAYERS_NUMBER = 34371
ZE_ZOMBIES_TO_SPAWN = 34372
ZE_ZOMBIES_SPAWNED = 34373
-- FUNCTION
function setZombiesEventPlayersLimit(value)
doSetStorage(ZE_PLAYERS_NUMBER, value)
end
function getZombiesEventPlayersLimit()
return getStorage(ZE_PLAYERS_NUMBER)
end
function addPlayerToZombiesArea(cid)
doSendMagicEffect(getThingPosition(cid), CONST_ME_TELEPORT)
doTeleportThing(cid, ZE_enterPosition, true)
doSendMagicEffect(getThingPosition(cid), CONST_ME_TELEPORT)
if(getPlayerAccess(cid) < ZE_ACCESS_TO_IGNORE_ARENA) then
setPlayerZombiesEventStatus(cid, os.time())
end
end
function kickPlayerFromZombiesArea(cid)
doSendMagicEffect(getThingPosition(cid), CONST_ME_TELEPORT)
doTeleportThing(cid, ZE_kickPosition, true)
doSendMagicEffect(getThingPosition(cid), CONST_ME_TELEPORT)
setPlayerZombiesEventStatus(cid, 0)
end
function getPlayerZombiesEventStatus(cid)
return getCreatureStorage(cid, ZE_isOnZombieArea)
end
function setPlayerZombiesEventStatus(cid, value)
doCreatureSetStorage(cid, ZE_isOnZombieArea, value)
end
function getZombiesEventPlayers()
local players = {}
for i, cid in pairs(getPlayersOnline()) do
if(getPlayerZombiesEventStatus(cid) > 0) then
table.insert(players, cid)
end
end
return players
end
function getZombiesCount()
return getStorage(ZE_ZOMBIES_SPAWNED)
end
function addZombiesCount()
doSetStorage(ZE_ZOMBIES_SPAWNED, getStorage(ZE_ZOMBIES_SPAWNED)+1)
end
function resetZombiesCount()
doSetStorage(ZE_ZOMBIES_SPAWNED, 0)
end
function getZombiesToSpawnCount()
return getStorage(ZE_ZOMBIES_TO_SPAWN)
end
function setZombiesToSpawnCount(count)
doSetStorage(ZE_ZOMBIES_TO_SPAWN, count)
end
function addZombiesEventBlockEnterPosition()
if(getTileItemById(ZE_blockEnterItemPosition, ZE_blockEnterItemID).uid == 0) then
doCreateItem(ZE_blockEnterItemID, 1, ZE_blockEnterItemPosition)
end
end
function removeZombiesEventBlockEnterPosition()
local item = getTileItemById(ZE_blockEnterItemPosition, ZE_blockEnterItemID)
if(item.uid ~= 0) then
doRemoveItem(item.uid)
end
end
function spawnNewZombie()
local posx = {}
local posy = {}
local posz = {}
local pir = {}
for i=1, 5 do
local posx_tmp = math.random(ZE_spawnFromPosition.x ,ZE_spawnToPosition.x)
local posy_tmp = math.random(ZE_spawnFromPosition.y ,ZE_spawnToPosition.y)
local posz_tmp = math.random(ZE_spawnFromPosition.z ,ZE_spawnToPosition.z)
local pir_tmp = 0
local spec = getSpectators({x=posx_tmp, y=posy_tmp, z=posz_tmp}, 3, 3, false)
if(spec and #spec > 0) then
for z, pid in pairs(spec) do
if(isPlayer(pid)) then
pir_tmp = pir_tmp + 1
end
end
end
posx = posx_tmp
posy = posy_tmp
posz = posz_tmp
pir = pir_tmp
end
local lowest_i = 1
for i=2, 5 do
if(pir < pir[lowest_i]) then
lowest_i = i
end
end
local ret = (type(doCreateMonster("Zombie Event", {x=posx[lowest_i], y=posy[lowest_i], z=posz[lowest_i]}, false)) == 'number')
if(ret) then
addZombiesCount()
end
return ret
end
Explicação :><:
ZE_blockEnterItemPosition = {x= 163, y=56, z=8} << Isso é a posição do item que vai trapar o tp, pra que ninguem entre no evento antes do inicio, (coloque o tp num lugar fechado com um item.
ZE_enterPosition = {x = 401, y = 163, z = 7} << Essa é a posição que o jogador ira apareçer ao entrar no evento.
ZE_kickPosition = {x=161, y=55, z=7} << Posição pra onde o player vai quando perder o evento (templo).
ZE_spawnFromPosition = {x = 388, y = 155, z = 7} << Posição de area do spawn, da parte noroeste do mapa (</\)
ZE_spawnToPosition = {x = 409, y = 171, z = 7} << Posição de area do spawn, parde sudeste do mapa (\/>)
ZE_blockEnterItemID = 12344 << Esse é o id do item que vai trapar a entrada pro tp, no caso é uma pedra preta esse item,
aí no rme vc teria que colocar esse item na frente do tp.
_________________________
Agora va em movements/scripts, crie uma pasta chamada zombie e dentro crie um arquivo chamado onenter.lua
e adicione o conteudo dentro:
function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)
if(not isPlayer(cid)) then
return true
end
if(getPlayerAccess(cid) >= ZE_ACCESS_TO_IGNORE_ARENA) then
addPlayerToZombiesArea(cid)
elseif(#getZombiesEventPlayers() < getZombiesEventPlayersLimit() and getStorage(ZE_STATUS) == 1) then
addPlayerToZombiesArea(cid)
local players_on_arena_count = #getZombiesEventPlayers()
if(players_on_arena_count == getZombiesEventPlayersLimit()) then
addZombiesEventBlockEnterPosition()
doSetStorage(ZE_STATUS, 2)
doBroadcastMessage("Evento Zombie foi iniciado")
else
doBroadcastMessage(getCreatureName(cid) .. " entrou no evento, mas falta " .. getZombiesEventPlayersLimit() - players_on_arena_count .. " players pra que o evento se inicie.")
end
else
doTeleportThing(cid, fromPosition, true)
addZombiesEventBlockEnterPosition()
end
return true
end
depois adicione a tag em movements.xml:
<movevent type="StepIn" actionid="5555" event="script" value="zombie/onenter.lua"/>
Agora vai em talkactions, crie uma pasta chamada zombie e crie um arquivo chamado onsay.lua, nele coloque isso:
function onSay(cid, words, param, channel)
if(getStorage(ZE_STATUS) ~= 2) then
local players_on_arena_count = #getZombiesEventPlayers()
if(param == 'force') then
if(players_on_arena_count > 0) then
setZombiesEventPlayersLimit(players_on_arena_count )
addZombiesEventBlockEnterPosition()
doSetStorage(ZE_STATUS, 2)
doBroadcastMessage("Zombie Arena Event started.")
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Zombie event se iniciou!!")
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "O evento nao se iniciou por falta de players...")
end
else
if(param ~= '' and tonumber(param) > 0) then
setZombiesEventPlayersLimit(tonumber(param))
end
removeZombiesEventBlockEnterPosition()
doSetStorage(ZE_STATUS, 1)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Event started.")
doPlayerBroadcastMessage(cid, "O Zombie event foi iniciado, estamos ao aguardo de " .. getZombiesEventPlayersLimit() - players_on_arena_count .. " players para dar inicio.")
end
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "O Zombie Event ja esta em andamento.")
end
return true
end
e adicione a tag no talkactions.xml
<talkaction log="yes" words="/zombiestart" access="4" event="script" value="zombie/onsay.lua"/>
Agora crie o monstro: Em data/monsters/ crie um monstro chamado zombie_event.xml e coloque isso dentro:
<monster name="Zombie Event" nameDescription="an event zombie" race="undead" experience="480" speed="170" manacost="0">
<health now="200000000" max="200000000"/>
<look type="311" corpse="9875"/>
<targetchange interval="5000" chance="50"/>
<strategy attack="100" defense="0"/>
<flags>
<flag summonable="0"/>
<flag attackable="1"/>
<flag hostile="1"/>
<flag illusionable="0"/>
<flag convinceable="0"/>
<flag pushable="0"/>
<flag canpushitems="1"/>
<flag canpushcreatures="1"/>
<flag targetdistance="1"/>
<flag staticattack="90"/>
<flag runonhealth="0"/>
</flags>
<attacks>
<attack name="melee" interval="1000" min="-1500" max="-2350"/>
</attacks>
<defenses armor="0" defense="0"/>
<immunities>
<immunity paralyze="1"/>
<immunity invisible="1"/>
<immunity fire="1"/>
<immunity energy="1"/>
<immunity poison="1"/>
</immunities>
<voices interval="5000" chance="10">
<voice sentence="You wont last long!"/>
<voice sentence="Mmmmh.. braains!"/>
</voices>
<script>
<event name="ZombieThink"/>
<event name="ZombieDeath"/>
</script>
<loot>
</loot>
</monster>
e depois registre o monstro em monsters.xml:
<monster name="Zombie Event" file="zombie_event.xml"/>]
Finalizando:
No tp que voce vai colocar no evento, coloque actionid 5555.
Depois de ter feito tudo isso reinicie seu servidor e para dar inicio é simples:
/zombiestart pra iniciar, com o numero de players na frente, exemplo:
/zombiestart 15
Caso não tenha dado o numero total de players e voce desejar iniciar o evento basta dizer:
/zombiestart force
Bom, é isto...
Caso de algum bug avise!