I was looking for a castle event in revscript and found this one, I didn't quite understand how it works can someone help me? the event starts the monsters spawn at the doors, but nothing happens when they die
script
lib
script
Lua:
local guilds = {}
local castlewar = CreatureEvent("CastleWar")
function castlewar.onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
local isGuild = false
local damage = primaryDamage + secondaryDamage
if attacker:isPlayer() == false then
if attacker:getMaster() == false then
return
end
attacker = attacker:getMaster()
end
if attacker:getGuild() == nil then
return
end
for k,v in pairs(guilds) do
if v[1] == attacker:getGuild():getId() then
v = {v[1], v[2] + damage}
isGuild = true
break
end
end
if not isGuild then
guilds[#guilds+1] = {attacker:getGuild():getId(), damage}
end
if creature:getHealth() - damage <= 0 then
table.sort(guilds, function(a,b) return a[2] > b[2] end)
db.query("CREATE TABLE IF NOT EXISTS `castle` (`guild_id` int(11) NOT NULL, guild_name varchar(255) NOT NULL) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;")
db.query("DELETE FROM `castle`")
if guilds[1][1] ~= nil then
local info = db.storeQuery("SELECT `name`, `ownerid` FROM `guilds` WHERE `id` = " .. guilds[1][1] .. " LIMIT 1")
local name = result.getString(info, "name")
local owner = result.getString(info, "ownerid")
db.query("INSERT INTO `castle` VALUES (".. guilds[1][1] ..", '".. name .."')")
broadcastMessage(woe.eventName.." has ended. Congratulations to ".. name .." for claiming ownership of the castle!", MESSAGE_EVENT_ADVANCE)
Tile(woe.castle):getHouse():setOwnerGuid(owner)
end
guilds = {}
for k,v in pairs(woe.doors) do
if Creature(v.name) ~= nil then
Creature(v.name):remove()
end
local door = Game.createItem(v.id, 1, v.pos)
door:setActionId(woe.actionid)
end
end
return primaryDamage, primaryType, -secondaryDamage, secondaryType
end
castlewar:register()
local castlewarglobal = GlobalEvent("CastleWarGlobal")
function castlewarglobal.onTime(interval)
if os.date("%H:%M") == woe.days[os.date("%A")] then
woe.queueEvent(woe.timeDelay+1)
end
end
castlewarglobal:time("18:00:00")
castlewarglobal:register()
local castlewartalk = TalkAction("!woe")
function castlewartalk.onSay(player, words, param)
if not player:getGroup():getAccess() then
return true
end
if player:getAccountType() < ACCOUNT_TYPE_GOD then
return false
end
woe.queueEvent(woe.timeDelay+1)
return false
end
castlewartalk:register()
lib
Lua:
woe = {
eventName = "[WOE]",
timeDelay = 1, -- minutes before event starts
bcMsg = " is starting in ",
doors = {
{name = "Castle Gate", id = 6257, pos = {x = 1021, y = 1028, z = 7} },
{name = "Castle Gate", id = 6257, pos = {x = 1022, y = 1028, z = 7} }
},
actionid = 33542, -- for the doors
crystal = {id = 9784, name="Emperium", pos = {x = 1022, y = 1020, z = 7} },
castle = {x = 1012, y = 1027, z = 7}, -- just has to be one of the housetiles of the castle
days = {
-- to enable a day for the globalevent do ["Weekday"] = time
-- for example: ["Monday"] = 18:00,
},
queueEvent = function(x)
x = x - 1
if x > 0 then
broadcastMessage(woe.eventName..woe.bcMsg..x..(x > 1 and "minutes!" or "minute!"), MESSAGE_EVENT_ADVANCE)
addEvent(woe.queueEvent, x * 60 * 1000, x)
else
woe.startEvent()
end
end,
startEvent = function()
for k,v in pairs(woe.doors) do
local item = Tile(v.pos):getItemById(v.id)
if item ~= nil then
item:remove()
Game.createMonster(v.name, v.pos, false, true)
else
print("WOE GATE POSITION INVALID OR MISSING [x:"..v.pos.x.." | y:"..v.pos.y.." | z:"..v.pos.z.."]")
end
end
local c = woe.crystal
local item = Tile(c.pos):getItemById(c.id)
if item ~= nil then
item:remove()
Game.createMonster(c.name, c.pos, false, true)
else
print("WOE CRYSTAL POSITION INVALID OR MISSING [x:"..c.pos.x.." | y:"..c.pos.y.." | z:"..c.pos.z.."]")
end
end,
}