• 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 Spell that pull monster (single target)

Icaraii

Well-Known Member
Joined
Jan 5, 2020
Messages
469
Solutions
1
Reaction score
58
Guy, I would like a spell that pulls the monsters that the player is atacking to the player, max 5 sqm way and check interferences in the way.
For example, if player is surround of monsters and uses the spell into a monster that is far away, he pull the monster as close as it can get.

Also, is it possible to make another spell?! It would be like this:
Player uses spell that last for 30 seconds, every monster that hits the player from more then 2 sqm away, it will be pull close to the player, also checking interferences in the way.

Are those spells possible to be made?
 
up
Post automatically merged:

I found this script on the forum:
local function doPullCreature(target, cid)
if target > 0 then
if not isNpc(target) then
local position = getThingPosition(cid)
local fromPosition = getThingPosition(target)
local x = ((fromPosition.x - position.x) < 0 and 1 or ((fromPosition.x - position.x) == 0 and 0 or -1))
local y = ((fromPosition.y - position.y) < 0 and 1 or ((fromPosition.y - position.y) == 0 and 0 or -1))
local toPosition = {x = fromPosition.x + x, y = fromPosition.y + y, z = fromPosition.z}
if doTileQueryAdd(target, toPosition) == 1 and getTileInfo(toPosition).house == false then
doTeleportThing(target, toPosition, true)
end
end
end
end
local spell = {}
spell.config = {
[3] = {
damageType = 1,
areaEffect = 2,
area = {
{0, 0, 1, 1, 1, 0, 0},
{0, 1, 1, 1, 1, 1, 0},
{1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 3, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1},
{0, 1, 1, 1, 1, 1, 0},
{0, 0, 1, 1, 1, 0, 0}
}
},
[2] = {
damageType = 1,
areaEffect = 2,
area = {
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 1, 1, 1, 0, 0},
{0, 1, 1, 1, 1, 1, 0},
{0, 1, 1, 3, 1, 1, 0},
{0, 1, 1, 1, 1, 1, 0},
{0, 0, 1, 1, 1, 0, 0},
{0, 0, 0, 0, 0, 0, 0}
}
},
[1] = {
damageType = 1,
areaEffect = 2,
area = {
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 1, 1, 1, 0, 0},
{0, 0, 1, 3, 1, 0, 0},
{0, 0, 1, 1, 1, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0}
}
}
}

spell.combats = {}
for _, config in ipairs(spell.config) do
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, config.damageType)
setCombatParam(combat, COMBAT_PARAM_EFFECT, config.areaEffect)
function onTargetCreature(cid, target)
doPullCreature(target, cid)
end
setCombatCallback(combat, CALLBACK_PARAM_TARGETCREATURE, "onTargetCreature")
setCombatArea(combat, createCombatArea(config.area))
table.insert(spell.combats, combat)
end
function onCastSpell(cid, var)
for n = 1, #spell.combats do
addEvent(doCombat, (n * 150) - 150, cid.uid, spell.combats[n], var)
end
return true
end
But it shows a error on my distro:

Lua Script Error: [Spell Interface]
in callback: data/spells/scripts/attack/pull.lua:eek:nTargetCreature
(Unknown scriptfile)
data/spells/scripts/attack/pull.lua:2: attempt to compare number with userdata

Lua Script Error: [Spell Interface]
in callback: data/spells/scripts/attack/pull.lua:eek:nTargetCreature
(Unknown scriptfile)
data/spells/scripts/attack/pull.lua:2: attempt to compare number with userdata

And also I would like to put it single target, so should I replace the script for this?

local function doPullCreature(target, cid)
if target > 0 then
if not isNpc(target) then
local position = getThingPosition(cid)
local fromPosition = getThingPosition(target)
local x = ((fromPosition.x - position.x) < 0 and 1 or ((fromPosition.x - position.x) == 0 and 0 or -1))
local y = ((fromPosition.y - position.y) < 0 and 1 or ((fromPosition.y - position.y) == 0 and 0 or -1))
local toPosition = {x = fromPosition.x + x, y = fromPosition.y + y, z = fromPosition.z}
if doTileQueryAdd(target, toPosition) == 1 and getTileInfo(toPosition).house == false then
doTeleportThing(target, toPosition, true)
end
end
end
end

function onGetFormulaValues(player, level, magicLevel)
local min = (level / 5) + (magicLevel * 1.4) + 8
local max = (level / 5) + (magicLevel * 2.2) + 14
return -min, -max
end

combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(creature, variant)
return combat:execute(creature, variant)
end
But then I got this error:

Lua Script Error: [Test Interface]
data/spells/scripts/attack/pull.lua
data/spells/scripts/attack/pull.lua:21: attempt to index global 'combat' (a nil value)
stack traceback:
[C]: in function '__index'
data/spells/scripts/attack/pull.lua:21: in main chunk
[Warning - Event::checkScript] Can not load script: scripts/attack/pull.lua
 
Last edited:
You just forget define 'combat' so script try to call globall "combat" value.

Lua:
local combat = Combat()
 
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, 246)
combat:setParameter(COMBAT_PARAM_BLOCKARMOR, true)
combat:setParameter(COMBAT_PARAM_BLOCKARMOR, true)

local function doPullCreature(target, cid)
   if target > 0 then
    if not isNpc(target) then
        local position = getThingPosition(cid)
        local fromPosition = getThingPosition(target)
        local x = ((fromPosition.x - position.x) < 0 and 1 or ((fromPosition.x - position.x) == 0 and 0 or -1))
        local y = ((fromPosition.y - position.y) < 0 and 1 or ((fromPosition.y - position.y) == 0 and 0 or -1))
        local toPosition = {x = fromPosition.x + x, y = fromPosition.y + y, z = fromPosition.z}
        if doTileQueryAdd(target, toPosition) == 1 and getTileInfo(toPosition).house == false then
            doTeleportThing(target, toPosition, true)
        end
    end
   end
end

function onGetFormulaValues(player, level, magicLevel)
    local min = (level / 5) + (magicLevel * 1.4) + 8
    local max = (level / 5) + (magicLevel * 2.2) + 14
    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(creature, variant)
    return combat:execute(creature, variant)
end

Ok, I made the changes, but the effect is appearing on myself, and still not pulling the enemy.
 
Last edited:
Back
Top