• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua Private city war system TFS 0.4

Axelor

Member
Joined
Sep 2, 2010
Messages
505
Reaction score
9
Does anyone still have the private city war system, also known as war anti-entrosa for TFS 0.4 ?

Would be nice if someone could share or want to sell :)
 
I had a Brazil server with that script I am not sure if it gonna work but I will post it for you to test, it was based on TFS 0.4 too.
on data/creaturescripts add this line to creaturescripts.xml
XML:
<event type="logout" name="entrosaLogout" event="script" value="warEntrosaLogout.lua"/>
then on data/creaturescripts/scripts make a LUA script with name warEntrosaLogout.lua and add this to it
Lua:
function onLogout(cid)
    if getPlayerStorageValue(cid, 888123) > os.time() then
        doPlayerSendCancel(cid, "Vc n pode logar enquanto esta em war! Espere "..getPlayerStorageValue(cid, 888123) - os.time().." segundos.")
        return false
    end
    return true
end
now on data/talkactions add this line to talkactions.xml
XML:
<talkaction log="yes" words="!war" event="script" value="warEntrosa.lua"/>
then on data/talkactions/scripts make a LUA script with name warEntrosa.lua and add this to it
Lua:
local arena_storage = 454523
local players_storage = 456512
local storage_accept = 151230
local storage_check = 153201
local guild_invite = 542351
local guild_accept = 456121
local time_1_pos = {x = 26366, y = 31962, z = 6}
local time_2_pos = {x = 26484, y = 31957, z = 6}
local city = "Carlin"

local function getOnlineGuildMembersByRank(guildId, rank, selectLowerRanks) -- Funcao feita pelo Omega
    if not rank then
        rank = 3
        selectLowerRanks = true
    end
    local list = {}
    for _, pid in pairs(getPlayersOnline()) do
        if getPlayerGuildId(pid) == guildId then
            local playerRank = getPlayerGuildLevel(pid)
            if playerRank == rank or (selectLowerRanks and playerRank <= rank) then
                table.insert(list, pid)
            end
        end
    end
    return list
end

function onSay(cid, words, param, channel)
    if param == "" then
        doPlayerSendCancel(cid, "Use os parametros corretos.")
        return true
    end
   
    local t = string.explode(param, ",")
   
    if words == "!war"..city.." invite," then
       
        if getPlayerGuildLevel(cid) < 3 then
            doPlayerSendCancel(cid, "Somente liders de guild podem usar esse comando.")
            return true
        end
       
        if getGuildId(t[2]) and getGuildId(t[2]) ~= getPlayerGuildId(cid) then
            if #getOnlineGuildMembersByRank(getGuildId(t[2]), 3, false) > 0 then
                if getGlobalStorageValue(arena_storage) <= os.time() then
                    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Voce convidou a guild "..t[2].." para uma war em "..city.."!")
                    for _, gid in pairs(getOnlineGuildMembersByRank(getGuildId(t[2]), 3, false)) do
                        doPlayerSendTextMessage(gid, MESSAGE_STATUS_CONSOLE_ORANGE, getCreatureName(cid).." da guild "..getPlayerGuildName(cid).." chamou sua guild para uma war em "..city.." Para aceitar diga /war"..city.." accept, "..getPlayerGuildName(cid)..".")
                        setPlayerStorageValue(gid, storage_accept, os.time() + 20*60)
                        setPlayerStorageValue(gid, storage_check, getPlayerGuildId(cid))
                    end
                else
                    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "A arena ja esta ocupada.")
                end
            else
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Nenhum lider da guild "..t[2].." esta online.")
            end
        else
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Essa guild nao existe.")
        end
   
   
    elseif "!war"..city.." accept," then
        if getPlayerGuildLevel(cid) < 3 then
            doPlayerSendCancel(cid, "Somente liders de guild podem usar esse comando.")
            return true
        end
        if getGuildId(t[2]) and getGuildId(t[2]) ~= getPlayerGuildId(cid) then
            if getPlayerStorageValue(cid, storage_accept) > os.time() then
                if getPlayerStorageValue(cid, storage_check) == getGuildId(t[2]) then
                    setGlobalStorageValue(arena_storage, os.time() + 3600)
                    setGlobalStorageValue(guild_accept, getPlayerGuildId(cid))
                    setGlobalStorageValue(guild_invite, getGuildId(t[2]))
                    if #getOnlineGuildMembersByRank(getGuildId(t[2]), 3, true) > 0 then
                        for _, gid in pairs(getOnlineGuildMembersByRank(getGuildId(t[2]), 3, true)) do
                        doPlayerSendTextMessage(gid, MESSAGE_STATUS_CONSOLE_BLUE, "Sua guild entrou em war contra a guild "..getPlayerGuildName(cid).."! Para participar diga /war"..city.." go")
                        end
                    end
                    if #getOnlineGuildMembersByRank(getPlayerGuildId(cid), 3, true) > 0 then
                        for _, pid in pairs(getOnlineGuildMembersByRank(getPlayerGuildId(cid), 3, true)) do
                            doPlayerSendTextMessage(pid, MESSAGE_STATUS_CONSOLE_BLUE, "Sua guild entrou em war contra a guild "..t[2].."! Para participar diga /war"..city.." go")
                        end
                    end
                    addEvent(function()
                        for _, pid in pairs(getPlayersOnline()) do
                            if isInArea(getThingPos(pid), {x = 26357, y = 31906, z = 3}, {x = 26507, y = 32030, z = 3}) or isInArea(getThingPos(pid), {x = 26357, y = 31906, z = 4}, {x = 26507, y = 32030, z = 4}) or isInArea(getThingPos(pid), {x = 26357, y = 31906, z = 5}, {x = 26507, y = 32030, z = 5}) or isInArea(getThingPos(pid), {x = 26357, y = 31906, z = 6}, {x = 26507, y = 32030, z = 6}) or isInArea(getThingPos(pid), {x = 26357, y = 31906, z = 7}, {x = 26507, y = 32030, z = 7}) or isInArea(getThingPos(pid), {x = 26357, y = 31906, z = 8}, {x = 26507, y = 32030, z = 8}) or isInArea(getThingPos(pid), {x = 26357, y = 31906, z = 9}, {x = 26507, y = 32030, z = 9}) then
                                doTeleportThing(pid, getTownTemplePosition(getPlayerTown(cid)))
                                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Voce foi teleportado para o templo pq o tempo de war acabou")
                            end
                        end
                    end, 1000*3600)
                    addEvent(setGlobalStorageValue, 3600*1000, guild_accept, -1)
                    addEvent(setGlobalStorageValue, 3600*1000, guild_invite, -1)
                else
                    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Essa guild nao te invitou para uma war.")
                end
            else
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Sua guild n foi chamada para nenhuma war.")
            end
        else
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Essa guild nao existe.")
        end
    elseif "!war"..city.." go" then
        if getTilePzInfo(getThingPos(cid)) == false then
            doPlayerSendCancel(cid, "Vc precisa estar na pz")
            return true
        end
        if getGlobalStorageValue(guild_invite) == getPlayerGuildId(cid) or getGlobalStorageValue(guild_accept) == getPlayerGuildId(cid) then
            doPlayerSetStorageValue(cid, 888123, os.time() + getGlobalStorageValue(arena_storage))
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Voce entrou na war!")
            if getGlobalStorageValue(guild_invite) == getPlayerGuildId(cid) then
                doTeleportThing(cid, time_1_pos)
            else
                doTeleportThing(cid, time_2_pos)
            end
        else
            doPlayerSendCancel(cid, "Sua guild nao esta em war")
        end
    end
    return true
end
Then now on data/talkactions/lib make a LUA file and name it WAR.lua then add this to it
Lua:
War = {
   
    numero = { 0, 10, 15, 20, 30, 40 },    -- quantidade de jogadores (0=infinito)
    tempo = { quinze_min = 15,          trinta_min = 30,            sessenta_min = 60 },            --    colocar o nome das variaveis iguais
    preco = { quinze_min = 75000,      trinta_min = 100000,     sessenta_min = 150000},        --  caso fizer alguma alteração
   
    modo = { tradicional = 1, semUe = 2, soSd = 3},
    modo_string = {
                    [1] = {'tradicional', 'padrao', 'normal', '1'},
                    [2] = {'sem ue', 'semue', 'semUe', '2'},
                    [3] = {'apenas sd', 'só sd', 'so sd' , 'soh sd', '3'}
    },  
   
    --[[      
            você pode colocar quantos mapas quiser de uma mesma cidade      
            na tabela referente ao mapa, cada vetor da matriz é composto da Posição do Time A e do B
           
            exemplo:          
            [0] = { {posA, posB}, {posA2, posB2}, {posA3, posA4}  }    -- aqui vc tem 3 mapas configurado para Edron
                       
            posA = local da cidade em que os jogadores da guild A será teleportados
            posB = local para a guild B
           
            você é livre para escolher quais e quantas copias da cidade
           
            preste atenção! o valor da string e da position deve ser o mesmo!
]]
   
    cidade_string = {
                          [0] = {'edron', "Edron", 'EDRON'},
                --[[      [1] = {'dara', 'darashia', 'Darashia', 'DARASHIA'},
                          [2] = {'lb', 'liberty bay', 'Liberty Bay', 'LIBERTY BAY'},
                          [3] = {'carlin', 'Carlin', 'CARLIN'},
                          [4] = {'cormaya', 'Cormaya', 'CORMAYA'},
                          [5] = {'ank', 'ankrahmun', 'Ankrahmun', 'ANKRAHMUN'},
                          [6] = {'yalahar', 'Yalahar', 'YALAHAR'},
                          [7] = {'venore', 'Venore', 'VENORE'}    ]]
    },
    mapas = {  
                          [0] = {     {{x=1178,y=636,z=7},{x=1178,y=692,z=7}}     },        -- exemplo de apenas um mapa Edron configurado
                          [1] = {},
                          [2] = {},
                          [3] = {},
                          [4] = {},
                          [5] = {},
                          [6] = {},
                          [7] = {}  
    },
}

for city, v in pairs(War.mapas) do
    for _, mapa in pairs(v) do
        Instances(city, mapa)
    end
end

Wars = {}

function War:new(id, param)
   
     return setmetatable({
   
            -- config
            id = id,
            desafiante = param.desafiante,
            aceito = false,
            numero_jogadores = param.numero,
            modo = param.modo,
            tempo = param.tempo,
            instanceid = param.instanceid,
            valor = param.valor,
            positions = {[param.guildA] = param.positionA, [param.guildB] = param.positionB},
           
            -- uso real
            players = {[param.guildA] = {}, [param.guildB] = {}},
            frags = {[param.guildA] = 0, [param.guildB] = 0},
            name = {}
           
           
     }, { __index = self }), addEvent(function (id, param)
                                                    if Wars[id] and Wars[id].aceito == false then
                                                        doPlayerDepositMoney(self.desafiante, valor)
                                                        Wars[id]:broadcastToGuilds(22, "O convite nao foi aceito.")
                                                        Wars[id] = false
                                                        Instances[param.instanceid]:unregister()
                                                    end
                                                end, 5 * 60 * 1000, id, param)
end

setmetatable(Wars, { __call =     function(self, param)
                                        local id = #Wars+1
                                        Instances[param.instanceid]:register()
                                        param.positionA = Instances[param.instanceid].posA
                                        param.positionB = Instances[param.instanceid].posB
                                       
                                        Wars[id] = War:new(id, param)
                                       
                                        Wars[id].name = {{param.guildA, param.nomeA}, {param.guildB, param.nomeB}}
                                       
                                        local text = "[City War] "..param.nomeA .. " invitou a guild " .. param.nomeB .. " para uma war!\n"
                                        text = text .. "A war sera na cidade " .. War.cidade_string[param.cidade][1]
                                        if (param.numero == 0) then                                      
                                            text = text .. " sem limite de jogadores para cada time"
                                        else
                                            text = text .. " com no maximo " .. param.numero .. " jogadores para cada time"
                                        end                                                                              
                                        text = text .. " por " .. param.tempo .. " minutos"
                                        text = text .. " no modo " .. War.modo_string[param.modo][1]
                                        text = text .. "\nO lider da guild " .. param.nomeB .. " tem cinco minutos para aceitar o convite. Digite: /citywar accept, " .. param.nomeA
                                       
                                        Wars[id]:broadcastToGuilds(22, text)
                                end })
                                                               
                               
function War:start()
    self.aceito = true  
    self:broadcastToGuilds(22, "[City War] A War entre " .. self.name[1][2] .. " e " .. self.name[2][2] .. "  foi iniciada! Para entrar digite: /citywar go" )
   
    addEvent(War.broadcast, (self.tempo * 60 * 1000) - (5 * 60 * 1000), self, 22, "[City War] Faltam 5 minutos para a War acabar.")
    addEvent(War.broadcast, (self.tempo * 60 * 1000) - (3 * 60 * 1000), self, 22, "[City War] Faltam 3 minutos para a War acabar.")
    addEvent(War.broadcast, (self.tempo * 60 * 1000) - (1 * 60 * 1000), self, 22, "[City War] Falta 1 minuto para a War acabar.")
    addEvent(War.finish, self.tempo * 60 * 1000, self)
end

function War:finish()
   
    local text = "A war entre as guilds " .. self.name[1][2] .. " e " .. self.name[2][2] .. " acabou!\n"
    text = text .. self:getPlacarString()
    self:broadcastToGuilds(22, text)
   
    for guild, teams in pairs(self.players) do
        for k, cid in pairs(teams) do
            if type(cid) == 'number' and isPlayer(cid) then
                local pos = getTownTemplePosition(getPlayerTown(cid))          
                doTeleportThing(cid, pos)          
               
                setPlayerWarType(cid, 0)
                unregisterCreatureEvent(cid, "morte")  
               
                doRemoveCondition(cid, CONDITION_INFIGHT)
                if getCreatureSkullType(cid) == SKULL_WHITE then
                    doCreatureSetSkullType(cid, 0)
                end
               
                self.players[guild][k] = nil
            end
        end
    end  
    Instances[self.instanceid]:unregister()
   
    db.executeQuery("INSERT INTO [ICODE]city_war[/ICODE] ([ICODE]frags_guild1[/ICODE], [ICODE]frags_guild2[/ICODE], [ICODE]guild1[/ICODE], [ICODE]guild2[/ICODE], [ICODE]tempo[/ICODE], [ICODE]modo[/ICODE]) VALUES ('" .. self.frags[self.name[1][1]] .. "', '" .. self.frags[self.name[2][1]] .. "', '" .. self.name[1][2] .. "', '" .. self.name[2][2] .. "', '" .. self.tempo .. "', '" .. self.modo .. "' );")
    Wars[self.id] = true
end

local condition_infight = createConditionObject(CONDITION_INFIGHT, -1)

function War:newPlayer(cid)
    if self.aceito == false then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The war was not accepted yet.")
        return true
    end

    local guildId = getPlayerGuildId(cid)
        if (self.numero_jogadores == 0 or table.elements(self.players[guildId]) < self.numero_jogadores) then
            doTeleportThing(cid, self.positions[guildId])
            table.insert(self.players[guildId], cid)
        else
            return false
        end
    doAddCondition(cid, condition_infight)
    setPlayerWarType(cid, self.modo)
    registerCreatureEvent(cid, "citywar")
    return true
end

function War:removePlayer(cid)
    --town = getPlayerTown(cid)
    --pos = getTownTemplePosition(town)      
           
    --doTeleportThing(cid, pos)
   
    setPlayerWarType(cid, 0)  
    unregisterCreatureEvent(cid, "citywar")

    tmp = false
    for guild, teams in pairs(self.players) do
        for k, v in pairs(teams) do
            if v == cid then
                self.players[guild][k] = nil
                tmp = true
                break
            end
        end
        if tmp == true then
            break
        end
    end
    doRemoveCondition(cid, CONDITION_INFIGHT)
    if getCreatureSkullType(cid) == SKULL_WHITE then
        doCreatureSetSkullType(cid, 0)
    end
end

function War:isGuildOnWar(guildId)
    if self.name[1][1] == guildId or self.name[2][1] == guildId then
        return true  
    end
        return false
end

function War:kill(killer, cid)
    if (isPlayer(killer) or (isMonster(killer) and getCreatureMaster(killer))) then
        killer = isPlayer(killer) and killer or getCreatureMaster(killer)
        if getPlayerGuildId(killer) ~= getPlayerGuildId(cid) then
            self.frags[getPlayerGuildId(killer)] = self.frags[getPlayerGuildId(killer)] + 1
            self:broadcast(22, "[City War] \n".. getPlayerName(killer) .. " matou " .. getPlayerName(cid) .. ".\n" .. self:getPlacarString())
        end
    end
end

function War:getPlacarString()
    local text = "Placar: " .. self.name[1][2] .. " " .. self.frags[self.name[1][1]] .. " x "
    text = text .. self.frags[self.name[2][1]] .. " " .. self.name[2][2].."."  
    return text
end

function War:broadcast(messagetype, text)
    for k, v in pairs(self.players) do
        for _, cid in pairs(v) do
            if isPlayer(cid) then
                doPlayerSendTextMessage(cid, messagetype, text)
            end
        end
    end
end

function War:broadcastToGuilds(messagetype, text)
    local guilds = {self.name[1][1], self.name[2][1]}
    local isinarray, sendmessage, getguildid = isInArray, doPlayerSendTextMessage, getPlayerGuildId
   
    for k, v in pairs(getPlayersOnline()) do
        if isinarray(guilds, getguildid(v)) then
            sendmessage(v, messagetype, text)
        end
    end
end

-- função static, callback entre creaturescripts e o evento
function War.morte(cid, killer)
    for k,v in pairs(Wars) do
        if type(v) == 'table' then
            if v:isGuildOnWar(getPlayerGuildId(cid)) then
                v:kill(killer, cid)
                v:removePlayer(cid)
            end
        end
    end
    return true
end
That should work for Carlin, You will have maybe to change XYZ If you use different map and also you'll have to translate Brazil words to English to suit your server.
And if you want to add more cities just copy the talkactions file and change XYZ/name for the other city you want.
if it didn't then that Brazil server I had made some specific source edits along with the LUA scripts.
 
I had a Brazil server with that script I am not sure if it gonna work but I will post it for you to test, it was based on TFS 0.4 too.
on data/creaturescripts add this line to creaturescripts.xml
XML:
<event type="logout" name="entrosaLogout" event="script" value="warEntrosaLogout.lua"/>
then on data/creaturescripts/scripts make a LUA script with name warEntrosaLogout.lua and add this to it
Lua:
function onLogout(cid)
    if getPlayerStorageValue(cid, 888123) > os.time() then
        doPlayerSendCancel(cid, "Vc n pode logar enquanto esta em war! Espere "..getPlayerStorageValue(cid, 888123) - os.time().." segundos.")
        return false
    end
    return true
end
now on data/talkactions add this line to talkactions.xml
XML:
<talkaction log="yes" words="!war" event="script" value="warEntrosa.lua"/>
then on data/talkactions/scripts make a LUA script with name warEntrosa.lua and add this to it
Lua:
local arena_storage = 454523
local players_storage = 456512
local storage_accept = 151230
local storage_check = 153201
local guild_invite = 542351
local guild_accept = 456121
local time_1_pos = {x = 26366, y = 31962, z = 6}
local time_2_pos = {x = 26484, y = 31957, z = 6}
local city = "Carlin"

local function getOnlineGuildMembersByRank(guildId, rank, selectLowerRanks) -- Funcao feita pelo Omega
    if not rank then
        rank = 3
        selectLowerRanks = true
    end
    local list = {}
    for _, pid in pairs(getPlayersOnline()) do
        if getPlayerGuildId(pid) == guildId then
            local playerRank = getPlayerGuildLevel(pid)
            if playerRank == rank or (selectLowerRanks and playerRank <= rank) then
                table.insert(list, pid)
            end
        end
    end
    return list
end

function onSay(cid, words, param, channel)
    if param == "" then
        doPlayerSendCancel(cid, "Use os parametros corretos.")
        return true
    end
  
    local t = string.explode(param, ",")
  
    if words == "!war"..city.." invite," then
      
        if getPlayerGuildLevel(cid) < 3 then
            doPlayerSendCancel(cid, "Somente liders de guild podem usar esse comando.")
            return true
        end
      
        if getGuildId(t[2]) and getGuildId(t[2]) ~= getPlayerGuildId(cid) then
            if #getOnlineGuildMembersByRank(getGuildId(t[2]), 3, false) > 0 then
                if getGlobalStorageValue(arena_storage) <= os.time() then
                    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Voce convidou a guild "..t[2].." para uma war em "..city.."!")
                    for _, gid in pairs(getOnlineGuildMembersByRank(getGuildId(t[2]), 3, false)) do
                        doPlayerSendTextMessage(gid, MESSAGE_STATUS_CONSOLE_ORANGE, getCreatureName(cid).." da guild "..getPlayerGuildName(cid).." chamou sua guild para uma war em "..city.." Para aceitar diga /war"..city.." accept, "..getPlayerGuildName(cid)..".")
                        setPlayerStorageValue(gid, storage_accept, os.time() + 20*60)
                        setPlayerStorageValue(gid, storage_check, getPlayerGuildId(cid))
                    end
                else
                    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "A arena ja esta ocupada.")
                end
            else
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Nenhum lider da guild "..t[2].." esta online.")
            end
        else
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Essa guild nao existe.")
        end
  
  
    elseif "!war"..city.." accept," then
        if getPlayerGuildLevel(cid) < 3 then
            doPlayerSendCancel(cid, "Somente liders de guild podem usar esse comando.")
            return true
        end
        if getGuildId(t[2]) and getGuildId(t[2]) ~= getPlayerGuildId(cid) then
            if getPlayerStorageValue(cid, storage_accept) > os.time() then
                if getPlayerStorageValue(cid, storage_check) == getGuildId(t[2]) then
                    setGlobalStorageValue(arena_storage, os.time() + 3600)
                    setGlobalStorageValue(guild_accept, getPlayerGuildId(cid))
                    setGlobalStorageValue(guild_invite, getGuildId(t[2]))
                    if #getOnlineGuildMembersByRank(getGuildId(t[2]), 3, true) > 0 then
                        for _, gid in pairs(getOnlineGuildMembersByRank(getGuildId(t[2]), 3, true)) do
                        doPlayerSendTextMessage(gid, MESSAGE_STATUS_CONSOLE_BLUE, "Sua guild entrou em war contra a guild "..getPlayerGuildName(cid).."! Para participar diga /war"..city.." go")
                        end
                    end
                    if #getOnlineGuildMembersByRank(getPlayerGuildId(cid), 3, true) > 0 then
                        for _, pid in pairs(getOnlineGuildMembersByRank(getPlayerGuildId(cid), 3, true)) do
                            doPlayerSendTextMessage(pid, MESSAGE_STATUS_CONSOLE_BLUE, "Sua guild entrou em war contra a guild "..t[2].."! Para participar diga /war"..city.." go")
                        end
                    end
                    addEvent(function()
                        for _, pid in pairs(getPlayersOnline()) do
                            if isInArea(getThingPos(pid), {x = 26357, y = 31906, z = 3}, {x = 26507, y = 32030, z = 3}) or isInArea(getThingPos(pid), {x = 26357, y = 31906, z = 4}, {x = 26507, y = 32030, z = 4}) or isInArea(getThingPos(pid), {x = 26357, y = 31906, z = 5}, {x = 26507, y = 32030, z = 5}) or isInArea(getThingPos(pid), {x = 26357, y = 31906, z = 6}, {x = 26507, y = 32030, z = 6}) or isInArea(getThingPos(pid), {x = 26357, y = 31906, z = 7}, {x = 26507, y = 32030, z = 7}) or isInArea(getThingPos(pid), {x = 26357, y = 31906, z = 8}, {x = 26507, y = 32030, z = 8}) or isInArea(getThingPos(pid), {x = 26357, y = 31906, z = 9}, {x = 26507, y = 32030, z = 9}) then
                                doTeleportThing(pid, getTownTemplePosition(getPlayerTown(cid)))
                                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Voce foi teleportado para o templo pq o tempo de war acabou")
                            end
                        end
                    end, 1000*3600)
                    addEvent(setGlobalStorageValue, 3600*1000, guild_accept, -1)
                    addEvent(setGlobalStorageValue, 3600*1000, guild_invite, -1)
                else
                    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Essa guild nao te invitou para uma war.")
                end
            else
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Sua guild n foi chamada para nenhuma war.")
            end
        else
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Essa guild nao existe.")
        end
    elseif "!war"..city.." go" then
        if getTilePzInfo(getThingPos(cid)) == false then
            doPlayerSendCancel(cid, "Vc precisa estar na pz")
            return true
        end
        if getGlobalStorageValue(guild_invite) == getPlayerGuildId(cid) or getGlobalStorageValue(guild_accept) == getPlayerGuildId(cid) then
            doPlayerSetStorageValue(cid, 888123, os.time() + getGlobalStorageValue(arena_storage))
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Voce entrou na war!")
            if getGlobalStorageValue(guild_invite) == getPlayerGuildId(cid) then
                doTeleportThing(cid, time_1_pos)
            else
                doTeleportThing(cid, time_2_pos)
            end
        else
            doPlayerSendCancel(cid, "Sua guild nao esta em war")
        end
    end
    return true
end
Then now on data/talkactions/lib make a LUA file and name it WAR.lua then add this to it
Lua:
War = {
  
    numero = { 0, 10, 15, 20, 30, 40 },    -- quantidade de jogadores (0=infinito)
    tempo = { quinze_min = 15,          trinta_min = 30,            sessenta_min = 60 },            --    colocar o nome das variaveis iguais
    preco = { quinze_min = 75000,      trinta_min = 100000,     sessenta_min = 150000},        --  caso fizer alguma alteração
  
    modo = { tradicional = 1, semUe = 2, soSd = 3},
    modo_string = {
                    [1] = {'tradicional', 'padrao', 'normal', '1'},
                    [2] = {'sem ue', 'semue', 'semUe', '2'},
                    [3] = {'apenas sd', 'só sd', 'so sd' , 'soh sd', '3'}
    }, 
  
    --[[     
            você pode colocar quantos mapas quiser de uma mesma cidade     
            na tabela referente ao mapa, cada vetor da matriz é composto da Posição do Time A e do B
          
            exemplo:         
            [0] = { {posA, posB}, {posA2, posB2}, {posA3, posA4}  }    -- aqui vc tem 3 mapas configurado para Edron
                      
            posA = local da cidade em que os jogadores da guild A será teleportados
            posB = local para a guild B
          
            você é livre para escolher quais e quantas copias da cidade
          
            preste atenção! o valor da string e da position deve ser o mesmo!
]]
  
    cidade_string = {
                          [0] = {'edron', "Edron", 'EDRON'},
                --[[      [1] = {'dara', 'darashia', 'Darashia', 'DARASHIA'},
                          [2] = {'lb', 'liberty bay', 'Liberty Bay', 'LIBERTY BAY'},
                          [3] = {'carlin', 'Carlin', 'CARLIN'},
                          [4] = {'cormaya', 'Cormaya', 'CORMAYA'},
                          [5] = {'ank', 'ankrahmun', 'Ankrahmun', 'ANKRAHMUN'},
                          [6] = {'yalahar', 'Yalahar', 'YALAHAR'},
                          [7] = {'venore', 'Venore', 'VENORE'}    ]]
    },
    mapas = { 
                          [0] = {     {{x=1178,y=636,z=7},{x=1178,y=692,z=7}}     },        -- exemplo de apenas um mapa Edron configurado
                          [1] = {},
                          [2] = {},
                          [3] = {},
                          [4] = {},
                          [5] = {},
                          [6] = {},
                          [7] = {} 
    },
}

for city, v in pairs(War.mapas) do
    for _, mapa in pairs(v) do
        Instances(city, mapa)
    end
end

Wars = {}

function War:new(id, param)
  
     return setmetatable({
  
            -- config
            id = id,
            desafiante = param.desafiante,
            aceito = false,
            numero_jogadores = param.numero,
            modo = param.modo,
            tempo = param.tempo,
            instanceid = param.instanceid,
            valor = param.valor,
            positions = {[param.guildA] = param.positionA, [param.guildB] = param.positionB},
          
            -- uso real
            players = {[param.guildA] = {}, [param.guildB] = {}},
            frags = {[param.guildA] = 0, [param.guildB] = 0},
            name = {}
          
          
     }, { __index = self }), addEvent(function (id, param)
                                                    if Wars[id] and Wars[id].aceito == false then
                                                        doPlayerDepositMoney(self.desafiante, valor)
                                                        Wars[id]:broadcastToGuilds(22, "O convite nao foi aceito.")
                                                        Wars[id] = false
                                                        Instances[param.instanceid]:unregister()
                                                    end
                                                end, 5 * 60 * 1000, id, param)
end

setmetatable(Wars, { __call =     function(self, param)
                                        local id = #Wars+1
                                        Instances[param.instanceid]:register()
                                        param.positionA = Instances[param.instanceid].posA
                                        param.positionB = Instances[param.instanceid].posB
                                      
                                        Wars[id] = War:new(id, param)
                                      
                                        Wars[id].name = {{param.guildA, param.nomeA}, {param.guildB, param.nomeB}}
                                      
                                        local text = "[City War] "..param.nomeA .. " invitou a guild " .. param.nomeB .. " para uma war!\n"
                                        text = text .. "A war sera na cidade " .. War.cidade_string[param.cidade][1]
                                        if (param.numero == 0) then                                     
                                            text = text .. " sem limite de jogadores para cada time"
                                        else
                                            text = text .. " com no maximo " .. param.numero .. " jogadores para cada time"
                                        end                                                                             
                                        text = text .. " por " .. param.tempo .. " minutos"
                                        text = text .. " no modo " .. War.modo_string[param.modo][1]
                                        text = text .. "\nO lider da guild " .. param.nomeB .. " tem cinco minutos para aceitar o convite. Digite: /citywar accept, " .. param.nomeA
                                      
                                        Wars[id]:broadcastToGuilds(22, text)
                                end })
                                                              
                              
function War:start()
    self.aceito = true 
    self:broadcastToGuilds(22, "[City War] A War entre " .. self.name[1][2] .. " e " .. self.name[2][2] .. "  foi iniciada! Para entrar digite: /citywar go" )
  
    addEvent(War.broadcast, (self.tempo * 60 * 1000) - (5 * 60 * 1000), self, 22, "[City War] Faltam 5 minutos para a War acabar.")
    addEvent(War.broadcast, (self.tempo * 60 * 1000) - (3 * 60 * 1000), self, 22, "[City War] Faltam 3 minutos para a War acabar.")
    addEvent(War.broadcast, (self.tempo * 60 * 1000) - (1 * 60 * 1000), self, 22, "[City War] Falta 1 minuto para a War acabar.")
    addEvent(War.finish, self.tempo * 60 * 1000, self)
end

function War:finish()
  
    local text = "A war entre as guilds " .. self.name[1][2] .. " e " .. self.name[2][2] .. " acabou!\n"
    text = text .. self:getPlacarString()
    self:broadcastToGuilds(22, text)
  
    for guild, teams in pairs(self.players) do
        for k, cid in pairs(teams) do
            if type(cid) == 'number' and isPlayer(cid) then
                local pos = getTownTemplePosition(getPlayerTown(cid))         
                doTeleportThing(cid, pos)         
              
                setPlayerWarType(cid, 0)
                unregisterCreatureEvent(cid, "morte") 
              
                doRemoveCondition(cid, CONDITION_INFIGHT)
                if getCreatureSkullType(cid) == SKULL_WHITE then
                    doCreatureSetSkullType(cid, 0)
                end
              
                self.players[guild][k] = nil
            end
        end
    end 
    Instances[self.instanceid]:unregister()
  
    db.executeQuery("INSERT INTO [ICODE]city_war[/ICODE] ([ICODE]frags_guild1[/ICODE], [ICODE]frags_guild2[/ICODE], [ICODE]guild1[/ICODE], [ICODE]guild2[/ICODE], [ICODE]tempo[/ICODE], [ICODE]modo[/ICODE]) VALUES ('" .. self.frags[self.name[1][1]] .. "', '" .. self.frags[self.name[2][1]] .. "', '" .. self.name[1][2] .. "', '" .. self.name[2][2] .. "', '" .. self.tempo .. "', '" .. self.modo .. "' );")
    Wars[self.id] = true
end

local condition_infight = createConditionObject(CONDITION_INFIGHT, -1)

function War:newPlayer(cid)
    if self.aceito == false then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The war was not accepted yet.")
        return true
    end

    local guildId = getPlayerGuildId(cid)
        if (self.numero_jogadores == 0 or table.elements(self.players[guildId]) < self.numero_jogadores) then
            doTeleportThing(cid, self.positions[guildId])
            table.insert(self.players[guildId], cid)
        else
            return false
        end
    doAddCondition(cid, condition_infight)
    setPlayerWarType(cid, self.modo)
    registerCreatureEvent(cid, "citywar")
    return true
end

function War:removePlayer(cid)
    --town = getPlayerTown(cid)
    --pos = getTownTemplePosition(town)     
          
    --doTeleportThing(cid, pos)
  
    setPlayerWarType(cid, 0) 
    unregisterCreatureEvent(cid, "citywar")

    tmp = false
    for guild, teams in pairs(self.players) do
        for k, v in pairs(teams) do
            if v == cid then
                self.players[guild][k] = nil
                tmp = true
                break
            end
        end
        if tmp == true then
            break
        end
    end
    doRemoveCondition(cid, CONDITION_INFIGHT)
    if getCreatureSkullType(cid) == SKULL_WHITE then
        doCreatureSetSkullType(cid, 0)
    end
end

function War:isGuildOnWar(guildId)
    if self.name[1][1] == guildId or self.name[2][1] == guildId then
        return true 
    end
        return false
end

function War:kill(killer, cid)
    if (isPlayer(killer) or (isMonster(killer) and getCreatureMaster(killer))) then
        killer = isPlayer(killer) and killer or getCreatureMaster(killer)
        if getPlayerGuildId(killer) ~= getPlayerGuildId(cid) then
            self.frags[getPlayerGuildId(killer)] = self.frags[getPlayerGuildId(killer)] + 1
            self:broadcast(22, "[City War] \n".. getPlayerName(killer) .. " matou " .. getPlayerName(cid) .. ".\n" .. self:getPlacarString())
        end
    end
end

function War:getPlacarString()
    local text = "Placar: " .. self.name[1][2] .. " " .. self.frags[self.name[1][1]] .. " x "
    text = text .. self.frags[self.name[2][1]] .. " " .. self.name[2][2].."." 
    return text
end

function War:broadcast(messagetype, text)
    for k, v in pairs(self.players) do
        for _, cid in pairs(v) do
            if isPlayer(cid) then
                doPlayerSendTextMessage(cid, messagetype, text)
            end
        end
    end
end

function War:broadcastToGuilds(messagetype, text)
    local guilds = {self.name[1][1], self.name[2][1]}
    local isinarray, sendmessage, getguildid = isInArray, doPlayerSendTextMessage, getPlayerGuildId
  
    for k, v in pairs(getPlayersOnline()) do
        if isinarray(guilds, getguildid(v)) then
            sendmessage(v, messagetype, text)
        end
    end
end

-- função static, callback entre creaturescripts e o evento
function War.morte(cid, killer)
    for k,v in pairs(Wars) do
        if type(v) == 'table' then
            if v:isGuildOnWar(getPlayerGuildId(cid)) then
                v:kill(killer, cid)
                v:removePlayer(cid)
            end
        end
    end
    return true
end
That should work for Carlin, You will have maybe to change XYZ If you use different map and also you'll have to translate Brazil words to English to suit your server.
And if you want to add more cities just copy the talkactions file and change XYZ/name for the other city you want.
if it didn't then that Brazil server I had made some specific source edits along with the LUA scripts.


On server start I get these errors on console

PHP:
[16:27:08.309] mysql_real_query(): UPDATE `players` SET `rank_id` = 0, `guildnick` = '', `guildjoin` = 0 WHERE `rank_id` IN (1,2,3); - MYSQL ERROR: Unknown column 'guildjoin' in 'field list' (1054)
[16:27:08.309] mysql_real_query(): UPDATE `players` SET `rank_id` = 0, `guildnick` = '', `guildjoin` = 0 WHERE `rank_id` IN (); - MYSQL ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1 (1064)
[16:27:08.309] mysql_real_query(): UPDATE `players` SET `rank_id` = 0, `guildnick` = '', `guildjoin` = 0 WHERE `rank_id` IN (); - MYSQL ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1 (1064
 
Back
Top