Skip to content

Instantly share code, notes, and snippets.

@zach2good
Created July 20, 2021 19:24
Show Gist options
  • Save zach2good/d96a8d626b4dad8d53cfdde5a554b427 to your computer and use it in GitHub Desktop.
Save zach2good/d96a8d626b4dad8d53cfdde5a554b427 to your computer and use it in GitHub Desktop.
campaign_battle.lua
-----------------------------------
-- Campaign Battle global (Grauberg [S])
-----------------------------------
xi = xi or {}
xi.campaignBattle = xi.campaignBattle or {}
local startPos = {
x = 799.256,
y = 72.21,
z = 748.53,
}
-- !gotoid 17142367
local fortificationId = 17142367
-- !gotoid 17142229
local mobIds = {
17142229, -- NM
17142230,
17142231,
17142232,
17142233,
17142234,
17142235,
17142236,
17142237,
17142238,
}
-- CLuaBaseEntity(TYPE_NPC | 17142501 | Polished_Fang_LC)
-- TODO:
-- - A way to generate long paths between two arbitrary points on a map
-- - A way to assign those paths to mobs at runtime, from scripting
-- Before a battle starts
--xi.campaignBattle.zones[xi.zone.GRAUBERG_S] = nil
--
--local state = {
-- allyStrength = 100,
-- enemyStrength = 100,
-- phase = 0,
--}
-- When a battle starts
--xi.campaignBattle.zones[xi.zone.GRAUBERG_S] = {}
--xi.campaignBattle.zones[xi.zone.GRAUBERG_S].state = {} -- State object
--xi.campaignBattle.zones[xi.zone.GRAUBERG_S].mobs = {} -- list of mob Ids
--xi.campaignBattle.zones[xi.zone.GRAUBERG_S].fortifications = {} -- list of fortification Ids
--xi.campaignBattle.zones[xi.zone.GRAUBERG_S].npcs = {} -- list of npcs Ids
-- Spawn NPCS
-- Make sure fortifications are sane
-- Spawn Mobs
-- Start mobs pathing
xi.campaignBattle.count = 0
local tick
tick = function()
local npc = GetNPCByID(17142501)
local tickEnabled = npc:getLocalVar("TickEnabled")
xi.campaignBattle.count = xi.campaignBattle.count + 1
--if xi.campaignBattle.count > 5 then
-- xi.campaignBattle.count = 0
-- xi.campaignBattle.stop()
--end
if tickEnabled == 1 then
npc:timer(1000, function()
tick()
end)
end
end
xi.campaignBattle.start = function(player)
player:setPos(startPos.x, startPos.y, startPos.z)
local npc = GetNPCByID(17142501)
npc:setLocalVar("TickEnabled", 1)
print("Spawning Fort")
local fortification = GetMobByID(fortificationId)
fortification:setAllegiance(2) -- Player
SpawnMob(fortificationId)
print("Spawning Mobs")
for idx, mobId in ipairs(mobIds) do
local mob = GetMobByID(mobId)
SpawnMob(mobId)
mob:setPos(startPos.x + math.random(-2.0, 2.0), startPos.y, startPos.z + math.random(-2.0, 2.0))
mob:updateEnmity(fortification)
print(mob:getName())
mob:engage(fortification:getID())
end
tick()
end
xi.campaignBattle.stop = function(player)
local npc = GetNPCByID(17142501)
npc:setLocalVar("TickEnabled", 0)
DespawnMob(fortificationId)
for idx, mobId in ipairs(mobIds) do
DespawnMob(mobId)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment