Ir para conteúdo
  • Cadastre-se

(Resolvido)Erro talkactions


Ir para solução Resolvido por WooX,

Posts Recomendados

Tinha postado um anti entrosa que consegui resolver em partes da war continuar depois de uma rodada.

 

Mas tem um problema que se torna grave em questão que os monster ou summon se mata o player no evento entrosa o servidor cai, o erro ocorre no arquivo war.lua

erro na linha 212, abaixo da imagem tem o arquivo lua inteiro..

self.frags[getPlayerGuildId(killer)] = self.frags[getPlayerGuildId(killer)] + 1

 

image.png.7604d475047a5396e03feb410a4132bb.png

 

 

 


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 `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)
    self.frags[getPlayerGuildId(killer)] = self.frags[getPlayerGuildId(killer)] + 1
    self:broadcast(22, "[City War] \n".. getPlayerName(killer) .. " matou " .. getPlayerName(cid) .. ".\n" .. self:getPlacarString())
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

 

Editado por maleskinho (veja o histórico de edições)
Link para o post
Compartilhar em outros sites

Não tenho como testar e não tenho muita experiência com essa versão do TFS, mas tenta mudar essa função:
 

function War:kill(killer, cid)
    self.frags[getPlayerGuildId(killer)] = self.frags[getPlayerGuildId(killer)] + 1
    self:broadcast(22, "[City War] \n".. getPlayerName(killer) .. " matou " .. getPlayerName(cid) .. ".\n" .. self:getPlacarString())
end

Deixando assim:
 

function War:kill(killer, cid)
    if(killer:isMonster()) then
        local master = killer:getMaster()
        if(not master or not master:isPlayer()) then
            return true
        end
        killer = master
    end

    self.frags[getPlayerGuildId(killer)] = self.frags[getPlayerGuildId(killer)] + 1
    self:broadcast(22, "[City War] \n".. getPlayerName(killer) .. " matou " .. getPlayerName(cid) .. ".\n" .. self:getPlacarString())
end

 

                                                                     Ajudei? De nada \o/                                            Att Rusherzin

Link para o post
Compartilhar em outros sites
  • Solução

@maleskinho A função War:kill não está verificando se o quem matou o player era um player também, e ainda assim a função tenta buscar pelo GuildId de quem matou o player (é óbvio, mas monstros não tem GuildId). 

 

Testa ai.

Spoiler

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 `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) 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

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

 

 

 

 

 

Nós somos aquilo que fazemos repetidamente. Excelência, não é um modo de agir, mas um hábito.

                                                                                                                                                                                                                                        Aristóteles 

Link para o post
Compartilhar em outros sites
1 hora atrás, Rusherzin disse:

Não tenho como testar e não tenho muita experiência com essa versão do TFS, mas tenta mudar essa função:
 


function War:kill(killer, cid)
    self.frags[getPlayerGuildId(killer)] = self.frags[getPlayerGuildId(killer)] + 1
    self:broadcast(22, "[City War] \n".. getPlayerName(killer) .. " matou " .. getPlayerName(cid) .. ".\n" .. self:getPlacarString())
end

Deixando assim:
 


function War:kill(killer, cid)
    if(killer:isMonster()) then
        local master = killer:getMaster()
        if(not master or not master:isPlayer()) then
            return true
        end
        killer = master
    end

    self.frags[getPlayerGuildId(killer)] = self.frags[getPlayerGuildId(killer)] + 1
    self:broadcast(22, "[City War] \n".. getPlayerName(killer) .. " matou " .. getPlayerName(cid) .. ".\n" .. self:getPlacarString())
end

 

@Rusherzin Mesmo erro, mas obrigado por tenta ajudar

 

1 hora atrás, Way20 disse:

@maleskinho A função War:kill não está verificando se o quem matou o player era um player também, e ainda assim a função tenta buscar pelo GuildId de quem matou o player (é óbvio, mas monstros não tem GuildId). 

 

Testa ai.

  Mostrar conteúdo oculto


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 `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) 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

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

 

 

@Way20 Deu certo amigo, era o único erro nesse evento tinha outro mas consegui resolver.

 

Muito Obrigado :D

Link para o post
Compartilhar em outros sites
3 minutos atrás, maleskinho disse:

@Rusherzin Mesmo erro, mas obrigado por tenta ajudar

 

@Way20 Deu certo amigo, era o único erro nesse evento tinha outro mas consegui resolver.

 

Muito Obrigado :D

 

No meu código eu esqueci dos Summons, se o summon de um player matar outro player não vai enviar a mensagem de kill. Tem como melhorar esse código fazendo funcionar o código do @Rusherzin (na verdade o código dele está correto, mas devido ao uso de metatables no script ele confundiu sua distro com TFS 1.x).

 

Sumona um monstro qualquer e deixa ele matar algum player inimigo na area Anti-Entrosa, verifica se envia a mensagem dizendo que o dono do summon matou o player. Muda essa função.

function War:kill(killer, cid)
	if (isPlayer(killer) or (isMonster(killer) and getCreatureMaster(killer))) then
		killer = isPlayer(killer) and killer or getCreatureMaster(killer)
		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

 

 

 

 

Nós somos aquilo que fazemos repetidamente. Excelência, não é um modo de agir, mas um hábito.

                                                                                                                                                                                                                                        Aristóteles 

Link para o post
Compartilhar em outros sites
23 minutos atrás, Way20 disse:

 

No meu código eu esqueci dos Summons, se o summon de um player matar outro player não vai enviar a mensagem de kill. Tem como melhorar esse código fazendo funcionar o código do @Rusherzin (na verdade o código dele está correto, mas devido ao uso de metatables no script ele confundiu sua distro com TFS 1.x).

 

Sumona um monstro qualquer e deixa ele matar algum player inimigo na area Anti-Entrosa, verifica se envia a mensagem dizendo que o dono do summon matou o player. Muda essa função.


function War:kill(killer, cid)
	if (isPlayer(killer) or (isMonster(killer) and getCreatureMaster(killer))) then
		killer = isPlayer(killer) and killer or getCreatureMaster(killer)
		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

 

 

Sim é otx


@Way20 Sumonei os fire elemental e contabilizo certinho, muito obrigado novamente.

 

Ficou perfeito o script ;)

 

--------------------------------

 

@Way20 os da mesma guild se ataca no evento e contabiliza pra eles mesmo os pontos consegue bloquear pra não ataca os da mesma guild na war?

Editado por maleskinho (veja o histórico de edições)
Link para o post
Compartilhar em outros sites
41 minutos atrás, maleskinho disse:

 

@Way20 os da mesma guild se ataca no evento e contabiliza pra eles mesmo os pontos consegue bloquear pra não ataca os da mesma guild na war?

 

 

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

 

 

 

 

Nós somos aquilo que fazemos repetidamente. Excelência, não é um modo de agir, mas um hábito.

                                                                                                                                                                                                                                        Aristóteles 

Link para o post
Compartilhar em outros sites
10 minutos atrás, Way20 disse:

 


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

 

@Way20 show agora sim perfeito, muito obrigado novamente.

Link para o post
Compartilhar em outros sites

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

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emojis são permitidos.

×   Seu link foi automaticamente incorporado.   Mostrar como link

×   Seu conteúdo anterior foi restaurado.   Limpar o editor

×   Não é possível colar imagens diretamente. Carregar ou inserir imagens do URL.

×
×
  • Criar Novo...

Informação Importante

Confirmação de Termo