• 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 Convert Script TFS 0.4 to TFS 1.5 downgrade

Azerty

Active Member
Joined
Apr 15, 2022
Messages
316
Solutions
4
Reaction score
32
I know it's a lot to ask, but can anyone convert this script to TFS 1.5? If possible in revscript?

lib folder:
Lua:
COH_PUSHTIME = 10800 -- Tempo (em segundos) de exhausted para usar o comando !gocastle - Padrão (3 horas)
COH_AREA = {{x = 11107, y = 1104, z = 7}, {x = 1109, y = 1106, z = 7}} -- Canto superior esquerdo / inferior direito do Castle

-- // Não mexa daqui para baixo
COH_STATUS = 201320111714
COH_PREPARE1 = 201320111715
COH_PUSHSTOR = 201320111716
COH_PREPARE2 = 201320111717

function guildVencedora()
    local name
    local consulta = db.getResult("SELECT `guild` FROM `castelo_guerra` ORDER BY `id` DESC;")
    if (consulta:getID() ~= -1) then
        name = tonumber(consulta:getDataInt('guild'))
    else
        return 0
    end
    return name
end

function doCastleRemoveEnemies()

 for index, creature in ipairs(getPlayersOnline()) do
  if isInArea(getThingPos(creature), COH_AREA[1], COH_AREA[2]) then
   if (guildVencedora() ~= getPlayerGuildId(cid)) then
    doTeleportThing(creature, getTownTemplePosition(getPlayerTown(creature)))
   end
  end
 end
 return true
end

movements folder:

Lua:
function onStepIn(cid, item, pos, fromPosition)
local pos = getThingPos(cid)
 
if item.actionid == 16203 then
    if not isPlayer(cid) then
        return true
    end
    if (getPlayerGuildId(cid) == guildVencedora()) then
        doSendMagicEffect(getThingPos(cid), 14)
        doSendAnimatedText(pos, "CW", math.random(1, 255))
    else
        doSendMagicEffect(getThingPos(cid), 2)
        doTeleportThing(cid, fromPosition, false)
        doPlayerSendCancel(cid, "[CASTLE WAR 24H] Você não pertence á guild dominante.")
    end
  return true
 end

if item.actionid == 16202 then
    if not isPlayer(cid) then
      return true
    end

    if getPlayerGuildId(cid) > 0 then
        if (getPlayerGuildId(cid) == guildVencedora()) then
            doPlayerSendCancel(cid, "[CASTLE WAR 24H] Sua guild ja esta dominando.")         
            return false
        end

    if (getPlayerGuildId(cid) ~= guildVencedora()) and (getPlayerLevel(cid) >= 100) then
        doPlayerSendTextMessage(cid, 20, "[CASTLE WAR 24H] Você e sua guild estão no comando, os antigos donos podem se vingar!")
        setGlobalStorageValue(COH_PREPARE1, -1)
        setGlobalStorageValue(COH_PREPARE2, -1)
        db.query("INSERT INTO `castelo_guerra` (`guild`) VALUES (" .. getPlayerGuildId(cid) .. ");")
        doCastleRemoveEnemies()
        doBroadcastMessage("[CASTLE WAR 24H] O jogador ["..getCreatureName(cid).."] e sua guild ["..getPlayerGuildName(cid).."] estão no comando do castelo, vá dominar e impedir isso!")
    end
    else
        doSendMagicEffect(pos, 2) 
        doTeleportThing(cid, fromPosition, false)
        doPlayerSendCancel(cid, "[CASTLE WAR 24H] Você não possui uma guild.")
    end
return true
 end

if item.actionid == 16200 then
  if not isPlayer(cid) then
      return true
  end
  if getPlayerGuildId(cid) > 0 then
    doSendAnimatedText(pos, "CW", math.random(1, 255))
    if (getPlayerGuildId(cid) == guildVencedora()) and (getGlobalStorageValue(COH_PREPARE1) ~= getPlayerGuildName(cid)) and ((getGlobalStorageValue(COH_PREPARE2) ~= getPlayerGuildName(cid))) then
        setGlobalStorageValue(COH_PREPARE1, getPlayerGuildName(cid))
        doBroadcastMessage("[CASTLE WAR 24H] Atenção! A guild "..getPlayerGuildName(cid).." está tentando dominar o castelo, preparem-se!")
    end
    else
        doSendMagicEffect(pos, 2) 
        doTeleportThing(cid, fromPosition, false)
        doPlayerSendCancel(cid, "[CASTLE WAR 24H] Você não possui uma guild.")   
    return true
    end   
end
 
if item.actionid == 16201 then
    if not isPlayer(cid) then
        return true
    end
    doSendAnimatedText(pos, "CW", math.random(1, 255))
    if (getPlayerGuildId(cid) == guildVencedora()) and (getGlobalStorageValue(COH_PREPARE2) ~= getPlayerGuildName(cid)) then
        setGlobalStorageValue(COH_PREPARE2, getPlayerGuildName(cid))
        doBroadcastMessage("[CASTLE WAR 24H] Atenção! A guild "..getPlayerGuildName(cid).." está muito próxima do domínio, ataquem!")
    end
    end
    return true
end

talkactions folder:
Lua:
function onSay(cid, words, param)

 if getPlayerGuildLevel(cid) == GUILDLEVEL_LEADER then
  if getPlayerStorageValue(cid, COH_PUSHSTOR) < os.time() then
   if (getPlayerGuildId(cid) == guildVencedora()) then
    if isInArea(getThingPos(cid), COH_AREA[1], COH_AREA[2]) then
     if #getMembersOnline(getPlayerGuildId(cid)) > 0 then
      for index, creature in ipairs(getMembersOnline(getPlayerGuildId(cid))) do
       if (getTileInfo(getThingPos(creature)).protection ~= true) then
        return doPlayerSendCancel(cid, "[CoH] Os membros devem estar em área PZ.")
       end
       doTeleportThing(creature, getThingPos(cid))
      end
      setPlayerStorageValue(cid, COH_PUSHSTOR, os.time() + COH_PUSHTIME)
      doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "[Castle of Honor] Você teleportou seus membros, comando pode ser usado a cada "..tostring(COH_PUSHTIME / 60).." minuto(s).")
     else
      doPlayerSendCancel(cid, "[CoH] Para executar isso, sua guild deve ter 2 ou mais membros online.")
     end
    else
     doPlayerSendCancel(cid, "[CoH] Você deve estar no castelo.")
    end
   else
    doPlayerSendCancel(cid, "[CoH] Sua guild não é dona do castelo.")
   end
  else
   doPlayerSendCancel(cid, "[CoH] Você deve aguardar "..tostring(math.ceil((getPlayerStorageValue(cid, COH_PUSHSTOR) - os.time()) / 60)).." minuto(s) para usar este comando.")
  end
 else
  doPlayerSendCancel(cid, "[CoH] Você deve ser líder de uma guild para executar este comando.")
 end
 return true
end

function getMembersOnline(id)
 local mbr = {}

 for index, creature in ipairs(getPlayersOnline()) do
  if getPlayerGuildId(creature) == id then
   if getCreatureSkullType(creature) < 3 then
    table.insert(mbr, creature)
   end
  end                     
 end
 return mbr or #mbr
end
 
Poderia tentar assim?

lib folder:
Lua:
COH_PUSHTIME = 10800
COH_AREA = {{x = 11107, y = 1104, z = 7}, {x = 1109, y = 1106, z = 7}}

COH_STATUS = 201320111714
COH_PREPARE1 = 201320111715
COH_PUSHSTOR = 201320111716
COH_PREPARE2 = 201320111717

function guildVencedora()
    local name
    local consulta = db.getResult("SELECT `guild` FROM `castelo_guerra` ORDER BY `id` DESC;")
    if (consulta:getID() ~= -1) then
        name = tonumber(consulta:getDataInt('guild'))
    else
        return 0
    end
    return name
end

function doCastleRemoveEnemies()
    for index, creature in ipairs(getOnlinePlayers()) do
        if isInArea(getThingPos(creature), COH_AREA[1], COH_AREA[2]) then
            if (guildVencedora() ~= getPlayerGuildId()) then
                doTeleportThing(creature, getTownTemplePosition(getPlayerTown(creature)))
            end
        end
    end
    return true
end

movements folder:




Code:
function onStepIn(cid, item, pos, fromPosition)
    local pos = getThingPos(cid)

    if item.actionid == 16203 then
        if not isPlayer(cid) then
            return true
        end
        if (getPlayerGuildId() == guildVencedora()) then
            doSendMagicEffect(getThingPos(cid), 14)
            doSendAnimatedText(pos, "CW", math.random(1, 255))
        else
            doSendMagicEffect(getThingPos(cid), 2)
            doTeleportThing(cid, fromPosition, false)
            doPlayerSendCancel(cid, "[CASTLE WAR 24H] Você não pertence à guild dominante.")
        end
        return true
    end

    if item.actionid == 16202 then
        if not isPlayer(cid) then
            return true
        end

        if getPlayerGuildId() > 0 then
            if (getPlayerGuildId() == guildVencedora()) then
                doPlayerSendCancel(cid, "[CASTLE WAR 24H] Sua guild já está dominando.")
                return false
            end

            if (getPlayerGuildId() ~= guildVencedora()) and (getPlayerLevel(cid) >= 100) then
                doPlayerSendTextMessage(cid, 20, "[CASTLE WAR 24H] Você e sua guild estão no comando, os antigos donos podem se vingar!")
                setGlobalStorageValue(COH_PREPARE1, -1)
                setGlobalStorageValue(COH_PREPARE2, -1)
                db.query("INSERT INTO `castelo_guerra` (`guild`) VALUES (" .. getPlayerGuildId() .. ");")
                doCastleRemoveEnemies()
                doBroadcastMessage("[CASTLE WAR 24H] O jogador ["..getCreatureName(cid).."] e sua guild ["..getPlayerGuildName().."] estão no comando do castelo, vá dominar e impedir isso!")
            end
        else
            doSendMagicEffect(pos, 2)
            doTeleportThing(cid, fromPosition, false)
            doPlayerSendCancel(cid, "[CASTLE WAR 24H] Você não possui uma guild.")
        end
        return true
    end

    if item.actionid == 16200 then
        if not isPlayer(cid) then
            return true
        end
        if getPlayerGuildId() > 0 then
            doSendAnimatedText(pos, "CW", math.random(1, 255))
            if (getPlayerGuildId() == guildVencedora()) and (getGlobalStorageValue(COH_PREPARE1) ~= getPlayerGuildName()) and ((getGlobalStorageValue(COH_PREPARE2) ~= getPlayerGuildName())) then
                setGlobalStorageValue(COH_PREPARE1, getPlayerGuildName())
                doBroadcastMessage("[CASTLE WAR 24H] Atenção! A guild "..getPlayerGuildName().." está tentando dominar o castelo, preparem-se!")
            end
        else
            doSendMagicEffect(pos, 2)
            doTeleportThing(cid, fromPosition, false)
            doPlayerSendCancel(cid, "[CASTLE WAR 24H] Você não possui uma guild.")
            return true
        end
    end

    if item.actionid == 16201 then
        if not isPlayer(cid) then
            return true
        end
        doSendAnimatedText(pos, "CW", math.random(1, 255))
        if (getPlayerGuildId() == guildVencedora()) and (getGlobalStorageValue(COH_PREPARE2) ~= getPlayerGuildName()) then
            setGlobalStorageValue(COH_PREPARE2, getPlayerGuildName())
            doBroadcastMessage("[CASTLE WAR 24H] Atenção! A guild "..getPlayerGuildName().." está muito próxima do domínio, ataquem!")
        end
        return true
    end
end

talkactions folder:

Code:
function onSay(cid, words, param)
    if getPlayerGuildLevel(cid) == GUILDLEVEL_LEADER then
        if getPlayerStorageValue(cid, COH_PUSHSTOR) < os.time() then
            if (getPlayerGuildId() == guildVencedora()) then
                if isInArea(getThingPos(cid), COH_AREA[1], COH_AREA[2]) then
                    local guildMembersOnline = getMembersOnline(getPlayerGuildId())
                    if #guildMembersOnline > 0 then
                        for index, creature in ipairs(guildMembersOnline) do
                            if (getTileInfo(getThingPos(creature)).protection ~= true) then
                                return doPlayerSendCancel(cid, "[CoH] Os membros devem estar em área PZ.")
                            end
                            doTeleportThing(creature, getThingPos(cid))
                        end
                        setPlayerStorageValue(cid, COH_PUSHSTOR, os.time() + COH_PUSHTIME)
                        doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "[Castle of Honor] Você teleportou seus membros, comando pode ser usado a cada "..tostring(COH_PUSHTIME / 60).." minuto(s).")
                    else
                        doPlayerSendCancel(cid, "[CoH] Para executar isso, sua guild deve ter 2 ou mais membros online.")
                    end
                else
                    doPlayerSendCancel(cid, "[CoH] Você deve estar no castelo.")
                end
            else
                doPlayerSendCancel(cid, "[CoH] Sua guild não é dona do castelo.")
            end
        else
            doPlayerSendCancel(cid, "[CoH] Você deve aguardar "..tostring(math.ceil((getPlayerStorageValue(cid, COH_PUSHSTOR) - os.time()) / 60)).." minuto(s) para usar este comando.")
        end
    else
        doPlayerSendCancel(cid, "[CoH] Você deve ser líder de uma guild para executar este comando.")
    end
    return true
end

function getMembersOnline(id)
    local mbr = {}

    for index, creature in ipairs(getOnlinePlayers()) do
        if getPlayerGuildId(creature) == id then
            if getCreatureSkullType(creature) < 3 then
                table.insert(mbr, creature)
            end
        end
    end
    return mbr or #mbr
end
 
Caslte War?
the scripts are ready to use.. just take and paste your server..
 
Poderia tentar assim?

lib folder:
Lua:
COH_PUSHTIME = 10800
COH_AREA = {{x = 11107, y = 1104, z = 7}, {x = 1109, y = 1106, z = 7}}

COH_STATUS = 201320111714
COH_PREPARE1 = 201320111715
COH_PUSHSTOR = 201320111716
COH_PREPARE2 = 201320111717

function guildVencedora()
    local name
    local consulta = db.getResult("SELECT `guild` FROM `castelo_guerra` ORDER BY `id` DESC;")
    if (consulta:getID() ~= -1) then
        name = tonumber(consulta:getDataInt('guild'))
    else
        return 0
    end
    return name
end

function doCastleRemoveEnemies()
    for index, creature in ipairs(getOnlinePlayers()) do
        if isInArea(getThingPos(creature), COH_AREA[1], COH_AREA[2]) then
            if (guildVencedora() ~= getPlayerGuildId()) then
                doTeleportThing(creature, getTownTemplePosition(getPlayerTown(creature)))
            end
        end
    end
    return true
end

movements folder:




Code:
function onStepIn(cid, item, pos, fromPosition)
    local pos = getThingPos(cid)

    if item.actionid == 16203 then
        if not isPlayer(cid) then
            return true
        end
        if (getPlayerGuildId() == guildVencedora()) then
            doSendMagicEffect(getThingPos(cid), 14)
            doSendAnimatedText(pos, "CW", math.random(1, 255))
        else
            doSendMagicEffect(getThingPos(cid), 2)
            doTeleportThing(cid, fromPosition, false)
            doPlayerSendCancel(cid, "[CASTLE WAR 24H] Você não pertence à guild dominante.")
        end
        return true
    end

    if item.actionid == 16202 then
        if not isPlayer(cid) then
            return true
        end

        if getPlayerGuildId() > 0 then
            if (getPlayerGuildId() == guildVencedora()) then
                doPlayerSendCancel(cid, "[CASTLE WAR 24H] Sua guild já está dominando.")
                return false
            end

            if (getPlayerGuildId() ~= guildVencedora()) and (getPlayerLevel(cid) >= 100) then
                doPlayerSendTextMessage(cid, 20, "[CASTLE WAR 24H] Você e sua guild estão no comando, os antigos donos podem se vingar!")
                setGlobalStorageValue(COH_PREPARE1, -1)
                setGlobalStorageValue(COH_PREPARE2, -1)
                db.query("INSERT INTO `castelo_guerra` (`guild`) VALUES (" .. getPlayerGuildId() .. ");")
                doCastleRemoveEnemies()
                doBroadcastMessage("[CASTLE WAR 24H] O jogador ["..getCreatureName(cid).."] e sua guild ["..getPlayerGuildName().."] estão no comando do castelo, vá dominar e impedir isso!")
            end
        else
            doSendMagicEffect(pos, 2)
            doTeleportThing(cid, fromPosition, false)
            doPlayerSendCancel(cid, "[CASTLE WAR 24H] Você não possui uma guild.")
        end
        return true
    end

    if item.actionid == 16200 then
        if not isPlayer(cid) then
            return true
        end
        if getPlayerGuildId() > 0 then
            doSendAnimatedText(pos, "CW", math.random(1, 255))
            if (getPlayerGuildId() == guildVencedora()) and (getGlobalStorageValue(COH_PREPARE1) ~= getPlayerGuildName()) and ((getGlobalStorageValue(COH_PREPARE2) ~= getPlayerGuildName())) then
                setGlobalStorageValue(COH_PREPARE1, getPlayerGuildName())
                doBroadcastMessage("[CASTLE WAR 24H] Atenção! A guild "..getPlayerGuildName().." está tentando dominar o castelo, preparem-se!")
            end
        else
            doSendMagicEffect(pos, 2)
            doTeleportThing(cid, fromPosition, false)
            doPlayerSendCancel(cid, "[CASTLE WAR 24H] Você não possui uma guild.")
            return true
        end
    end

    if item.actionid == 16201 then
        if not isPlayer(cid) then
            return true
        end
        doSendAnimatedText(pos, "CW", math.random(1, 255))
        if (getPlayerGuildId() == guildVencedora()) and (getGlobalStorageValue(COH_PREPARE2) ~= getPlayerGuildName()) then
            setGlobalStorageValue(COH_PREPARE2, getPlayerGuildName())
            doBroadcastMessage("[CASTLE WAR 24H] Atenção! A guild "..getPlayerGuildName().." está muito próxima do domínio, ataquem!")
        end
        return true
    end
end

talkactions folder:

Code:
function onSay(cid, words, param)
    if getPlayerGuildLevel(cid) == GUILDLEVEL_LEADER then
        if getPlayerStorageValue(cid, COH_PUSHSTOR) < os.time() then
            if (getPlayerGuildId() == guildVencedora()) then
                if isInArea(getThingPos(cid), COH_AREA[1], COH_AREA[2]) then
                    local guildMembersOnline = getMembersOnline(getPlayerGuildId())
                    if #guildMembersOnline > 0 then
                        for index, creature in ipairs(guildMembersOnline) do
                            if (getTileInfo(getThingPos(creature)).protection ~= true) then
                                return doPlayerSendCancel(cid, "[CoH] Os membros devem estar em área PZ.")
                            end
                            doTeleportThing(creature, getThingPos(cid))
                        end
                        setPlayerStorageValue(cid, COH_PUSHSTOR, os.time() + COH_PUSHTIME)
                        doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "[Castle of Honor] Você teleportou seus membros, comando pode ser usado a cada "..tostring(COH_PUSHTIME / 60).." minuto(s).")
                    else
                        doPlayerSendCancel(cid, "[CoH] Para executar isso, sua guild deve ter 2 ou mais membros online.")
                    end
                else
                    doPlayerSendCancel(cid, "[CoH] Você deve estar no castelo.")
                end
            else
                doPlayerSendCancel(cid, "[CoH] Sua guild não é dona do castelo.")
            end
        else
            doPlayerSendCancel(cid, "[CoH] Você deve aguardar "..tostring(math.ceil((getPlayerStorageValue(cid, COH_PUSHSTOR) - os.time()) / 60)).." minuto(s) para usar este comando.")
        end
    else
        doPlayerSendCancel(cid, "[CoH] Você deve ser líder de uma guild para executar este comando.")
    end
    return true
end

function getMembersOnline(id)
    local mbr = {}

    for index, creature in ipairs(getOnlinePlayers()) do
        if getPlayerGuildId(creature) == id then
            if getCreatureSkullType(creature) < 3 then
                table.insert(mbr, creature)
            end
        end
    end
    return mbr or #mbr
end
Dont work
Post automatically merged:

Caslte War?
the scripts are ready to use.. just take and paste your server..
I'll try to adapt it to the other castle map, thx
 
Caslte War?
the scripts are ready to use.. just take and paste your server..
hey friend, I had a small error, could you help me? I have this message in the console , grateful!
using tfs 1.4.2

Lua Script Error: [GlobalEvent Interface]
data/globalevents/scripts/events/castle/start.lua:eek:nTime
data/globalevents/scripts/events/castle/start.lua:22: attempt to call field 'sdate' (a nil value)
stack traceback:
[C]: in function 'sdate'
data/globalevents/scripts/events/castle/start.lua:22: in function <data/globalevents/scripts/events/castle/start.lua:21>
 
hey friend, I had a small error, could you help me? I have this message in the console , grateful!
using tfs 1.4.2

Lua Script Error: [GlobalEvent Interface]
data/globalevents/scripts/events/castle/start.lua:eek:nTime
data/globalevents/scripts/events/castle/start.lua:22: attempt to call field 'sdate' (a nil value)
stack traceback:
[C]: in function 'sdate'
data/globalevents/scripts/events/castle/start.lua:22: in function <data/globalevents/scripts/events/castle/start.lua:21>
try.
Lua:
local config = {
    semana_mes = "semana",
    days = {1, 2, 3, 4, 5, 6, 7},
}

local function warnEvent(i, minutes)
    Game.broadcastMessage("[Castle]\nThe event will begin in " .. minutes .. " minutes! The teleport is located at event room.")
    if i > 1 then
        addEvent(warnEvent, 2 * 60 * 1000, i - 1, minutes - 2)
    end
end

local function openCastle()
    Castle:Open()
end

local function closeCastle()
    Castle:Close()
end

function onTime(interval)
    local time = os.date("*t")
    if (config.semana_mes == "semana" and isInArray(config.days, time.wday)) or
       (config.semana_mes == "mes" and isInArray(config.days, time.day)) or
       config.semana_mes == "" then
        Game.broadcastMessage("[Castle]\nThe event will begin in 10 minutes! The teleport is located at event room.")
        addEvent(warnEvent, 2 * 60 * 1000, 4, 8)
        addEvent(openCastle, 10 * 60 * 1000)
        addEvent(closeCastle, (10 + 10) * 60 * 1000)
    end
    return true
end
 
Yes, I did that, this error came out and this one appeared, grateful!

this is the error
Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
data/lib/events/castle.lua:148: attempt to index a nil value
stack traceback:
[C]: in function '__index'
data/lib/events/castle.lua:148: in function 'Close'
data/globalevents/scripts/events/castle/start.lua:18: in function <data/globalevents/scripts/events/castle/start.lua:17>
 
Last edited:
Back
Top