Skip to content

Instantly share code, notes, and snippets.

@Xaekai
Last active April 15, 2020 23:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Xaekai/4765a75f76a4a4a07f4bbe1d468fcb13 to your computer and use it in GitHub Desktop.
Save Xaekai/4765a75f76a4a4a07f4bbe1d468fcb13 to your computer and use it in GitHub Desktop.
Some team battle event for TFS 0.x versions that support mods. Code heresies purged by inquisitor Lessaire.
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Rush Event" version="2.0.2.0" author="Lessaire" contact="https://otland.net/members/lessaire/" enabled="yes">
<credits>
This cleaned and refactored version is brought to you by Lessaire.
There is so much wrong with this still,
but since this crap is out in the wild may as well do what I can
All I know is the original authors, whoever they were, should feel ashamed.
Original Credits:
Maybe ChaitoSoft.com
Maybe GarQet
Maybe someone else
I dont fucking care, this script is 8 years old.
</credits>
<notes>
This revision attempts to register the creatureEvents in the buffered login script at the bottom.
If for whatever reason that doesn't work, you need to just move them to your regular login.lua.
</notes>
<description>
-------------------------------------------------------------------------------------------------
Configuration Guide:
announce - Event start announcement message
whyBother - Announcement of cancellation due to insufficient participants
winnerRed - Announcement that red team has won event
winnerBlue - Announcement that blue team has won event
posLobby - Position of Event Lobby where participants muster
posTeamRed - Position of Red Team temple/start
posTeamBlue - Position of Blue Team temple/start
minLevel - Minimum player level to participate
minAttend - Minimum attendance to start event
maxAttend - Maximum attendance of the arena
scoreWin - Number of frags to win battle
prizeItem - ItemID of reward
prizeAmount - Quantity of reward
preamble - Delay minutes between announcement and commencement
results - Delay minutes to publish results
-- Global Storages
scoreRed - Number of frags scored by Red team
scoreBlue - Number of frags scored by Blue team
stateSignup - EventState: registration open
stateBegun - EventState: has commenced and is underway (2 globals for event state? noob shit)
stateAttend - EventState: attendance
stateIndice - EventState: current registration indice (for team assigning, noob shit)
inArena - PlayerState: Sent to event grounds
registered - PlayerState: Registered for event || EventState: Winning kill
onTeamRed - PlayerState: On Team Red
onTeamBlue - PlayerState: On Team Blue
-------------------------------------------------------------------------------------------------
</description>
<config name="eventConfig"><![CDATA[
local eventName = "Rush Battle" -- Massive Team Battle Event
rushConfig = {
eventName = eventName,
announce = eventName .. " has been started! Have fun..",
whyBother = eventName .. " will not occur! Too few participants registered.",
winnerRed = eventName .. " is completed, Red Team has won!",
winnerBlue = eventName .. " is completed, Blue Team has won!",
posTeamRed = { x = 31504, y = 31652, z = 7 },
posTeamBlue = { x = 31434, y = 31586, z = 7 },
posLobby = { x = 31494, y = 31557, z = 7 },
minAttend = 1,
maxAttend = 500,
minLevel = 50,
scoreWin = 3,
prizeItem = 2160,
prizeAmount = 10,
preamble = 5,
results = 5,
stateSignup = 39145,
stateBegun = 39146,
stateAttend = 39147,
stateIndice = 39148,
inArena = 39149,
registered = 39150,
onTeamRed = 39151,
onTeamBlue = 39152,
scoreRed = 39153,
scoreBlue = 39154,
teamRed = "Red Team",
teamBlue = "Blue Team",
joinHow = "You can join this epic event by writing this command in a protection zone: !battle",
outfitLock = "You cannot change your outfit during the event.",
errorClose = "At the moment there are no records for this event.",
errorLow = "Your level is too low to participate in this event.",
errorHere = "You are already registered in this event.",
errorSafe = "You must be in protection zone.",
errorFull = "Event is full",
}
-- Lobby wait should be at least 2 minutes
rushConfig.preamble = math.max(2, rushConfig.preamble)
]]></config>
<lib name="RushUtils"><![CDATA[
function doPlayerRemoveDamagingConditions(cid)
local tmp = {1, 2, 4, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 32768, 65536}
for i = 1, #tmp do
if(hasCondition(cid, tmp[i])) then doRemoveCondition(cid, tmp[i]) end
end
return true
end
]]></config>
<globalevent name="Recognition" interval="30000" event="script"><![CDATA[
domodlib('eventConfig')
function onThink(interval, lastExecution, thinkInterval)
if(getGlobalStorageValue(rushConfig.stateSignup) == 1) then
for _, pid in ipairs(getPlayersOnline()) do
if getPlayerStorageValue(pid, rushConfig.registered) == 1 then
if(getPlayerStorageValue(pid, rushConfig.onTeamBlue) == 0) then
doSendAnimatedText(getCreaturePosition(pid), "RED TEAM", TEXTCOLOR_RED)
elseif(getPlayerStorageValue(pid, rushConfig.onTeamBlue) == 1) then
doSendAnimatedText(getCreaturePosition(pid), "BLUE TEAM", TEXTCOLOR_LIGHTBLUE)
end
end
end
return true
end
return true
end
]]></globalevent>
<talkaction words="!check" event="script"><![CDATA[
domodlib('eventConfig')
function onSay(cid, words, param, channel)
if getPlayerGroupId(cid) > 3 then
local red = getGlobalStorageValue(rushConfig.scoreRed)
local blue = getGlobalStorageValue(rushConfig.scoreBlue)
local nRed = rushConfig.teamRed
local nBlue = rushConfig.teamBlue
local limit = rushConfig.scoreWin
local message = ""
if blue < limit and red < limit then
message = string.format("%s: %s frags.\n%s: %s frags.\nMatch is under way to %s frags.", nRed, red, nBlue, blue, limit)
elseif blue >= limit then
message = string.format("%s scored %s/%s frags. %s should win.", nBlue, blue, limit, nBlue)
elseif red >= limit then
message = string.format("%s scored %s/%s frags. %s should win.", nRed, red, limit, nRed)
end
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, message)
return true
end
return true
end
]]></talkaction>
<talkaction words="!start" event="script"><![CDATA[
domodlib('eventConfig')
function onSay(cid, words, param, channel)
if getPlayerGroupId(cid) > 3 then
setGlobalStorageValue(rushConfig.stateIndice, 1)
setGlobalStorageValue(rushConfig.scoreBlue, 0)
setGlobalStorageValue(rushConfig.scoreRed, 0)
setGlobalStorageValue(rushConfig.stateSignup, 1)
setGlobalStorageValue(rushConfig.stateAttend, 0)
setGlobalStorageValue(rushConfig.stateBegun, 0)
local message = string.format("Attention! %s will start in %s minutes. %s", rushConfig.eventName, rushConfig.preamble, rushConfig.joinHow)
doBroadcastMessage(message, MESSAGE_STATUS_WARNING)
local function broadcaster( minutes )
if(minutes == 1) then
doBroadcastMessage(rushConfig.eventName .. ", starts in a minute. Last chance to join: !battle", MESSAGE_STATUS_WARNING)
return true;
end
doBroadcastMessage(rushConfig.eventName .. ", starts in " .. minutes .. rushConfig.joinHow, MESSAGE_STATUS_WARNING)
end
if(rushConfig.preamble > 5) then addEvent(broadcaster, (rushConfig.preamble - 4) * 1000 * 60, 4) end
if(rushConfig.preamble > 4) then addEvent(broadcaster, (rushConfig.preamble - 3) * 1000 * 60, 3) end
if(rushConfig.preamble > 3) then addEvent(broadcaster, (rushConfig.preamble - 2) * 1000 * 60, 2) end
if(rushConfig.preamble > 2) then addEvent(broadcaster, (rushConfig.preamble - 1) * 1000 * 60, 1) end
addEvent(start, rushConfig.preamble * 1000 * 60)
return true
end
return true
end
function results()
if(getGlobalStorageValue(rushConfig.stateSignup) == 1) then
local red = getGlobalStorageValue(rushConfig.scoreRed)
local blue = getGlobalStorageValue(rushConfig.scoreBlue)
doBroadcastMessage(rushConfig.eventName .. " results:\nRed Team scored: ".. red .." frags.\nBlue Team scored: ".. blue .." frags.\nMatch is under way to ".. rushConfig.scoreWin .." frags.", MESSAGE_STATUS_WARNING)
addEvent(results, rushConfig.results * 1000 * 60)
end
end
function start()
if(getGlobalStorageValue(rushConfig.stateSignup) == 1 and getGlobalStorageValue(rushConfig.stateAttend) >= rushConfig.minAttend) then
doBroadcastMessage(rushConfig.announce, MESSAGE_STATUS_WARNING)
setGlobalStorageValue(rushConfig.stateBegun, 1)
addEvent(results, rushConfig.results * 1000 * 60)
for _, pid in ipairs(getPlayersOnline()) do
local myOutfit = getCreatureOutfit(pid)
local red = {lookType = myOutfit.lookType, lookHead = 94, lookBody = 94, lookLegs = 94, lookFeet = 94, lookTypeEx = 0, lookAddons = myOutfit.lookAddons}
local blue = {lookType = myOutfit.lookType, lookHead = 86, lookBody = 86, lookLegs = 86, lookFeet = 86, lookTypeEx = 0, lookAddons = myOutfit.lookAddons}
if getPlayerStorageValue(pid, rushConfig.registered) == 1 then
doCreatureAddHealth(pid, getCreatureMaxHealth(pid))
doCreatureAddMana(pid, getCreatureMaxMana(pid))
if((getPlayerStorageValue(pid, rushConfig.stateIndice) % 2) == 1) then
doCreatureChangeOutfit(pid, red)
setPlayerStorageValue(pid, rushConfig.inArena, 1)
doTeleportThing(pid, rushConfig.posTeamRed)
setPlayerStorageValue(pid, rushConfig.registered, 1)
setPlayerStorageValue(pid, rushConfig.onTeamBlue, 0)
setPlayerStorageValue(pid, rushConfig.onTeamRed, 1)
doSendMagicEffect(getCreaturePosition(pid), 10)
doPlayerSendTextMessage(pid, MESSAGE_EVENT_ADVANCE, "You are in RED TEAM!\nThis battle will continue up to ".. rushConfig.scoreWin .." frags!")
else
doCreatureChangeOutfit(pid, blue)
doTeleportThing(pid, rushConfig.posTeamBlue)
setPlayerStorageValue(pid, rushConfig.inArena, 1)
setPlayerStorageValue(pid, rushConfig.registered, 1)
setPlayerStorageValue(pid, rushConfig.onTeamBlue, 1)
setPlayerStorageValue(pid, rushConfig.onTeamRed, 0)
doSendMagicEffect(getCreaturePosition(pid), 10)
doPlayerSendTextMessage(pid, MESSAGE_EVENT_ADVANCE, "You are in BLUE TEAM!\nThis battle will continue up to ".. rushConfig.scoreWin .." frags!")
end
end
end
elseif(getGlobalStorageValue(rushConfig.stateAttend) < rushConfig.minAttend) then
doBroadcastMessage(rushConfig.whyBother, MESSAGE_STATUS_WARNING)
setGlobalStorageValue(rushConfig.stateSignup, -1)
for _, pid in ipairs(getPlayersOnline()) do
if getPlayerStorageValue(pid, rushConfig.registered) == 1 then
setPlayerStorageValue(pid, rushConfig.registered, -1)
doTeleportThing(pid, getTownTemplePosition(getPlayerTown(pid)))
doSendMagicEffect(getCreaturePosition(pid), CONST_ME_TELEPORT)
end
end
end
end
]]></talkaction>
<talkaction words="!battle" event="script"><![CDATA[
domodlib('eventConfig')
function onSay(cid, words, param, channel)
if not (getGlobalStorageValue(rushConfig.stateSignup) == 1 and getGlobalStorageValue(rushConfig.stateBegun) ~= 1) then
doPlayerSendCancel(cid, rushConfig.errorClose)
return true
end
if getPlayerLevel(cid) < rushConfig.minLevel then
doPlayerSendCancel(cid, rushConfig.errorLow)
return true
end
if not (getPlayerStorageValue(cid, rushConfig.registered) == -1) then
doPlayerSendCancel(cid, rushConfig.errorHere)
return true
end
if getTilePzInfo(getPlayerPosition(cid)) ~= true then
doPlayerSendCancel(cid, rushConfig.errorSafe)
return true
end
if getGlobalStorageValue(rushConfig.stateAttend) >= rushConfig.maxAttend then
doPlayerSendCancel(cid, rushConfig.errorFull .. " [" .. getGlobalStorageValue(rushConfig.stateAttend) .. " players]!")
return true
end
setGlobalStorageValue(rushConfig.stateAttend, getGlobalStorageValue(rushConfig.stateAttend)+1)
if getGlobalStorageValue(rushConfig.stateAttend) == rushConfig.maxAttend then
doPlayerSendCancel(cid, rushConfig.errorFull .. " [" .. getGlobalStorageValue(rushConfig.stateAttend) .. " players]!")
else
doBroadcastMessage("" .. getPlayerName(cid) .. " has joined to the " .. rushConfig.eventName .. "! Now, we have: " .. getGlobalStorageValue(rushConfig.stateAttend) .. " players!", 19)
end
setPlayerStorageValue(cid, rushConfig.registered, 1)
setPlayerStorageValue(cid, rushConfig.inArena, -1)
doTeleportThing(cid, rushConfig.posLobby)
doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
setPlayerStorageValue(cid, rushConfig.stateIndice, getGlobalStorageValue(rushConfig.stateIndice))
setGlobalStorageValue(rushConfig.stateIndice, tonumber(getGlobalStorageValue(rushConfig.stateIndice))+1)
return true
end
]]></talkaction>
<event type="combat" name="RushCombat" event="script"><![CDATA[
domodlib('eventConfig')
function onCombat(cid, target)
if(getGlobalStorageValue(rushConfig.stateSignup) == 1) then
if isPlayer(cid) and isPlayer(target) then
if getPlayerStorageValue(cid, rushConfig.registered) == 1 and getPlayerStorageValue(target, rushConfig.registered) == 1 then
if getPlayerStorageValue(cid, rushConfig.onTeamBlue) == getPlayerStorageValue(target, rushConfig.onTeamBlue) then
return doPlayerSendCancel(cid, "Sorry, you may not attack your teammates.") and false
end
end
end
end
return true
end
]]></event>
<event type="attack" name="RushAttack" event="script"><![CDATA[
domodlib('eventConfig')
function onAttack(cid, target)
if(getGlobalStorageValue(rushConfig.stateSignup) == 1) then
if isPlayer(cid) and isPlayer(target) then
if getPlayerStorageValue(cid, rushConfig.registered) == 1 and getPlayerStorageValue(target, rushConfig.registered) == 1 then
if getPlayerStorageValue(cid, rushConfig.onTeamBlue) == getPlayerStorageValue(target, rushConfig.onTeamBlue) then
return doPlayerSendCancel(cid, "Sorry, you may not attack your teammates.") and false
end
end
end
end
return true
end
]]></event>
<event type="preparedeath" name="RushDead" event="script"><![CDATA[
domodlib('eventConfig')
domodlib('RushUtils')
function onPrepareDeath(cid, deathList)
if(not isPlayer(cid)) then
return true
end
if getPlayerStorageValue(cid, rushConfig.registered) == -1 then
return true
end
if getGlobalStorageValue(rushConfig.stateSignup) == 1 then
local strings = {""}
local j, position, corpse = 1, 1, 0
for _, pid in ipairs(deathList) do
if isCreature(pid) == true then
strings[position] = j == 1 and "" or strings[position] .. ", "
strings[position] = strings[position] .. getCreatureName(pid) .. ""
j = j + 1
else
strings[position] = j == 1 and "" or strings[position] .. ", "
strings[position] = strings[position] .."a field item"
j = j + 1
end
end
local sex = (getPlayerSex(cid) == 0 and "She" or "He")
for i, str in ipairs(strings) do
if(str:sub(str:len()) ~= ",") then
str = str .. "."
end
desc = "You recognize "
desc = desc .. "" .. getCreatureName(cid) .. ". " .. sex .. " was killed by " .. str
end
if(getPlayerSex(cid) == 1) then
corpse = doCreateItem(3058, getCreaturePosition(cid))
else
corpse = doCreateItem(3065, getCreaturePosition(cid))
end
doItemSetAttribute(corpse, "description", desc)
if((getPlayerStorageValue(cid, rushConfig.stateIndice) % 2) == 1) then
setGlobalStorageValue(rushConfig.scoreBlue, getGlobalStorageValue(rushConfig.scoreBlue)+1)
else
setGlobalStorageValue(rushConfig.scoreRed, getGlobalStorageValue(rushConfig.scoreRed)+1)
end
local red = getGlobalStorageValue(rushConfig.scoreRed)
local blue = getGlobalStorageValue(rushConfig.scoreBlue)
local victoryRed = red >= rushConfig.scoreWin
local victoryBlue = blue >= rushConfig.scoreWin
local winner = victoryBlue or victoryRed
if (not winner) then
if((getPlayerStorageValue(cid, rushConfig.stateIndice) % 2) == 1) then
doTeleportThing(cid, rushConfig.posTeamRed)
doSendMagicEffect(getCreaturePosition(cid), 10)
doCreatureAddHealth(cid, getCreatureMaxHealth(cid), MAGIC_EFFECT_UNKNOWN, COLOR_UNKNOWN, true)
doCreatureAddMana(cid, getCreatureMaxMana(cid))
doPlayerRemoveDamagingConditions(cid)
if getCreatureSkullType(cid) == SKULL_WHITE then
doCreatureSetSkullType(cid, 0)
end
else
doTeleportThing(cid, rushConfig.posTeamBlue)
doSendMagicEffect(getCreaturePosition(cid), 10)
doCreatureAddHealth(cid, getCreatureMaxHealth(cid), MAGIC_EFFECT_UNKNOWN, COLOR_UNKNOWN, true)
doCreatureAddMana(cid, getCreatureMaxMana(cid))
doPlayerRemoveDamagingConditions(cid)
if getCreatureSkullType(cid) == SKULL_WHITE then
doCreatureSetSkullType(cid, 0)
end
end
else
local message = victoryBlue and rushConfig.winnerBlue or rushConfig.winnerRed
local team = victoryBlue and rushConfig.onTeamBlue or rushConfig.onTeamRed
doBroadcastMessage(message, MESSAGE_STATUS_WARNING)
for _, pid in ipairs(getPlayersOnline()) do
if(getPlayerStorageValue(pid, team) == 1) then
doPlayerAddItem(pid, rushConfig.prizeItem, rushConfig.prizeAmount)
end
end
end
-- With this kill, a team won
if winner then
setGlobalStorageValue(rushConfig.stateSignup, -1)
setGlobalStorageValue(rushConfig.stateBegun, -1)
local function decampPlayer(cid)
setPlayerStorageValue(cid, rushConfig.inArena, -1)
setPlayerStorageValue(cid, rushConfig.onTeamBlue, -1)
setPlayerStorageValue(cid, rushConfig.onTeamRed, -1)
setPlayerStorageValue(cid, rushConfig.registered, -1)
setPlayerStorageValue(cid, rushConfig.stateIndice, -1)
doCreatureAddHealth(cid, getCreatureMaxHealth(cid), MAGIC_EFFECT_UNKNOWN, COLOR_UNKNOWN, true)
doCreatureAddMana(cid, getCreatureMaxMana(cid))
doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)), true)
doPlayerRemoveDamagingConditions(cid)
end
decampPlayer(cid)
for _, pid in ipairs(getPlayersOnline()) do
if(getPlayerStorageValue(pid, rushConfig.registered) == 1) then decampPlayer(pid) end
end
return false
end
return false
end
return true
end
]]></event>
<event type="outfit" name="RushOutfit" event="script"><![CDATA[
domodlib('eventConfig')
function onOutfit(cid, old, current)
if getPlayerGroupId(cid) > 3 then
return true
end
if(getGlobalStorageValue(rushConfig.stateSignup) == 1) then
if getPlayerStorageValue(cid, rushConfig.inArena) == 1 then
if getPlayerStorageValue(cid, rushConfig.registered) > -1 then
doPlayerSendCancel(cid, rushConfig.outfitLock)
return false
end
end
end
return true
end
]]></event>
<event type="login" name="RushReset" event="buffer"><![CDATA[
domodlib('eventConfig')
-- Just in case anything strange happens, clean up player storage
setPlayerStorageValue(cid, rushConfig.inArena, -1)
setPlayerStorageValue(cid, rushConfig.onTeamBlue, -1)
setPlayerStorageValue(cid, rushConfig.onTeamRed, -1)
setPlayerStorageValue(cid, rushConfig.registered, -1)
setPlayerStorageValue(cid, rushConfig.stateIndice, -1)
-- This should work since this chunk is on the bottom of the file
registerCreatureEvent(cid, "RushCombat")
registerCreatureEvent(cid, "RushAttack")
registerCreatureEvent(cid, "RushDead")
registerCreatureEvent(cid, "RushOutfit")
_result = true
]]></event>
</mod>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment