• 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!

help with script "open gates"

kite28

Member
Joined
May 15, 2012
Messages
69
Reaction score
5
hello, I have a little problem with the code because I found it somewhere on the Internet, I'm trying to implement it into tfs 1.4.2 and unfortunately it doesn't work, I'm a beginner scripter who is still learning, could someone help me with it?




local BUFF_SUBID = 1

local Storages = {
LeeBuffExhaust = "LeeBuffExhaust"
}

local SKILL_TAIJUTSU = 1
local CONDITION_PARAM_SKILL_FIST = 590
local CONDITION_PARAM_SKILL_AXE = 591

local c = {
exhaustTime = 30000, -- tempo do exausted pra usar denovo ao fechar
gateInfo = {
[1] = {
onUseSay = {"KAIMON!", 56},
neededSkill = {SKILL_TAIJUTSU, 10},
hitDamage = 20,
hitDelay = 1000,
stopInHealthPercent = 10,
outfit = 138,
effect = {425, {1, 0}},
effectDelay = 500,
damageMultiplier = 1.10,
speedMultiplier = 1.20,
giveSkills = {
[CONDITION_PARAM_SKILL_FIST] = 5,
[CONDITION_PARAM_SKILL_AXE] = 5
},
},
[2] = {
onUseSay = {"KYUUMON!", 56},
neededSkill = {SKILL_TAIJUTSU, 25},
hitDamage = 30,
hitDelay = 1000,
stopInHealthPercent = 10,
outfit = 139,
effect = {425, {1, 0}},
effectDelay = 500,
damageMultiplier = 1.20,
speedMultiplier = 1.40,
giveSkills = {
[CONDITION_PARAM_SKILL_FIST] = 8,
[CONDITION_PARAM_SKILL_AXE] = 8
},
},
[3] = {
onUseSay = {"SEIMON!", 56},
neededSkill = {SKILL_TAIJUTSU, 40},
hitDamage = 40,
hitDelay = 1000,
stopInHealthPercent = 10,
outfit = 140,
effect = {425, {1, 0}},
effectDelay = 500,
damageMultiplier = 1.30,
speedMultiplier = 1.60,
giveSkills = {
[CONDITION_PARAM_SKILL_FIST] = 12,
[CONDITION_PARAM_SKILL_AXE] = 12
},
},
[4] = {
onUseSay = {"SHOOMON!", 56},
neededSkill = {SKILL_TAIJUTSU, 60},
hitDamage = 50,
hitDelay = 1000,
stopInHealthPercent = 10,
outfit = 141,
effect = {425, {1, 0}},
effectDelay = 500,
damageMultiplier = 1.40,
speedMultiplier = 1.80,
giveSkills = {
[CONDITION_PARAM_SKILL_FIST] = 15,
[CONDITION_PARAM_SKILL_AXE] = 15
},
},
[5] = {
onUseSay = {"TOMON!", 56},
neededSkill = {SKILL_TAIJUTSU, 70},
hitDamage = 75,
hitDelay = 1000,
stopInHealthPercent = 10,
outfit = 142,
effect = {425, {1, 0}},
effectDelay = 500,
damageMultiplier = 1.50,
speedMultiplier = 2.00,
giveSkills = {
[CONDITION_PARAM_SKILL_FIST] = 20,
[CONDITION_PARAM_SKILL_AXE] = 20
},
},
[6] = {
onUseSay = {"KEIMON!", 56},
neededSkill = {SKILL_TAIJUTSU, 80},
hitDamage = 100,
hitDelay = 1000,
stopInHealthPercent = 10,
outfit = 143,
effect = {425, {1, 0}},
effectDelay = 500,
damageMultiplier = 1.60,
speedMultiplier = 2.20,
giveSkills = {
[CONDITION_PARAM_SKILL_FIST] = 24,
[CONDITION_PARAM_SKILL_AXE] = 24
},
},
[7] = {
onUseSay = {"KYOOMON!", 56},
neededSkill = {SKILL_TAIJUTSU, 100},
hitDamage = 150,
hitDelay = 1000,
stopInHealthPercent = 10,
outfit = 144,
effect = {424, {1, 0}},
effectDelay = 500,
damageMultiplier = 1.70,
speedMultiplier = 2.50,
giveSkills = {
[CONDITION_PARAM_SKILL_FIST] = 30,
[CONDITION_PARAM_SKILL_AXE] = 30
},
},
[8] = {
onUseSay = {"HACHIMON!", 56},
neededSkill = {SKILL_TAIJUTSU, 140},
hitDamage = 200,
hitDelay = 1000,
stopInHealthPercent = 0,
outfit = 145,
effect = {426, {1, 0}},
effectDelay = 500,
damageMultiplier = 1.80,
speedMultiplier = 3.00,
giveSkills = {
[CONDITION_PARAM_SKILL_FIST] = 40,
[CONDITION_PARAM_SKILL_AXE] = 40
},
}
}
}

local gateHandler = {}
local conditions = {}

for n, i in ipairs(c.gateInfo) do
conditions[n] = {}
if (i.giveSkills) then
local attributesCondition = Condition(CONDITION_ATTRIBUTES, -1, true, BUFF_SUBID)
for paramId, value in pairs(i.giveSkills) do
Condition.setParameter(attributesCondition, paramId, value)
end
conditions[n][#conditions[n] + 1] = attributesCondition
end

if (i.speedMultiplier) then
local speedCondition = Condition(CONDITION_HASTE, -1, true, BUFF_SUBID)
Condition.setFormula(speedCondition, i.speedMultiplier, 0, i.speedMultiplier, 0)
conditions[n][#conditions[n] + 1] = speedCondition
end
end

local function closeGates(cid, full)
if (isCreature(cid)) then
player:removeCondition(cid, CONDITION_ATTRIBUTES, BUFF_SUBID)
player:removeCondition(cid, CONDITION_HASTE, BUFF_SUBID)
player:removeCondition(cid, CONDITION_OUTFIT, 0)
if (full) then
Game.sendAnimatedText("KAI!", position, 215)
doCreatureEraseStorage(cid, Storages.LeeBuff)
timeStorage.set(cid, Storages.LeeBuffExhaust, c.exhaustTime)
gateHandler[cid] = nil
end
end
end

local function hitHealthEvent(cid, serial)
if (isCreature(cid)) then
local handler = gateHandler[cid]
if (not handler or handler.serial ~= serial) then
return
end

local hitDamage = handler.hitHealthStack + handler.gateInfo.hitDamage
local stopInHealthPercent = handler.gateInfo.stopInHealthPercent
if (stopInHealthPercent > 0 and getCreatureHealthPercent(cid, hitDamage) <= stopInHealthPercent) then
closeGates(cid, true)
return
end

player:addHealth(cid, -hitDamage)
gateHandler[cid].hitHealthStack = hitDamage
addEvent(hitHealthEvent, handler.gateInfo.hitDelay, cid, serial)
else
gateHandler[cid] = nil
end
end

local function sendEffectEvent(cid, serial)
if (isCreature(cid)) then
local handler = gateHandler[cid]
if (not handler or handler.serial ~= serial) then
return
end

doSendMagicEffectWithOffset(getThingPosition(cid), handler.gateInfo.effect[1], handler.gateInfo.effect[2])
addEvent(sendEffectEvent, handler.gateInfo.effectDelay, cid, serial)
end
end

function onCastSpell(cid, var)
local player = Player(cid)
local param = var.string:lower()
if (param == "kai") then
if (gateHandler[cid]) then
closeGates(cid, true)
return true
else
player:sendCancelMessageWithEffect(cid, "You do not have any gate open.", CONST_ME_POFF)
return false
end
end

local gateNumber = tonumber(param)
local i = c.gateInfo[gateNumber]
if (i) then
if (timeStorage.has(cid, Storages.LeeBuffExhaust)) then
player:sendCancelMessageWithEffect(cid, "Wait for the cooldown [" .. timeStorage.getCooldown(cid, Storages.LeeBuffExhaust) .. "s].", CONST_ME_POFF)
return false
end

if (getPlayerSkill(cid, i.neededSkill[1]) < i.neededSkill[2]) then
player:sendCancelMessageWithEffect(cid, "You do not have enough " .. SKILL_NAMES[i.neededSkill[1]] .. " (needed: " .. i.neededSkill[2] .. ").", CONST_ME_POFF)
return false
end

local startHitStack = 0
local previousGate = gateHandler[cid]
if (previousGate) then
if (previousGate.gateInfo == i) then
player:sendCancelMessageWithEffect(cid, "You are already with this gate open.", CONST_ME_POFF)
return false
end

startHitStack = previousGate.hitHealthStack
closeGates(cid, false)
end

if (i.onUseSay) then
Game.sendAnimatedText(getThingPosition(cid), i.onUseSay[1], i.onUseSay[2])
end

if (i.outfit) then
player:eek:utfit(cid, {lookType = i.outfit}, -1)
end

local newSerial = genSerial()
gateHandler[cid] = {hitHealthStack = startHitStack, gateInfo = i, serial = newSerial}
player:setStorageValue(cid, Storages.LeeBuff, i.damageMultiplier)
sendEffectEvent(cid, newSerial)
hitHealthEvent(cid, newSerial)
for _, condition in ipairs(conditions[gateNumber]) do
player:addCondition(cid, condition)
end
return true
else
player:sendCancelMessageWithEffect(cid, "How to use: \"open gates kai\", \"open gates 1\", \"open gates 2\"...", CONST_ME_POFF)
end
return false
end
 
I haven't tested it, come back and let me know if it worked.

Lua:
local BUFF_SUBID = 1

local Storages = {
    LeeBuffExhaust = "LeeBuffExhaust"
}

local SKILL_TAIJUTSU = 1
local CONDITION_PARAM_SKILL_FIST = 590
local CONDITION_PARAM_SKILL_AXE = 591

local c = {
    exaustoTime = 30000, -- tempo do exausted para usar novamente ao fechar
    gateInfo = {
        [1] = {
            onUseSay = {"KAIMON!", 56},
            needSkill = {SKILL_TAIJUTSU, 10},
            hitDamage = 20,
            hitDelay = 1000,
            stopInHealthPercent = 10,
            outfit = 138,
            effect = {425, {1, 0}},
            effectDelay = 500,
            damageMultiplier = 1.10,
            speedMultiplier = 1.20,
            giveSkills = {
                [CONDITION_PARAM_SKILL_FIST] = 5,
                [CONDITION_PARAM_SKILL_AXE] = 5
            },
        },
        -- Insira as outras configurações aqui
    }
}

local gateHandler = {}
local conditions = {}

for n, i in ipairs(c.gateInfo) do
    conditions[n] = {}
    if (i.giveSkills) then
        local attributesCondition = Condition(CONDITION_ATTRIBUTES, -1, nil, BUFF_SUBID)
        for paramId, value in pairs(i.giveSkills) do
            Condition.setParameter(attributesCondition, paramId, value)
        end
        conditions[n][#conditions[n] + 1] = attributesCondition
    end

    if (i.speedMultiplier) then
        local speedCondition = Condition(CONDITION_HASTE, -1, nil, BUFF_SUBID)
        Condition.setFormula(speedCondition, i.speedMultiplier, -1, i.speedMultiplier, -1)
        conditions[n][#conditions[n] + 1] = speedCondition
    end
end

function closeGates(cid, full)
    if (isCreature(cid)) then
        player:removeCondition(cid, CONDITION_ATTRIBUTES, BUFF_SUBID)
        player:removeCondition(cid, CONDITION_HASTE, BUFF_SUBID)
        player:removeCondition(cid, CONDITION_OUTFIT, 0)
        if (full) then
            Game.sendAnimatedText("KAI!", getCreaturePosition(cid), 215)
            doCreatureSetStorage(cid, Storages.LeeBuff, -1)
            doCreatureEraseStorage(cid, Storages.LeeBuff)
            timeStorage.set(cid, Storages.LeeBuffExhaust, c.exhaustTime)
            gateHandler[cid] = nil
        end
    end
end

local function hitHealthEvent(cid, serial)
    if (isCreature(cid)) then
        local handler = gateHandler[cid]
        if (not handler or handler.serial ~= serial) then
            return
        end

        local hitDamage = handler.hitHealthStack + handler.gateInfo.hitDamage
        local stopInHealthPercent = handler.gateInfo.stopInHealthPercent
        if (stopInHealthPercent > 0 and getCreatureHealthPercent(cid) <= stopInHealthPercent) then
            closeGates(cid, true)
            return
        end

        doCreatureAddHealth(cid, -hitDamage)
        gateHandler[cid].hitHealthStack = hitDamage
        addEvent(hitHealthEvent, handler.gateInfo.hitDelay, cid, serial)
    else
        gateHandler[cid] = nil
    end
end

local function sendEffectEvent(cid, serial)
    if (isCreature(cid)) then
        local handler = gateHandler[cid]
        if (not handler or handler.serial ~= serial) then
            return
        end

        doSendMagicEffect(getCreaturePosition(cid), handler.gateInfo.effect[1], handler.gateInfo.effect[2])
        addEvent(sendEffectEvent, handler.gateInfo.effectDelay, cid, serial)
    end
end

function onCastSpell(cid, var)
    local player = Player(cid)
    local param = var:getString():lower()
    if (param == "kai") then
        if (gateHandler[cid]) then
            closeGates(cid, true)
            return true
        else
            player:sendCancelMessageWithEffect("Você não tem nenhum portão aberto.", CONST_ME_POFF)
            return false
        end
    end

    local gateNumber = tonumber(param)
    local i = c.gateInfo[gateNumber]
    if (i) then
        if (timeStorage.has(cid, Storages.LeeBuffExhaust)) then
            player:sendCancelMessageWithEffect("Aguarde o resfriamento [" .. timeStorage.get(cid, Storages.LeeBuffExhaust) .. "s].", CONST_ME_POFF)
            return false
        end

        if (getPlayerSkillLevel(cid, i.needSkill[1]) < i.needSkill[2]) then
            player:sendCancelMessageWithEffect("Você não tem habilidade " .. SKILL_NAMES[i.needSkill[1]] .. " suficiente (necessário: " .. i.needSkill[2] .. ").", CONST_ME_POFF)
            return false
        end

        local startHitStack = 0
        local previousGate = gateHandler[cid]
        if (previousGate) then
            if (previousGate.gateInfo == i) then
                player:sendCancelMessageWithEffect("Você já está com este portão aberto.", CONST_ME_POFF)
                return false
            end
            startHitStack = previousGate.hitHealthStack
            closeGates(cid, false)
        end

        if (i.onUseSay) then
            Game.sendAnimatedText(getCreaturePosition(cid), i.onUseSay[1], i.onUseSay[2])
        end

        if (i.outfit) then
            player:setOutfit(i.outfit, -1)
        end

        local newSerial = genSerial()
        gateHandler[cid] = {hitHealthStack = startHitStack, gateInfo = i, serial = newSerial}
        doCreatureSetStorage(cid, Storages.LeeBuff, i.damageMultiplier)
        sendEffectEvent(cid, newSerial)
        hitHealthEvent(cid, newSerial)
        for _, condition in ipairs(conditions[gateNumber]) do
            player:addCondition(condition)
        end
        return true
    else
        player:sendCancelMessageWithEffect("Como usar: \"portões abertos kai\", \"portões abertos 1\", \"portões abertos 2\"...", CONST_ME_POFF)
    end
    return false
end
 
Last edited by a moderator:
[Warning - Event::checkScript] Can not load script: scripts/postacie/lee/open_gates.lua
data/spells/scripts/postacie/lee/open_gates.lua:159: function arguments expected near 'endCancelMessageWithEffect'
i change
Lua:
else
player:s
endCancelMessageWithEffect("Como usar: \"portões abertos kai\", \"portões abertos 1\", \"portões abertos 2\"...", CONST_ME_POFF)
end
to
Code:
else
    player:sendCancelMessageWithEffect("Como usar: \"portões abertos kai\", \"portões abertos 1\", \"portões abertos 2\"...", CONST_ME_POFF)
end

and now i have this error :
Code:
Lua Script Error: [Spell Interface]
data/spells/scripts/postacie/lee/open_gates.lua:onCastSpell
data/spells/scripts/postacie/lee/open_gates.lua:158: attempt to call method 'sendCancelMessageWithEffect' (a nil value)
 
i change
Lua:
else
player:s
endCancelMessageWithEffect("Como usar: \"portões abertos kai\", \"portões abertos 1\", \"portões abertos 2\"...", CONST_ME_POFF)
end
to
Code:
else
    player:sendCancelMessageWithEffect("Como usar: \"portões abertos kai\", \"portões abertos 1\", \"portões abertos 2\"...", CONST_ME_POFF)
end

and now i have this error :
Code:
Lua Script Error: [Spell Interface]
data/spells/scripts/postacie/lee/open_gates.lua:onCastSpell
data/spells/scripts/postacie/lee/open_gates.lua:158: attempt to call method 'sendCancelMessageWithEffect' (a nil value)
change where is:

sendCancelMessageWithEffect

to:

sendCancelMessage

or simply add this function in the script in line 1

Lua:
local function Player.sendCancelMessageWithEffect(self, message, effect)
    self:sendCancelMessage(message)
    self:getPosition():sendMagicEffect(effect)
end
 
change where is:



to:



or simply add this function in the script in line 1

Lua:
local function Player.sendCancelMessageWithEffect(self, message, effect)
    self:sendCancelMessage(message)
    self:getPosition():sendMagicEffect(effect)
end
after the change there is no error but nothing happens either. "Como usar: \"portões abertos kai\", \"portões abertos 1\", \"portões abertos 2\" is displayed at the bottom of the game screen. but when I type open gates or open gates 1, open gates kai nothing happens

Or:
Alternatively, would someone be able to write such a script for me? the idea is to enter "open gates" and the gate opens until you meet the requirements, e.g. here is taijutsu. if you don't have taijutsu, you stay at the currently open gate and you can't enter the gate any further
 
Last edited:
Back
Top