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

Exercise Weapons/Dummy TFS 1.X 8.6

sirluumi

New Member
Joined
Jun 12, 2020
Messages
3
Reaction score
0
We tried adding exercise weapons with this code

Lua:
local dummies = {11257, 11264, 11245, 9934, 8707}
local skillRate = 1*configManager.getNumber(configKeys.RATE_SKILL)
local isTraining = 37
-- skillRate = 1.1*30 = 30 + 3 (10%) = 33x
 
local function start_train(pid,start_pos,itemid,fpos)
    local player = Player(pid)
        player:setStorageValue(isTraining, 1)
        player:setStorageValue(Storage.isTraining, 1)
    if player ~= nil then
        local pos_n = player:getPosition()
        if start_pos:getDistance(pos_n) == 0 and getTilePzInfo(pos_n) then
            if player:getItemCount(itemid) >= 1 then
                local exercise = player:getItemById(itemid,true)
                if exercise:isItem() then
                    if exercise:hasAttribute(ITEM_ATTRIBUTE_CHARGES) then
                        local charges_n = exercise:getAttribute(ITEM_ATTRIBUTE_CHARGES)
                        if charges_n >= 1 then
                            exercise:setAttribute(ITEM_ATTRIBUTE_CHARGES,(charges_n-1))
                            local voc = player:getVocation()
                            if skills[itemid].id == SKILL_MAGLEVEL then
                                magicTry = voc:getRequiredManaSpent(player:getBaseMagicLevel() + 1)-player:getManaSpent()
                                player:addManaSpent(math.ceil(250))
                            else
                                player:addSkillTries(skills[itemid].id, 1*skillRate)
                            end
                                fpos:sendMagicEffect(CONST_ME_HITAREA)
                            if skills[itemid].range then
                                pos_n:sendDistanceEffect(fpos, skills[itemid].range)
                            end
                            if charges_n == 1 then
                                exercise:remove(1)
                                return true
                            end
                            local training = addEvent(start_train, voc:getAttackSpeed(), pid,start_pos,itemid,fpos)
                            player:setStorageValue(isTraining, 1)
                            player:setStorageValue(Storage.isTraining, 1)
                        else
                            exercise:remove(1)
                            player:sendCancelMessage("Your training weapon vanished.")
                            player:sendTextMessage(MESSAGE_INFO_DESCR, "Your training weapon vanished.")
                            stopEvent(training)
                            player:setStorageValue(isTraining, 0)
                            player:setStorageValue(Storage.isTraining, 0)
                        end
                    end
                end
            end
        else
            player:sendCancelMessage("Your training has stopped.")
            player:sendTextMessage(MESSAGE_INFO_DESCR, "Youy training has stopped.")
            stopEvent(training)
            player:setStorageValue(isTraining, 0)
            player:setStorageValue(Storage.isTraining, 0)
        end
    else
        stopEvent(training)
        player:sendCancelMessage("Your training has stopped.")
        player:setStorageValue(isTraining, 0)
        if player then -- verificar se o player ainda existe (logado), caso esteja, enviar mensagem de erro e parar treino. isso evita erros no console
            player:sendTextMessage(MESSAGE_INFO_DESCR, "Youy training has stopped.")
            player:setStorageValue(Storage.isTraining, 0)
        end
    end
    return true
end
 
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local start_pos = player:getPosition()
    if player:getStorageValue(Storage.isTraining) == 1 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You are already training.")
        return false
    end
    if target:isItem() then
        if isInArray(dummies,target:getId()) then
            if not skills[item.itemid].range and (start_pos:getDistance(target:getPosition()) > 1) then
                player:sendCancelMessage("Get closer to the dummy.")
                player:sendTextMessage(MESSAGE_INFO_DESCR, "Get closer to the dummy.")
                stopEvent(training)
                return true
            end
            if player:getStorageValue(isTraining) == 1 then
                player:sendCancelMessage("You are already training.")
                return false
            end
            player:sendCancelMessage("You started training.")
            player:sendTextMessage(MESSAGE_INFO_DESCR, "You started training.")
            start_train(player:getId(),start_pos,item.itemid,target:getPosition())
        end
    return true
    end
end

But running into this problem, don't know how to define storage value


Code:
Lua Script Error: [Action Interface]
data/actions/scripts/ExerciseTraining/exercise_training.lua:onUse
data/actions/scripts/ExerciseTraining/exercise_training.lua:70: attempt to index global 'Storage' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/actions/scripts/ExerciseTraining/exercise_training.lua:70: in function <data/actions/scripts/ExerciseTraining/exercise_training.lua:68>

Thank you in advance, we have tried various different ways but dont seem to find the correct one.
 
Top