Ir para conteúdo
  • 0
Entre para seguir isso  
Attacks787

Scripting Exercise Weapon - OTX Server Global v3.10

Pergunta

Attacks787    1
Attacks787

The OTX Server Global - Version: (3.10)
Compiled with: Microsoft Visual C++ version 14.0
Compiled on Nov 18 2018 17:46:29 for platform x64

 

O treinamento com as armas de exercícios não estão funcionando, o que acontece é que ao usar a arma dummy aparece a seguinte mensagem:

 

Citar

12:37 You started training.
12:37 Your training has stopped.

Ou seja, o treinamento começa e em seguida, sem ocorrer algum hit, ele é finalizado. Abaixo segue o script utilizado para sistema.

 

data\actions\scripts\exercise_training.lua

Spoiler

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

 

action.xml

Spoiler

    <action fromid="32384" toid="32389" script="exercise_training.lua" allowfaruse="1"/>

 

events.xml

Spoiler

<event class="Player" method="onTradeRequest" enabled="1" />

 

data\events\scripts\player.lua

Spoiler

local exercise_ids = {32384,32385,32386,32387,32388,32389}

 

function Player:onMoveItem(item, count, fromPosition, toPosition, fromCylinder, toCylinder)

    if isInArray(exercise_ids,item.itemid) then
        self:sendCancelMessage('You cannot move this item outside this container.')
        return false
    end

function Player:onTradeRequest(target, item)

    if isInArray(exercise_ids,item.itemid) then
        return false
    end

 

Alguém sabe a solução deste problema?

Editado por Attacks787

Compartilhar este post


Link para o post
Compartilhar em outros sites

2 respostass a esta questão

Recommended Posts

  • 0
Attacks787    1
Attacks787

Bug foi corrigido utilizando os scripts que eu postei.

Solução:  o exercise wand so funciona em pz zone.

Segundo bug, quando o player logava durante o treino e voltava a treinar, aparecia a mensagem "You are already training.", desta forma não era mais possível retornar ao treino. 

Solução:  Como a storage não era removida acontecia esse bug, a solução foi adicionar uma função ( player:setStorageValue(37, 0) ) em logout.lua

creaturescripts/scripts/others/logout.lua

Spoiler

function onLogout(player)
    local playerId = player:getId()
    if nextUseStaminaTime[playerId] ~= nil then
        nextUseStaminaTime[playerId] = nil
    end

    player:saveSpecialStorage()
    player:setStorageValue(37, 0)
    
     local stats = player:inBossFight()
     if stats then
         local boss = Monster(stats.bossId)
         -- Player logged out (or died) in the middle of a boss fight, store his damageOut and stamina
         if boss then
             local dmgOut = boss:getDamageMap()[playerId]
             if dmgOut then
                 stats.damageOut = (stats.damageOut or 0) + dmgOut.total
             end
             stats.stamina = player:getStamina()
         end
     end
     return true
end


 

Compartilhar este post


Link para o post
Compartilhar em outros sites
Visitante
Este tópico está impedido de receber novos posts.
Entre para seguir isso  

  • Quem Está Navegando   0 membros estão online

    Nenhum usuário registrado visualizando esta página.

×