• 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 Help with sendMagicEffect appearing on the player

Icaraii

Well-Known Member
Joined
Jan 5, 2020
Messages
469
Solutions
1
Reaction score
58
I have this spell, that is a summon bomb and it works perfectly. However, when I put sprites bigger than 32x32, I need to put offset (x,y) for the effect to appear where I want, but when I do this, the effect is appearing on the caster, instead of appearing where the summon died. What am I doing wrong?

spell.lua:
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setArea(createCombatArea(AREA_SQUARE1X1))
combat:setParameter(COMBAT_PARAM_BLOCKARMOR, true)
combat:setParameter(COMBAT_PARAM_BLOCKSHIELD, true)

function onGetFormulaValues(player, skill, attack, skill, factor)
    local maxHealth = player:getMaxHealth()
    local maxMana = player:getMaxMana()
    local playlvl = player:getLevel()
    
    local min = ((playlvl < 300 and playlvl or 300) + ((maxHealth + maxMana) / 16) + (attack * 4) + (skill * 2)) * 0,55
    local max = ((playlvl < 300 and playlvl or 300) + ((maxHealth + maxMana) / 16) + (attack * 4) + (skill * 2)) * 1,1
    
    return -min, -max   
end
combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")


function onCastSpell(cid, var)
    local player = Player(cid)
    if player == nil then
        return false
    end
 
    local playerPos = player:getPosition()
    if #player:getSummons() >= 2 then
        player:sendCancelMessage("You cannot summon more creatures.")
        playerPos:sendMagicEffect(CONST_ME_POFF)
        return false
    end

    local creatureId = doSummonCreature("Barrelbomb", playerPos)
    if creatureId == false then
        player:sendCancelMessage(RET_NOTENOUGHROOM)
        playerPos:sendMagicEffect(CONST_ME_POFF)
        return false
    end

    local monster = Monster(creatureId)
    monster:setMaster(player)
    monster:registerEvent("barrelbomb")

    addEvent(function(cid)
        local creature = Creature(cid)
        if creature ~= nil then
            local player = creature:getMaster()
            if player then
                combat:execute(player, numberToVariant(cid))
            else
                combat:execute(creature, numberToVariant(cid))
            end
            local creaturePos = creature:getPosition()
            creaturePos.x = creaturePos.x +1
            creaturePos.y = creaturePos.y +1
            creaturePos:sendMagicEffect(122)
            creature:remove()
        end
    end, 5000, creatureId)

    monster:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
    playerPos:sendMagicEffect(CONST_ME_MAGIC_BLUE)
    return true
end

creaturescript.lua:
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setArea(createCombatArea(AREA_SQUARE1X1))
combat:setParameter(COMBAT_PARAM_BLOCKARMOR, true)
combat:setParameter(COMBAT_PARAM_BLOCKSHIELD, true)

function onGetFormulaValues(player, skill, attack, skill, factor)
    local maxHealth = player:getMaxHealth()
    local maxMana = player:getMaxMana()
    local playlvl = player:getLevel()
    
    local min = ((playlvl < 300 and playlvl or 300) + ((maxHealth + maxMana) / 16) + (attack * 4) + (skill * 2)) * 0,55
    local max = ((playlvl < 300 and playlvl or 300) + ((maxHealth + maxMana) / 16) + (attack * 4) + (skill * 2)) * 1,1
    
    return -min, -max   
end
combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

function onDeath(creature, variant, cid, ...)
    local creature = Creature(cid)
    local master = creature:getMaster()
    if master then
        combat:execute(master, numberToVariant(cid))
    else
        combat:setFormula(COMBAT_FORMULA_DAMAGE, -10, 0, -20, 0)
        local creaturePos = creature:getPosition()
        creaturePos.x = creaturePos.x +1
        creaturePos.y = creaturePos.y +1
        creaturePos:sendMagicEffect(122)
        combat:execute(creature, numberToVariant(cid))
    end
    return true
end
 
Good job doing it yourself. Next time if you don't know how to do something try searching something similar here on otland and simply edit it. That's how I started.
That was what I did. I always try to do it by myself, but many times I'm not able to solve them by myself. But you guys here at otland always help me solve the problems and promote knowledge, you guys are great.
 
Back
Top