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

Action [TFS 1.2] Exercise Weapons

OTX 3.10

Code:
Lua Script Error: [Event Interface]
data/events/scripts/player.lua
data/events/scripts/player.lua:281: attempt to index global 'item' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/events/scripts/player.lua:281: in main chunk
[Warning - Events::load] Can not load script: player.lua

player.lua

Code:
    -- Exercise Weapons
if isInArray(exercise_ids,item.itemid) then
    self:sendCancelMessage('You cannot move this item outside this container.')
    return false
end
function Player:onMoveItem(item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    -- No move if item count > 20 items
    local tile = Tile(toPosition)
    if tile and tile:getItemCount() > 20 then
        self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
        return false
    end

Full Script player.lua
Kod: 710133 WKLEJTO.PL Darmowa wklejka, na zawsze! (http://www.wklejto.pl/710133)
 
Last edited:
Hello eveyone. I like to share the modifications I've made to the code.
I fixed the rates and the issue that allowed players to start the training several times with the same training weapon.

Lua:
local skills = {
    [32384] = {id=SKILL_SWORD,voc=4}, -- KNIGHT
    [32385] = {id=SKILL_AXE,voc=4}, -- KNIGHT
    [32386] = {id=SKILL_CLUB,voc=4}, -- KNIGHT
    [32387] = {id=SKILL_DISTANCE,voc=3,range=CONST_ANI_SIMPLEARROW}, -- PALADIN
    [32388] = {id=SKILL_MAGLEVEL,voc=2,range=CONST_ANI_ENERGY}, -- DRUID
    [32389] = {id=SKILL_MAGLEVEL,voc=1,range=CONST_ANI_FIRE}, -- SORCERER
}
 
------- CONFIG -----//
local dummies = {32142, 32143 ,32147, 32149} -- missing few dummies yet
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)
    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
                            --player:setStamina(player:getStamina() + 60)
                            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)
                        else
                            exercise:remove(1)
                            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Your training weapon vanished.")
                            stopEvent(training)
                            player:setStorageValue(isTraining, 0)
                        end
                    end
                end
            end
        else
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Your training has stopped.")
            stopEvent(training)
            player:setStorageValue(isTraining, 0)
        end
    else
        stopEvent(training)
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Your training has stopped.")
        player:setStorageValue(isTraining, 0)
    end
    return true
end
 
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local start_pos = player:getPosition()
    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:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Get closer to the dummy.")
                stopEvent(training)
                return false
            end
            if player:getStorageValue(isTraining) == 1 then
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You are already training.")
                return false
            end
            if not player:getVocation():getId() == skills[item.itemid].voc or not player:getVocation():getId() == (skills[item.itemid].voc+4) then
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Your vocation cannot use this training weapon.")
                stopEvent(training)
                return false
            end
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You started training.")
            start_train(player:getId(),start_pos,item.itemid,target:getPosition())
        end
    end
 
    return true
end
 
Hello eveyone. I like to share the modifications I've made to the code.
I fixed the rates and the issue that allowed players to start the training several times with the same training weapon.

Lua:
local skills = {
    [32384] = {id=SKILL_SWORD,voc=4}, -- KNIGHT
    [32385] = {id=SKILL_AXE,voc=4}, -- KNIGHT
    [32386] = {id=SKILL_CLUB,voc=4}, -- KNIGHT
    [32387] = {id=SKILL_DISTANCE,voc=3,range=CONST_ANI_SIMPLEARROW}, -- PALADIN
    [32388] = {id=SKILL_MAGLEVEL,voc=2,range=CONST_ANI_ENERGY}, -- DRUID
    [32389] = {id=SKILL_MAGLEVEL,voc=1,range=CONST_ANI_FIRE}, -- SORCERER
}

------- CONFIG -----//
local dummies = {32142, 32143 ,32147, 32149} -- missing few dummies yet
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)
    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
                            --player:setStamina(player:getStamina() + 60)
                            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)
                        else
                            exercise:remove(1)
                            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Your training weapon vanished.")
                            stopEvent(training)
                            player:setStorageValue(isTraining, 0)
                        end
                    end
                end
            end
        else
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Your training has stopped.")
            stopEvent(training)
            player:setStorageValue(isTraining, 0)
        end
    else
        stopEvent(training)
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Your training has stopped.")
        player:setStorageValue(isTraining, 0)
    end
    return true
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local start_pos = player:getPosition()
    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:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Get closer to the dummy.")
                stopEvent(training)
                return false
            end
            if player:getStorageValue(isTraining) == 1 then
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You are already training.")
                return false
            end
            if not player:getVocation():getId() == skills[item.itemid].voc or not player:getVocation():getId() == (skills[item.itemid].voc+4) then
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Your vocation cannot use this training weapon.")
                stopEvent(training)
                return false
            end
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You started training.")
            start_train(player:getId(),start_pos,item.itemid,target:getPosition())
        end
    end

    return true
end
I used you code, and know the character start and stop in the same time.

20:00 You started training.
20:00 Your training has stopped.

Dont give hit in dummy too.. have some solution? Need do something in items.xml?
 
OTX 3.10

Code:
Lua Script Error: [Event Interface]
data/events/scripts/player.lua
data/events/scripts/player.lua:281: attempt to index global 'item' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/events/scripts/player.lua:281: in main chunk
[Warning - Events::load] Can not load script: player.lua

player.lua

Code:
    -- Exercise Weapons
if isInArray(exercise_ids,item.itemid) then
    self:sendCancelMessage('You cannot move this item outside this container.')
    return false
end
function Player:onMoveItem(item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    -- No move if item count > 20 items
    local tile = Tile(toPosition)
    if tile and tile:getItemCount() > 20 then
        self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
        return false
    end

Full Script player.lua
Kod: 710133 WKLEJTO.PL Darmowa wklejka, na zawsze! (http://www.wklejto.pl/710133)


http://www.wklejto.pl/txt715198
 
Hello eveyone. I like to share the modifications I've made to the code.
I fixed the rates and the issue that allowed players to start the training several times with the same training weapon.

Lua:
local skills = {
    [32384] = {id=SKILL_SWORD,voc=4}, -- KNIGHT
    [32385] = {id=SKILL_AXE,voc=4}, -- KNIGHT
    [32386] = {id=SKILL_CLUB,voc=4}, -- KNIGHT
    [32387] = {id=SKILL_DISTANCE,voc=3,range=CONST_ANI_SIMPLEARROW}, -- PALADIN
    [32388] = {id=SKILL_MAGLEVEL,voc=2,range=CONST_ANI_ENERGY}, -- DRUID
    [32389] = {id=SKILL_MAGLEVEL,voc=1,range=CONST_ANI_FIRE}, -- SORCERER
}

------- CONFIG -----//
local dummies = {32142, 32143 ,32147, 32149} -- missing few dummies yet
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)
    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
                            --player:setStamina(player:getStamina() + 60)
                            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)
                        else
                            exercise:remove(1)
                            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Your training weapon vanished.")
                            stopEvent(training)
                            player:setStorageValue(isTraining, 0)
                        end
                    end
                end
            end
        else
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Your training has stopped.")
            stopEvent(training)
            player:setStorageValue(isTraining, 0)
        end
    else
        stopEvent(training)
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Your training has stopped.")
        player:setStorageValue(isTraining, 0)
    end
    return true
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local start_pos = player:getPosition()
    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:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Get closer to the dummy.")
                stopEvent(training)
                return false
            end
            if player:getStorageValue(isTraining) == 1 then
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You are already training.")
                return false
            end
            if not player:getVocation():getId() == skills[item.itemid].voc or not player:getVocation():getId() == (skills[item.itemid].voc+4) then
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Your vocation cannot use this training weapon.")
                stopEvent(training)
                return false
            end
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You started training.")
            start_train(player:getId(),start_pos,item.itemid,target:getPosition())
        end
    end

    return true
end


Can you add modification?
Storage after logging out does not change the value to 0, this way after relog during training, you can not continue.
 
78a5ac9f6bc1e7f8bb9ac538ea6356de.gif

dont work :X
Work only on Protection Zone
 
Can you add modification?
Storage after logging out does not change the value to 0, this way after relog during training, you can not continue.
I search the erro, this work only if you attack the target on pz zone.. But know I try change the rate and nothing happens.
When I change de number in skillrate, don't change the rates.

local skillRate = 100*configManager.getNumber(configKeys.RATE_SKILL)

What I need do?
 
Can you add modification?
Storage after logging out does not change the value to 0, this way after relog during training, you can not continue.

I solved this problem using in creaturescirpts/others/logout.xml

Code:
player:setStorageValue(37, 0)

Now I try to change the rateskills
 
Hi guys. Anyone know how to properly add exercise weapon to in-game store to get this in one piece with 500 charges ?
I have all right with items setup and script.
 
Back
Top