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

Hugo Patriota

Atzosh.com
Joined
Nov 23, 2016
Messages
29
Solutions
1
Reaction score
2
I need help in this script, I need the player to stay 5 seconds stopped after 5 seconds it can walk * TFS 1.3

http://pastebin.com/05RAnvFL
Lua:
local config = {
    manaCost = 1000,
    timeRemoval = 5
}

local combat = createCombatObject()
    setCombatParam(combat, COMBAT_PARAM_TARGETCASTERORTOPMOST, true)
    setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
    setCombatParam(combat, COMBAT_PARAM_BLOCKSHIELD, 1)
    setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
    setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_STUN)
    setCombatFormula(combat, COMBAT_FORMULA_SKILL, 0, 0, 1.0, 0)

function onCastSpell(cid, var)
    local target = variantToNumber(var)
    local exhausted = createConditionObject(CONDITION_EXHAUST)
    setConditionParam(exhausted, CONDITION_PARAM_TICKS,5000)
   
    getPlayerPosition(target, true)
    addEvent(getPlayerPosition, config.timeRemoval * 1000, target, false)
   
    return doCombat(cid, combat, var)
end
 
Last edited by a moderator:
use code tags:
https://otland.net/threads/how-to-display-code-properly-in-your-post.168098/

The player metatable is part of the creature metatable.

https://github.com/otland/forgottenserver/wiki/Metatable:Creature
changeSpeed(delta)
getSpeed()

Lua:
local config = {
    manaCost = 1000,
    timeRemoval = 5
}

local combat = createCombatObject()
    setCombatParam(combat, COMBAT_PARAM_TARGETCASTERORTOPMOST, true)
    setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
    setCombatParam(combat, COMBAT_PARAM_BLOCKSHIELD, 1)
    setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
    setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_STUN)
    setCombatFormula(combat, COMBAT_FORMULA_SKILL, 0, 0, 1.0, 0)

function onCastSpell(cid, var)
    local target = variantToNumber(var)
    local exhausted = createConditionObject(CONDITION_EXHAUST)
    setConditionParam(exhausted, CONDITION_PARAM_TICKS,5000)
  
    getPlayerPosition(target, true)
    addEvent(getPlayerPosition, config.timeRemoval * 1000, target, false)
  
    local player = Player(cid)
    local playerspeed = player:getSpeed()
    player:changeSpeed(-playerspeed) -- or perhaps player:changeSpeed(0)
    addEvent(player:changeSpeed, config.timeRemoval * 1000, playerspeed)
  
    return doCombat(cid, combat, var)
end
 
[Warning - Event::checkScript] Can not load script: scripts/pbot/exori stun.lua
data/spells/scripts/pbot/exori stun.lua:25: function arguments expected near ','
 
Perhaps the addevent didnt like to call a function in a Player metatable. Lets try to create a function and re-initialize the player there after 5 seconds.
Lua:
local config = {
    manaCost = 1000,
    timeRemoval = 5
}

local combat = createCombatObject()
    setCombatParam(combat, COMBAT_PARAM_TARGETCASTERORTOPMOST, true)
    setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
    setCombatParam(combat, COMBAT_PARAM_BLOCKSHIELD, 1)
    setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
    setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_STUN)
    setCombatFormula(combat, COMBAT_FORMULA_SKILL, 0, 0, 1.0, 0)

function speedBackToNormal(cid, speed)
    local player = Player(cid)
    if player ~= nil then
        player:changeSpeed(speed)
    end
end

function onCastSpell(cid, var)
    local target = variantToNumber(var)
    local exhausted = createConditionObject(CONDITION_EXHAUST)
    setConditionParam(exhausted, CONDITION_PARAM_TICKS,5000)

    getPlayerPosition(target, true)
    addEvent(getPlayerPosition, config.timeRemoval * 1000, target, false)

    local player = Player(cid)
    local playerspeed = player:getSpeed()
    player:changeSpeed(-playerspeed) -- or perhaps player:changeSpeed(0)
    addEvent(speedBackToNormal, config.timeRemoval * 1000, cid, playerspeed)

    return doCombat(cid, combat, var)
end
 
i wouldn't go about doing it this way, because it just shows the player moving animation for like a minute and stops there, showing a false position to the client
but if you insist on doing it this way:
Lua:
local config = {
    manaCost = 1000,
    timeRemoval = 5
}

local combat = Combat()
    combat:setParameter(COMBAT_PARAM_TARGETCASTERORTOPMOST, true)
    combat:setParameter(COMBAT_PARAM_BLOCKARMOR, 1)
    combat:setParameter(COMBAT_PARAM_BLOCKSHIELD, 1)
    combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
    combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_STUN)
    combat:setFormula(COMBAT_FORMULA_SKILL, 0, 0, 1.0, 0)

function onCastSpell(creature, variant)
    local target = variantToNumber(variant)
    local exhausted = Condition(CONDITION_EXHAUST)
    exhausted:setParameter(CONDITION_PARAM_TICKS,5000)

    getPlayerPosition(target, true)
    addEvent(getPlayerPosition, config.timeRemoval * 1000, target, false)

    local player = Player(cid)
    local playerspeed = player:getSpeed()
    player:changeSpeed(-playerspeed)
    addEvent(Creature.changeSpeed, config.timeRemoval * 1000, player, playerspeed)

    return combat:execute(creature, variant)
end

@Znote when using the colon it expects that you're actually about to use it at that time, so it expects function arguments.
instead call the function using Creature.changeSpeed

edit:
i should also add that when the speed is changed for the player, if they are already attempting to move and the animation is showing, they won't be able to walk around even if their speed is back to normal because the animation must finish or they have to be pushed.
 
Perhaps the addevent didnt like to call a function in a Player metatable. Lets try to create a function and re-initialize the player there after 5 seconds.
Lua:
local config = {
    manaCost = 1000,
    timeRemoval = 5
}

local combat = createCombatObject()
    setCombatParam(combat, COMBAT_PARAM_TARGETCASTERORTOPMOST, true)
    setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
    setCombatParam(combat, COMBAT_PARAM_BLOCKSHIELD, 1)
    setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
    setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_STUN)
    setCombatFormula(combat, COMBAT_FORMULA_SKILL, 0, 0, 1.0, 0)

function speedBackToNormal(cid, speed)
    local player = Player(cid)
    if player ~= nil then
        player:changeSpeed(speed)
    end
end

function onCastSpell(cid, var)
    local target = variantToNumber(var)
    local exhausted = createConditionObject(CONDITION_EXHAUST)
    setConditionParam(exhausted, CONDITION_PARAM_TICKS,5000)

    getPlayerPosition(target, true)
    addEvent(getPlayerPosition, config.timeRemoval * 1000, target, false)

    local player = Player(cid)
    local playerspeed = player:getSpeed()
    player:changeSpeed(-playerspeed) -- or perhaps player:changeSpeed(0)
    addEvent(speedBackToNormal, config.timeRemoval * 1000, cid, playerspeed)

    return doCombat(cid, combat, var)
end

I do not understand, as I said above the script was working perfectly, today when I got the service it stopped working only thing I changed on the server was actions on levers .. does not make sense

Lua Script Error: [Spell Interface]
data/spells/scripts/pbot/exori stun.lua:eek:nCastSpell
luaAddEvent(). Argument #3 is unsafe
stack traceback:
[C]: in function 'addEvent'
data/spells/scripts/pbot/exori stun.lua:32: in function <data/spells/scripts/pbot/exori stun.lua:21>

Lua Script Error: [Spell Interface]
data/spells/scripts/pbot/exori stun.lua:eek:nCastSpell
luaAddEvent(). Argument #3 is unsafe
stack traceback:
[C]: in function 'addEvent'
data/spells/scripts/pbot/exori stun.lua:32: in function <data/spells/scripts/pbot/exori stun.lua:21>
 
@Xeraphus Could the client position sync issue be fixed by moving the player after 5 seconds? By simulating a push or teleport etc?

@Hugo Patriota Did you try @Xeraphus version? It also appears it does not like passing cid, although I have seen something similar using cid=cid in the addevent to bypass that.
 
I want to try to solve without mending in the source, because as I said the script worked for some reason is not locking the player anymore .. but I will see the version of @Xeraphus
 
@Xeraphus Could the client position sync issue be fixed by moving the player after 5 seconds? By simulating a push or teleport etc?

@Hugo Patriota Did you try @Xeraphus version? It also appears it does not like passing cid, although I have seen something similar using cid=cid in the addevent to bypass that.
it could be but it's not exactly an "ideal" way to go about it
workarounds should be avoided whenever possible
cid in this case is a creature object since he is still using tfs 0.x code style but it's just named cid
the "bypass" is:
Lua:
cid = (type(cid) == "userdata") and cid:getId() or cid
source editing is a good solution assuming he's already learned how to compile, there's already instructions on what to add and where (you don't even have to understand the code)
 
Back
Top