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

TFS 1.X+ TFS CANARY Dont use exercise weapons on dummy

Zuber98

New Member
Joined
Apr 27, 2021
Messages
12
Reaction score
2
hello guys dont use exercise weapons.


[2022-18-04 11:28:22.589] [error] Lua script error:
scriptInterface: [Scripts Interface]
scriptId: [/home/canary/data/scripts/actions/other/exercise_training.lua:callback]
timerEvent: []
callbackId:[]
function: []
error [.../canary/data/scripts/actions/other/exercise_training.lua:7: attempt to call global 'isInArray' (a nil value)
stack traceback:
[C]: in function 'isInArray'
.../canary/data/scripts/actions/other/exercise_training.lua:7: in function <.../canary/data/scripts/actions/other/exercise_training.lua:3>]


Lua:
local exerciseTraining = Action()

function exerciseTraining.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local playerId = player:getId()
    local targetId = target:getId()

    if target:isItem() and (isInArray(houseDummies, targetId) or isInArray(freeDummies, targetId)) then
        if onExerciseTraining[playerId] then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "This exercise dummy can only be used after a 30 second cooldown.")
            leaveTraining(playerId)
            return true
        end

        local playerPos = player:getPosition()
        if not exerciseWeaponsTable[item.itemid].allowFarUse and (playerPos:getDistance(target:getPosition()) > 1) then
            player:sendTextMessage(MESSAGE_FAILURE, "Get closer to the dummy.")
            return true
        end

        if not getTilePzInfo(playerPos) and not getTileNoPzZoneInfo(playerPos) then
            player:sendTextMessage(MESSAGE_FAILURE, "You need to be in a protection zone.")
            return true
        end

        local targetPos = target:getPosition()

        if isInArray(houseDummies, targetId) then
            local playersOnDummy = 0
            for _, playerTraining in pairs(onExerciseTraining) do
                if playerTraining.dummyPos == targetPos then
                    playersOnDummy = playersOnDummy + 1
                end
   
                if playersOnDummy == maxAllowedOnADummy then
                    player:sendTextMessage(MESSAGE_FAILURE, "That exercise dummy is busy.")
                    return true
                end
            end
        end

        if player:getStorageValue(Storage.isTraining) > os.time() then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "This exercise dummy can only be used after a 30 second cooldown.")
            return true
        end

        onExerciseTraining[playerId] = {}
        if not onExerciseTraining[playerId].event then
            onExerciseTraining[playerId].event = addEvent(exerciseEvent, 0, playerId, targetPos, item.itemid, targetId)
            onExerciseTraining[playerId].dummyPos = targetPos
            player:setTraining(true)
            player:setStorageValue(Storage.isTraining, os.time() + 30)
        end
        return true
    end
    return false
end

for weaponId, weapon in pairs(exerciseWeaponsTable) do
    exerciseTraining:id(weaponId)
    if weapon.allowFarUse then
        exerciseTraining:allowFarUse(true)
    end
end

exerciseTraining:register()
 
Last edited:
did you manage to fix it?
Post automatically merged:

hello guys dont use exercise weapons.


[2022-18-04 11:28:22.589] [error] Lua script error:
scriptInterface: [Scripts Interface]
scriptId: [/home/canary/data/scripts/actions/other/exercise_training.lua:callback]
timerEvent: []
callbackId:[]
function: []
error [.../canary/data/scripts/actions/other/exercise_training.lua:7: attempt to call global 'isInArray' (a nil value)
stack traceback:
[C]: in function 'isInArray'
.../canary/data/scripts/actions/other/exercise_training.lua:7: in function <.../canary/data/scripts/actions/other/exercise_training.lua:3>]


Lua:
local exerciseTraining = Action()

function exerciseTraining.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local playerId = player:getId()
    local targetId = target:getId()

    if target:isItem() and (isInArray(houseDummies, targetId) or isInArray(freeDummies, targetId)) then
        if onExerciseTraining[playerId] then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "This exercise dummy can only be used after a 30 second cooldown.")
            leaveTraining(playerId)
            return true
        end

        local playerPos = player:getPosition()
        if not exerciseWeaponsTable[item.itemid].allowFarUse and (playerPos:getDistance(target:getPosition()) > 1) then
            player:sendTextMessage(MESSAGE_FAILURE, "Get closer to the dummy.")
            return true
        end

        if not getTilePzInfo(playerPos) and not getTileNoPzZoneInfo(playerPos) then
            player:sendTextMessage(MESSAGE_FAILURE, "You need to be in a protection zone.")
            return true
        end

        local targetPos = target:getPosition()

        if isInArray(houseDummies, targetId) then
            local playersOnDummy = 0
            for _, playerTraining in pairs(onExerciseTraining) do
                if playerTraining.dummyPos == targetPos then
                    playersOnDummy = playersOnDummy + 1
                end
  
                if playersOnDummy == maxAllowedOnADummy then
                    player:sendTextMessage(MESSAGE_FAILURE, "That exercise dummy is busy.")
                    return true
                end
            end
        end

        if player:getStorageValue(Storage.isTraining) > os.time() then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "This exercise dummy can only be used after a 30 second cooldown.")
            return true
        end

        onExerciseTraining[playerId] = {}
        if not onExerciseTraining[playerId].event then
            onExerciseTraining[playerId].event = addEvent(exerciseEvent, 0, playerId, targetPos, item.itemid, targetId)
            onExerciseTraining[playerId].dummyPos = targetPos
            player:setTraining(true)
            player:setStorageValue(Storage.isTraining, os.time() + 30)
        end
        return true
    end
    return false
end

for weaponId, weapon in pairs(exerciseWeaponsTable) do
    exerciseTraining:id(weaponId)
    if weapon.allowFarUse then
        exerciseTraining:allowFarUse(true)
    end
end

exerciseTraining:register()
did you manage to fix it?
 
Back
Top