Ir para conteúdo

Featured Replies

Postado

Preciso de uma função pra cancelar a war caso o dono da guild queira desistir antes do tempo e mandar todos para o templo...

 

talkactions/scripts/citywar.lua

 

 

 

-- /citywar invite, guild, cidade, numero, modo, tempo
local function cityWarInvite(cid, param)

local guildId = getGuildId(param[2])
    if guildId == false then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Invalid guild name.")
        return false
    end
    if guildId == getPlayerGuildId(cid) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Invalid guild invite.")
        return false    
    end
    if isGuildAntiEntrosa(guildId) or isGuildAntiEntrosa(getPlayerGuildId(cid)) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Guild already on war.")
        return false        
    end
local nomeB = param[2]
    
    --if not cityWarExtraRequirements(cid, guildId) then
        --return false
    --end    
local ret, instance = isInAnyArray(War.cidade_string, param[3])
    if ret then        
        instanceid = Instance:getFree(instance)
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Invalid city name.")
        return false
    end
    
local numero = 0
    if tonumber(param[4]) and isInAnyArray(War.numero, tonumber(param[4])) then
        numero = tonumber(param[4])
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Invalid number of players.")
        return false
    end
    
local ret, modo = isInAnyArray(War.modo_string, param[5])
    if not ret then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Invalid type name.")
        return false
    end

local preco, tempo = 0, 0
    if tonumber(param[6]) then
        tempo = tonumber(param[6])
        ret, preco = isInAnyArray(War.tempo, tonumber(param[6]))
        if not ret then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Invalid duration time.")
            return false
        end
        if not doPlayerWithdrawMoney(cid, War.preco[preco]) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Not enough money.")
            return false            
        end
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Invalid duration time.")
        return false
    end        

local config = {
    desafiante = cid,
    nomeA = getPlayerGuildName(cid),
    nomeB = nomeB,
    tempo = tempo,
    valor = War.preco[preco],
    modo = modo,
    numero = numero,
    cidade = instance,
    instanceid = instanceid,
    guildA = getPlayerGuildId(cid),
    guildB = guildId
}

    Wars(config)
end

-- /citywar accept, guild
local function cityWarAccept(cid, param)
local selfGuild = getPlayerGuildId(cid)
local invitingGuild = getGuildId(param[2])
    if selfGuild == invitingGuild then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You cannot accept your own request.")
        return
    end
    for _, v in pairs(Wars) do
        if type(v) == 'table' then
            if v:isGuildOnWar(invitingGuild) and v:isGuildOnWar(selfGuild) then
                if doPlayerWithdrawMoney(cid, v.valor) then
                    v:start()
                else
                    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Not enough money.")
                end
            end
        end
    end
end

-- /citywar go
local function cityWarGo(cid)
selfGuild = getPlayerGuildId(cid)
    for _, v in pairs(Wars) do
        if type(v) == 'table' then
            if v:isGuildOnWar(selfGuild) then
                if getTileInfo(getThingPosition(cid)).protection == false then
                    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Please go to a protection zone.")
                    return true
                end
                return v:newPlayer(cid)
            end
        end
    end
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Your guild is not in a war.")
    return true
end

-- /citywar exit
local function cityWarExit(cid)
    if getPlayerWarType(cid) <= 0 then
        return false
    end
    selfGuild = getPlayerGuildId(cid)
    for _, v in pairs(Wars) do
        if type(v) == 'table' then
            if v:isGuildOnWar(selfGuild) then
                if getTileInfo(getThingPosition(cid)).protection == false then
                    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Please go to a protection zone.")
                    return true
                end
                v:removePlayer(cid)
            end
        end
    end
end

function onSay(cid, words, param, channel)
    if(param == '') then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command param required.")
        return true
    end    

    local t = string.explode(param, ",")
    local ret = RETURNVALUE_NOERROR

    local comando = t[1]
    if comando == "accept" then
        if isGuildLeader(cid) then
            if getPlayerWarType(cid) < 1 then
                cityWarAccept(cid, t)
            else
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You are already in a war.")    
            end
        else
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You are not a guild leader.")            
        end
    elseif comando == "invite" then
        if isGuildLeader(cid) then
            if getPlayerWarType(cid) < 1 then
                cityWarInvite(cid, t)
            else
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You are already in a war.")    
            end
        else
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You are not a guild leader.")            
        end
    elseif comando == "go" then
        if not cityWarGo(cid) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Player number limit reached.")            
        end
    elseif comando == "exit" then
        if not cityWarExit(cid) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You are not in war.")
        end
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Invalid command param.")
    end
    return true
end

 

talkactions/lib/war.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] = {'thais', "Thais", 'THAIS'},
                          [1] = {'dara', 'darashia', 'Darashia', 'DARASHIA'},
                          [2] = {'edron', 'Edron', 'EDRON'},
                          [3] = {'carlin', 'Carlin', 'CARLIN'},
                          [4] = {'yalahar', 'Yalahar', 'YALAHAR'},
                          [5] = {'ank', 'ankrahmun', 'Ankrahmun', 'ANKRAHMUN'},
             --[[         [6] = {'outro', 'Outro', 'OUTRO'},
                          [7] = {'venore', 'Venore', 'VENORE'}    ]]
    },
    mapas = {    
                          [0] = {     {{x=31300,y=32323,z=7},{x=31378,y=32336,z=7}}     },             -- exemplo de apenas um mapa Edron configurado
                          [1] = {     {{x=31324,y=32923,z=7},{x=31355,y=32971,z=7}}     },     
                          [2] = {     {{x=31310,y=32554,z=7},{x=31347,y=32577,z=7}}     },    
                          [3] = {     {{x=31336,y=32126,z=7},{x=31424,y=32133,z=7}}     },    
                          [4] = {     {{x=31299,y=32793,z=7},{x=31359,y=32809,z=7}}     },    
                          [5] = {     {{x=31256,y=33431,z=7},{x=31317,y=33373,z=7}}     },    
                          [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 `city_war` (`frags_guild1`, `frags_guild2`, `guild1`, `guild2`, `tempo`, `modo`) 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

 

talkactions/lib/instance.lua

 

 

 

-- Classe Instance
Instance = {}
Instances = {}
instances_abertas = true

 function Instance:new(id, cidade, pos)
    
     return setmetatable({
     
            id = id, 
            cidade = cidade,
            usando = false,
            posA = pos[1],
            posB = pos[2]
            
     }, { __index = self }) 
 end
setmetatable(Instances, { __call = function(self, cidade, pos) 
                                    local id = #Instances+1
                                    Instances[id] = Instance:new(id, cidade, pos) 
                                end })

    

function Instance:getFree(cidade) -- retorna uma instance livre
    if instances_abertas then    
        for k,v in pairs(Instances) do
            if v.cidade == cidade and v.usando == false then    
                return k
            end
        end
    end
    return false
end

function Instance:register()
    self.usando = true
end

function Instance:unregister()
    self.usando = false    
end

function Instance:getMaps()
maps = {}
    for _, v in pairs(Instances) do
        maps[v.cidade] = true
    end
    return maps
end

 

Editado por maleskinho
spoiler.. (veja o histórico de edições)

Participe da conversa

Você pode postar agora e se cadastrar mais tarde. Se você tem uma conta, faça o login para postar com sua conta.

Visitante
Responder

Quem Está Navegando 0

  • Nenhum usuário registrado visualizando esta página.

Conteúdo Similar

Estatísticas dos Fóruns

  • Tópicos 96.9k
  • Posts 520.1k

Informação Importante

Confirmação de Termo