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

cast spell onUse toPosition

Tormented

Member
Joined
Jan 13, 2024
Messages
33
Reaction score
13
Lua:
local combat = Combat()

combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_HOLYDAMAGE)

combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)

combat:setArea(createCombatArea(AREA_SQUARE1X1))



function onGetFormulaValues(player, skill, attack, factor)

    local min = 1

    local max = 1

    return -min, -max

end



combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")



local function onCastSpell(creature, variant)

    return combat:execute(creature, variant)

end

 onCastSpell(player, numberToVariant(player:getId()))





function onUse(player, item, fromPosition, target, toPosition, isHotkey)


how can i cast the spell onto toPosition with onUse?>
 
You must convert toPosition (item target position) to Variant with type VARIANT_TARGETPOSITION:
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_HOLYDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
combat:setArea(createCombatArea(AREA_SQUARE1X1))

function onGetFormulaValues(player, skill, attack, factor)
    local min = 1
    local max = 1
    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local variant = Variant(toPosition)

    return combat:execute(player, variant)
end
 
Last edited:
why no onCastSpell ? ah yeah cuz its just function that calls combat function my bad...

didnt work actually

Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_HOLYDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
combat:setArea(createCombatArea(AREA_SQUARE1X1))

function onGetFormulaValues(player, skill, attack, factor)
    local min = 1
    local max = 1
    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

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

local function kopanko(player, item, fromPosition, target, toPosition, isHotkey)
    local USES_STORAGE = 2554
    local REAL_USES = 25541
    local howmany = player:getStorageValue(REAL_USES)
    local uses = player:getStorageValue(USES_STORAGE) + 1
    player:setStorageValue(USES_STORAGE, uses)
    player:setStorageValue(REAL_USES, player:getStorageValue(REAL_USES) + 1)

 

    -- Cast the holy damage spell
    onCastSpell(player, numberToVariant(player:getId()))

    -- Check if the player has used the item 10000 times, and reward them with random exp if true
    if uses % 10000 == 0 then
        local reward = math.random(100, 200)
        player:setStorageValue(55656, player:getStorageValue(55656) + 1)
        player:addExperience(reward, true)
     
        player:setStorageValue(USES_STORAGE, 0)
        player:getPosition():sendMagicEffect(24)
    end
end

or i dont know how to use it here is full code.
 
why no onCastSpell ?
For 'spell' scripts C++ calls Lua onCastSpell(creature, variant).
For 'action use' scripts C++ calls Lua onUse function. You get a lot of params, we need to convert toPosition to Variant type, to make it work with combat:execute(creature, variant).

I've edited my code in post above. Removed variant.type = VARIANT_TARGETPOSITION. Now it should work.
 
Last edited:
Back
Top