• 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 local print nil value

Kahras

Member
Joined
Aug 6, 2012
Messages
101
Reaction score
7
Location
Warsaw
Hi, I have such a script on manarune:

Lua:
local exhaust = Condition(CONDITION_EXHAUST_HEAL)
exhaust:setParameter(CONDITION_PARAM_TICKS, (configManager.getNumber(configKeys.EX_ACTIONS_DELAY_INTERVAL) - 100))
-- 1000 - 100 due to exact condition timing. -100 doesn't hurt us, and players don't have reminding ~50ms exhaustion.

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if target == nil or not target:isPlayer() then
        return true
    end

    if player:getCondition(CONDITION_EXHAUST_HEAL) then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, Game.getReturnMessage(RETURNVALUE_YOUAREEXHAUSTED))
        return true
    end
    
        local level = getPlayerLevel(target)
        local magLevel = getPlayerMagLevel(target)
    if getPlayerVocation(target) == 4 then
        local min = (level * 1.5) + (magLevel * 2.5) - 0
        local max = (level * 1.7) + (magLevel * 2.7)
    else
        local min = (level * 1.5) + (magLevel * 2.5) - 0
        local max = (level * 1.7) + (magLevel * 2.7)
    end
    print(min)


    local itemId = item:getId()

    if itemId == 2272 then
        if target == player then
        doTargetCombatMana(0, target, min, max, CONST_ME_MAGIC_BLUE)
        elseif not doTargetCombatMana(0, target, min / 2, max / 2, CONST_ME_MAGIC_BLUE) then
            return false
        end

        player:addCondition(exhaust)
        target:say("Aaaah...", TALKTYPE_MONSTER_SAY)
        item:remove(1)
    end
    return true
end


And he wants to make separate values for each vocation.
The problem is, I don't know why, but it prints the min and returns me nil
 
Solution
Hi, I have such a script on manarune:

Lua:
local exhaust = Condition(CONDITION_EXHAUST_HEAL)
exhaust:setParameter(CONDITION_PARAM_TICKS, (configManager.getNumber(configKeys.EX_ACTIONS_DELAY_INTERVAL) - 100))
-- 1000 - 100 due to exact condition timing. -100 doesn't hurt us, and players don't have reminding ~50ms exhaustion.

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if target == nil or not target:isPlayer() then
        return true
    end

    if player:getCondition(CONDITION_EXHAUST_HEAL) then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, Game.getReturnMessage(RETURNVALUE_YOUAREEXHAUSTED))
        return true
    end
   
        local level = getPlayerLevel(target)
        local magLevel =...
Hi, I have such a script on manarune:

Lua:
local exhaust = Condition(CONDITION_EXHAUST_HEAL)
exhaust:setParameter(CONDITION_PARAM_TICKS, (configManager.getNumber(configKeys.EX_ACTIONS_DELAY_INTERVAL) - 100))
-- 1000 - 100 due to exact condition timing. -100 doesn't hurt us, and players don't have reminding ~50ms exhaustion.

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if target == nil or not target:isPlayer() then
        return true
    end

    if player:getCondition(CONDITION_EXHAUST_HEAL) then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, Game.getReturnMessage(RETURNVALUE_YOUAREEXHAUSTED))
        return true
    end
   
        local level = getPlayerLevel(target)
        local magLevel = getPlayerMagLevel(target)
    if getPlayerVocation(target) == 4 then
        local min = (level * 1.5) + (magLevel * 2.5) - 0
        local max = (level * 1.7) + (magLevel * 2.7)
    else
        local min = (level * 1.5) + (magLevel * 2.5) - 0
        local max = (level * 1.7) + (magLevel * 2.7)
    end
    print(min)


    local itemId = item:getId()

    if itemId == 2272 then
        if target == player then
        doTargetCombatMana(0, target, min, max, CONST_ME_MAGIC_BLUE)
        elseif not doTargetCombatMana(0, target, min / 2, max / 2, CONST_ME_MAGIC_BLUE) then
            return false
        end

        player:addCondition(exhaust)
        target:say("Aaaah...", TALKTYPE_MONSTER_SAY)
        item:remove(1)
    end
    return true
end


And he wants to make separate values for each vocation.
The problem is, I don't know why, but it prints the min and returns me nil
data/actions/actions.xml
XML:
<action itemid="2272" script="yourfile.lua" />

data/actions/scripts/yourfile.lua
Lua:
local exhaust = Condition(CONDITION_EXHAUST_HEAL)
exhaust:setParameter(CONDITION_PARAM_TICKS, (configManager.getNumber(configKeys.EX_ACTIONS_DELAY_INTERVAL) - 100))
-- 1000 - 100 due to exact condition timing. -100 doesn't hurt us, and players don't have reminding ~50ms exhaustion.

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if not target or not target:isPlayer() then
        return true
    end

    if player:getCondition(CONDITION_EXHAUST_HEAL) then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, Game.getReturnMessage(RETURNVALUE_YOUAREEXHAUSTED))
        return true
    end
    
    local level = target:getLevel()
    local magLevel = target:getMagicLevel()
    local min, max = 0, 0

    if target:getVocation():getBase():getId() == 4 then
        min = (level * 1.5) + (magLevel * 2.5) - 0
        max = (level * 1.7) + (magLevel * 2.7)
    else
        min = (level * 1.5) + (magLevel * 2.5) - 0
        max = (level * 1.7) + (magLevel * 2.7)
    end

    if target ~= player then
        min, max = min / 2, max / 2
    end

    if not doTargetCombatMana(0, target, min, max, CONST_ME_MAGIC_BLUE) then
        return false
    end

    player:addCondition(exhaust)
    target:say("Aaaah...", TALKTYPE_MONSTER_SAY)
    item:remove(1)
    return true
end
 
Solution
Back
Top