Ir para conteúdo
  • 0
dzfeoo

Scripting [Revscriptsys][OTBR] Castle War

Pergunta

dzfeoo    3
dzfeoo

Antes de fazer a sua pergunta, tenha certeza de ter lido as regras da seção e o guia abaixo:

https://forums.otserv.com.br/index.php?/forums/topic/168583-regras-da-seção/

https://forums.otserv.com.br/index.php?/forums/topic/165121-como-fazer-uma-pergunta-ou-o-grande-guia-do-usuário-com-dúvidas/

Obs: não delete esse formulário pré-definido, preencha-o corretamente para postar o seu tópico!

Descreva em algumas palavras a base utilizada. (Nome do servidor / Nome do cliente / Nome do website / etc.).

Base:

OTSERVBR-GLOBAL

Qual é a sua pergunta?

Alguém me ajuda a converter esse script de Castle War (TFS 1.3) para Revscriptsys?

 

creaturescripts/creaturescripts.xml

<event type="healthchange" name="hpChange" script="woe.lua"/>

creaturescripts/scripts/woe.lua

Spoiler

local guilds = {}

function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    local isGuild = false
    local damage = primaryDamage + secondaryDamage

    if attacker:isPlayer() == false then
        if attacker:getMaster() == false then
            return
        end
        attacker = attacker:getMaster()
    end

    if attacker:getGuild() == nil then
        return
    end

    for k,v in pairs(guilds) do
        if v[1] == attacker:getGuild():getId() then
            v = {v[1], v[2] + damage}
            isGuild = true
            break
        end
    end


    if not isGuild then
        guilds[#guilds+1] = {attacker:getGuild():getId(), damage}
    end

    if creature:getHealth() - damage <= 0 then
        table.sort(guilds, function(a,b) return a[2] > b[2] end)
        db.query("CREATE TABLE IF NOT EXISTS `castle` (`guild_id` int(11) NOT NULL, guild_name varchar(255) NOT NULL) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;")
        db.query("DELETE FROM `castle`")
        if guilds[1][1] ~= nil then
            local info = db.storeQuery("SELECT `name`, `ownerid` FROM `guilds` WHERE `id` = " .. guilds[1][1] .. " LIMIT 1")
            local name = result.getString(info, "name")
            local owner = result.getString(info, "ownerid")
            db.query("INSERT INTO `castle` VALUES (".. guilds[1][1] ..", '".. name .."')")
            broadcastMessage(woe.eventName.." has ended. Congratulations to ".. name .." for claiming ownership of the castle!", MESSAGE_EVENT_ADVANCE)
            Tile(woe.castle):getHouse():setOwnerGuid(owner)
        end
        guilds = {}

        for k,v in pairs(woe.doors) do

            if Creature(v.name) ~= nil then
                Creature(v.name):remove()
            end
        
            local door = Game.createItem(v.id, 1, v.pos)
            door:setActionId(woe.actionid)
        end

    end

    return primaryDamage, primaryType, -secondaryDamage, secondaryType
end

 


globalevents/globalevents

<globalevent name="War of Emperium" time="18:00" script="woe.lua"/>

globalevents/script

function onTime(interval)
    if os.date("%H:%M") == woe.days[os.date("%A")] then
        woe.queueEvent(woe.timeDelay+1)
    end
end

 

lib/lib.lua
 

-- Custom functions
dofile('data/lib/custom/custom.lua')

lib/custom/customa

dofile('data/lib/custom/woe.lua')

lib/custom/w

Spoiler

woe = {
    eventName = "[WOE]",
    timeDelay = 1, -- minutes before event starts
    bcMsg = " is starting in ",
    doors = {
        {name = "Castle Gate", id = 6257, pos = {x = 1021, y = 1028, z = 7} },
        {name = "Castle Gate", id = 6257, pos = {x = 1022, y = 1028, z = 7} }
    },
    actionid = 33542, -- for the doors
    crystal = {id = 9784, name="Emperium", pos = {x = 1022, y = 1020, z = 7} },
    castle = {x = 1012, y = 1027, z = 7}, -- just has to be one of the housetiles of the castle
    days = {
        -- to enable a day for the globalevent do ["Weekday"] = time
        -- for example: ["Monday"] = 18:00,
    },

    queueEvent = function(x)
        x = x - 1
        if x > 0 then
            broadcastMessage(woe.eventName..woe.bcMsg..x..(x > 1 and "minutes!" or "minute!"), MESSAGE_EVENT_ADVANCE)
            addEvent(woe.queueEvent, x * 60 * 1000, x)
        else
            woe.startEvent()
        end
    end,

    startEvent = function()
        for k,v in pairs(woe.doors) do
            local item = Tile(v.pos):getItemById(v.id)
            if item ~= nil then
                item:remove()
                Game.createMonster(v.name, v.pos, false, true)
            else
                print("WOE GATE POSITION INVALID OR MISSING [x:"..v.pos.x.." | y:"..v.pos.y.." | z:"..v.pos.z.."]")
            end
        end
        local c = woe.crystal
        local item = Tile(c.pos):getItemById(c.id)
        if item ~= nil then
            item:remove()
            Game.createMonster(c.name, c.pos, false, true)
        else
            print("WOE CRYSTAL POSITION INVALID OR MISSING [x:"..c.pos.x.." | y:"..c.pos.y.." | z:"..c.pos.z.."]")
        end
    end,

}

 

 


talkactions/talkactions.xml

<talkaction words="!woe" separator=" " script="woe.lua" />

talkactions/scripts/woe.lua

function onSay(player, words, param)
    if not player:getGroup():getAccess() then
        return true
    end

    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end

    woe.queueEvent(woe.timeDelay+1)

    return false
end

 

post original

Compartilhar este post


Link para o post
Compartilhar em outros sites

3 respostass a esta questão

Recommended Posts

  • 0
Famosiin    0
Famosiin

você fez alguma coisa errada, porque testei aqui e não retornou nenhum erro

Compartilhar este post


Link para o post
Compartilhar em outros sites
  • 0
Famosiin    0
Famosiin
local guilds = {}

local castlewar = CreatureEvent("CastleWar")
function castlewar.onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    local isGuild = false
    local damage = primaryDamage + secondaryDamage

    if attacker:isPlayer() == false then
        if attacker:getMaster() == false then
            return
        end
        attacker = attacker:getMaster()
    end

    if attacker:getGuild() == nil then
        return
    end

    for k,v in pairs(guilds) do
        if v[1] == attacker:getGuild():getId() then
            v = {v[1], v[2] + damage}
            isGuild = true
            break
        end
    end


    if not isGuild then
        guilds[#guilds+1] = {attacker:getGuild():getId(), damage}
    end

    if creature:getHealth() - damage <= 0 then
        table.sort(guilds, function(a,b) return a[2] > b[2] end)
        db.query("CREATE TABLE IF NOT EXISTS `castle` (`guild_id` int(11) NOT NULL, guild_name varchar(255) NOT NULL) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;")
        db.query("DELETE FROM `castle`")
        if guilds[1][1] ~= nil then
            local info = db.storeQuery("SELECT `name`, `ownerid` FROM `guilds` WHERE `id` = " .. guilds[1][1] .. " LIMIT 1")
            local name = result.getString(info, "name")
            local owner = result.getString(info, "ownerid")
            db.query("INSERT INTO `castle` VALUES (".. guilds[1][1] ..", '".. name .."')")
            broadcastMessage(woe.eventName.." has ended. Congratulations to ".. name .." for claiming ownership of the castle!", MESSAGE_EVENT_ADVANCE)
            Tile(woe.castle):getHouse():setOwnerGuid(owner)
        end
        guilds = {}

        for k,v in pairs(woe.doors) do

            if Creature(v.name) ~= nil then
                Creature(v.name):remove()
            end
        
            local door = Game.createItem(v.id, 1, v.pos)
            door:setActionId(woe.actionid)
        end

    end

    return primaryDamage, primaryType, -secondaryDamage, secondaryType
end
castlewar:register()


local castlewarglobal = GlobalEvent("CastleWarGlobal")

function castlewarglobal.onTime(interval)
    if os.date("%H:%M") == woe.days[os.date("%A")] then
        woe.queueEvent(woe.timeDelay+1)
    end
end

castlewarglobal:time("18:00:00")
castlewarglobal:register()

local castlewartalk = TalkAction("!woe")
function castlewartalk.onSay(player, words, param)
    if not player:getGroup():getAccess() then
        return true
    end

    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end

    woe.queueEvent(woe.timeDelay+1)

    return false
end

castlewartalk:register()

O arquivo Lib você pode manter, testa pra ver se vai funcionar

 

va em data/scripts/custom e crie um arquivo chamado castlewar e cole dentro

Editado por Famosiin

Compartilhar este post


Link para o post
Compartilhar em outros sites
  • 0
dzfeoo    3
dzfeoo
WOE GATE POSITION INVALID OR MISSING [x:31385 | y:31710 | z:7]
WOE GATE POSITION INVALID OR MISSING [x:31385 | y:31705 | z:7]
[2021-16-04 18:04:39.493] [error] Lua script error: (Unknown scriptfile)
data/lib/woe.lua:39: attempt to index a nil value
stack traceback:
        [C]: in function '__index'
        data/lib/woe.lua:39: in function 'startEvent'
        data/lib/woe.lua:24: in function <data/lib/woe.lua:18>

 

@Famosiin

Cara funcionou bem! O único problema é que ta retornando esse erro quando inicio o evento usando o talkaction com o GOD

Editado por dzfeoo

Compartilhar este post


Link para o post
Compartilhar em outros sites
Visitante
Este tópico está impedido de receber novos posts.

  • Quem Está Navegando   0 membros estão online

    Nenhum usuário registrado visualizando esta página.

×