• 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 check action id onCastSpell()

darkmu

Well-Known Member
Joined
Aug 26, 2007
Messages
274
Solutions
1
Reaction score
50
Location
Paraná,Brazil
TFS 1.4

I'm trying to validate when attacking a rune, check if the rune has the actionID, if it has its attack it will get stronger, can anyone help me?

Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_DEATHDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MORTAREA)
combat:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_SUDDENDEATH)

function onGetFormulaValues(player, level, maglevel)

    -- CONDITION NOT ACTION
    local min = (level / 5) + (maglevel * 4.3) + 35
    local max = (level / 5) + (maglevel * 7.4) + 54

    -- CONDITION ACTION ID
    --local min = (level / 5) + (maglevel * 5.3) + 35
    --local max = (level / 5) + (maglevel * 9.4) + 54
    
    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(creature, var, isHotkey)   
    return combat:execute(creature, var)
end

18:28 You see 3 sudden death runes. They can only be used by players with level 45 and magic level 15 or higher.
They weigh 2.10 oz.
Action ID: 15000
 
but how will he identify that it is an item? in this case I would have to put something for him to identify, right?
you must have an item with actionid in bp or eq and it will work, I use a similar solution on my own.
 
There are 2 options, simple hack and the better one which requires source edits.
1. Create 2nd script, Action script, that will save action id of last used rune which then you can read in spell script. I'm not sure if onUse will execute before onCastSpell tho, so that's up to you to test.
2. Edit sources so it passes one more argument to onCastSpell, used rune item or at least what action id it had (item is probably removed before onCastSpell is executed, not sure).

add it line 11:
Lua:
if actionId == XXXX then
You can't be serious?
 
It may not be what you want but something can be done about it with an Action:
data/scripts/customrune.lua
Lua:
local config = {
    itemId = 2294,
    actionID = 15000,
    distance = 7,
    target = true
}

local multipliers = {
    { min = 4.3, max = 7.4 },
    { min = 5.3, max = 9.4 }
}

local combats = {}
for index, multiplier in pairs(multipliers) do
    local combat = Combat()
    combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_DEATHDAMAGE)
    combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MORTAREA)
    combat:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_SUDDENDEATH)
    function onGetFormulaValues(player, level, maglevel)
        local min = (level / 5) + (maglevel * multiplier.min) + 35
        local max = (level / 5) + (maglevel * multiplier.max) + 54
        return -min, -max
    end
    combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")
    combats[index] = combat
end

local action = Action()

function action.onUse(player, item, fromPos, target, toPos, isHotkey)
    local tile = Tile(toPos)
    if not tile then
        return true
    end
    if config.target and not tile:getTopVisibleCreature(player) then
        player:sendCancelMessage(RETURNVALUE_YOUCANONLYUSEITONCREATURES)
        return true
    end
    if player:getPosition():getDistance(toPos) > config.distance then
        player:sendCancelMessage(RETURNVALUE_DESTINATIONOUTOFREACH)
        return true
    end
    if item:getActionId() == config.actionID then
        return combats[2]:execute(player, Variant(toPos))
    end
    return combats[1]:execute(player, Variant(toPos))
end

action:id(config.itemId)
action:aid(config.actionID)
action:allowFarUse(true)
action:blockWalls(true)
action:checkFloor(true)
action:register()
 
Back
Top