Skip to content
This repository has been archived by the owner on May 20, 2023. It is now read-only.

Commit

Permalink
fix a problem with exercise weapons (#539)
Browse files Browse the repository at this point in the history
* fix a problem with exercise weapons

Fixes a problem when a player logout while training with exercise weapons, which prevent the player to start training again.

* adjust storage on 051-storages

* Small fix for training weapons

Removed a piece of code that was removing exercise weapons before it has 0 charges.
Changed the cancel message to Text message, so it is displayed on Server Log.

* included missing end at login.lua
  • Loading branch information
lBaah authored and majestyotbr committed Sep 8, 2019
1 parent b9c492e commit fbe682b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
37 changes: 17 additions & 20 deletions data/actions/scripts/others/objects/exerciseTraining.lua
Expand Up @@ -15,7 +15,6 @@ local skills = {

local dummies = {32142, 32143, 32144, 32145, 32146, 32147, 32148, 32149}
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)
Expand Down Expand Up @@ -43,50 +42,48 @@ local function start_train(pid,start_pos,itemid,fpos)
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 false
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
end
return true
end
end
4 changes: 4 additions & 0 deletions data/creaturescripts/scripts/others/login.lua
Expand Up @@ -151,5 +151,9 @@ function onLogin(player)
local minutes = worldTime % 60
player:sendTibiaTime(hours, minutes)
end

if player:getStorageValue(Storage.isTraining) == 1 then -- redefinir storage de exercise weapon
player:setStorageValue(Storage.isTraining,0)
end
return true
end
3 changes: 2 additions & 1 deletion data/lib/miscellaneous/051-storages.lua
Expand Up @@ -1340,7 +1340,8 @@ Storage = {
combatProtectionStorage = 50722,
Factions = 50723,
blockMovementStorage = 100000,
PetSummon = 60045
PetSummon = 60045,
isTraining = 37

}

Expand Down

0 comments on commit fbe682b

Please sign in to comment.