Jump to content

(Resolvido)Update no Script de Trainer Off


Go to solution Solved by ZoR,

Recommended Posts

O problema é que, quando o player clica na estatua, e quando vai loga de novo, o login demora absurdamente, tipo 1 min para logar, acredito que seja algum erro do script (forma que foi feito) apesar de não dar erros no console.

 

obs: para tfs 0.4 Cliente 8.60

 

actions.lua

 

function onUse(cid, item, fromPosition, itemEx, toPosition)
   if(item.itemid == 8779) then -- sword
     doCreatureSetStorage(cid, 62669, SKILL_SWORD)
   elseif(item.itemid == 8836) then -- axe
     doCreatureSetStorage(cid, 62669, SKILL_AXE)
   elseif(item.itemid == 8777) then -- mlvl
     doCreatureSetStorage(cid, 62669, SKILL__MAGLEVEL)
   elseif(item.itemid == 8834) then -- club
     doCreatureSetStorage(cid, 62669, SKILL_CLUB)
   elseif(item.itemid == 3739) then -- distannce
     doCreatureSetStorage(cid, 62669, SKILL_DISTANCE)
   end
   if item.actionid == 1000 then
   doRemoveCreature(cid)
end
   return true
end

 

actions.xml

 

    --Offline Training--
<action itemid="8777" event="script" value="offtrain.lua"/>
<action itemid="3739" event="script" value="offtrain.lua"/>
<action itemid="8836" event="script" value="offtrain.lua"/>
<action itemid="8834" event="script" value="offtrain.lua"/>
<action itemid="8779" event="script" value="offtrain.lua"/>

 

creaturescript.lua

 

-- 0.4 - offline training - login.lua
function onLogin(cid)
   OfflineTraining_initialize(cid)
   if(OfflineTraining_isTraining(cid)) then
     OfflineTraining_turnOffTraining(cid)
     -- we add skill/mlvl, we select lower value: time that player was offline OR offline training time [bar in game - 9.6]
     OfflineTraining_addTrainedSkills(cid, math.min(OfflineTraining_getTime(cid), OfflineTraining_getOfflineTime(cid)))
     -- we remove offline training time [bar in game - 9.6],
     -- if player was offline longer then his 'offline training time' it will add him time [like on RL tibia]
     -- got '3  hours offline training time', stay logged off for 8 hours, you get skills for 3 hours and on login you got '5 hours offline training time'
     OfflineTraining_setTime(cid, math.abs(OfflineTraining_getTime(cid) - OfflineTraining_getOfflineTime(cid)))
     OfflineTraining_onEndTraining(cid)
   else
     -- offline training time also regenerate when you are offline, but NOT train
     OfflineTraining_setTime(cid, OfflineTraining_getTime(cid) + OfflineTraining_getOfflineTime(cid))
   end
   return true
end
 

 

outro creaturescript.lua

 

-- 0.4 - offline training - logout.lua
function onLogout(cid)
   if(OfflineTraining_canStartTraining(cid)) then
     OfflineTraining_turnOnTraining(cid)
     OfflineTraining_onStartTraining(cid)
   end
   OfflineTraining_setLogoutTime(cid)
   return true
end
 

 

creaturescript.xml

 

<event type="login" name="offtrain_PlayerLogin" event="script" value="train1.lua"/>
<event type="logout" name="offtrain_PlayerLogout" event="script" value="train2.lua"/>

 

 

global events.lua

 

 function onThink(interval) -- run it with interval 60 seconds
    for _, cid in pairs(getPlayersOnline()) do
    OfflineTraining_addTime(cid, 1)
    end
    return true
    end

 

global events,xml

<globalevent name="offtrain_add_minutes" interval="60000" event="script" value="offtrain0.lua"/>

 

lib.lua

 

-- config, in percent of normal training with 2 trainers and player vocation mana regeneration [by food]
OfflineTraining_rates = {
[SKILL_CLUB] = 25,
[SKILL_SWORD] = 25,
[SKILL_AXE] = 25,
[SKILL_DISTANCE] = 25,
[SKILL_SHIELD] = 25,
[SKILL__MAGLEVEL] = 25
}
-- function that you should edit to make it add other skill etc.
function OfflineTraining_canStartTraining(cid) -- return bool
return getCreatureStorage(cid, 62669) > 0
end
function OfflineTraining_onStartTraining(cid)
-- maybe someone will need
-- to save your time, this: doPlayerPopupFYI(cid, "You started offline training.")
-- NOT WORK :(
end
function OfflineTraining_onEndTraining(cid)
doCreatureSetStorage(cid, 62669, 0)
end
function OfflineTraining_addTrainedSkills(cid, trainTime) -- time in minutes!
local timeInSeconds = trainTime * 60
local vocInfo = getVocationInfo(getPlayerVocation(cid))
if(getCreatureStorage(cid, 62669) == SKILL_SWORD) then
doPlayerAddSkillTry(cid, SKILL_SWORD, ((timeInSeconds * 1000) / vocInfo["attackSpeed"]) * OfflineTraining_rates[SKILL_SWORD] / 100, true)
elseif(getCreatureStorage(cid, 62669) == SKILL_AXE) then
doPlayerAddSkillTry(cid, SKILL_AXE, ((timeInSeconds * 1000) / vocInfo["attackSpeed"]) * OfflineTraining_rates[SKILL_AXE] / 100, true)
elseif(getCreatureStorage(cid, 62669) == SKILL__MAGLEVEL) then
doPlayerAddSpentMana(cid, ((timeInSeconds / vocInfo["manaGainTicks"]) * vocInfo["manaGain"]) * OfflineTraining_rates[SKILL__MAGLEVEL] / 100, true)
elseif(getCreatureStorage(cid, 62669) == SKILL_CLUB) then
doPlayerAddSkillTry(cid, SKILL_CLUB, ((timeInSeconds * 1000) / vocInfo["attackSpeed"]) * OfflineTraining_rates[SKILL_CLUB] / 100, true)
elseif(getCreatureStorage(cid, 62669) == SKILL_DISTANCE) then
doPlayerAddSkillTry(cid, SKILL_DISTANCE, ((timeInSeconds * 1000) / vocInfo["attackSpeed"]) * OfflineTraining_rates[SKILL_DISTANCE] / 100, true)
end
doPlayerAddSkillTry(cid, SKILL_SHIELD, timeInSeconds * OfflineTraining_rates[SKILL_SHIELD] / 100, true)
end
 
-- 4 functions to show right values on 'bar' in Tibia 9.6
function OfflineTraining_getTime(cid)
return getCreatureStorage(cid, 62666)
end
function OfflineTraining_setTime(cid, newTime)
-- set values only between 0 - 720 [12 hours]
doCreatureSetStorage(cid, 62666, math.max(0, math.min(newTime, 720)))
-- now code to force server to send 'PlayerStats' (including Offline Time)
-- we must change any stat: hp,mana,stamina,cap,soul,exp,level
doPlayerAddSoul(cid, 1)
doPlayerAddSoul(cid, -1)
end
function OfflineTraining_addTime(cid, addTime)
OfflineTraining_setTime(cid, OfflineTraining_getTime(cid) + addTime)
end
function OfflineTraining_removeTime(cid, removeTime)
OfflineTraining_setTime(cid, OfflineTraining_getTime(cid) - removeTime)
end
 
-- functions for library to add skills/mlvl
function OfflineTraining_initialize(cid)
if(OfflineTraining_getTime(cid) == -1) then
OfflineTraining_setTime(cid, 720)
OfflineTraining_setLogoutTime(cid) -- block problem with first login 'add time'
end
end
function OfflineTraining_isTraining(cid)
return (getCreatureStorage(cid, 62667) > 0)
end
function OfflineTraining_turnOnTraining(cid)
doCreatureSetStorage(cid, 62667, 1)
end
function OfflineTraining_turnOffTraining(cid)
doCreatureSetStorage(cid, 62667, 0)
end
function OfflineTraining_getOfflineTime(cid)
return math.floor((os.time() - getCreatureStorage(cid, 62668)) / 60)
end
function OfflineTraining_setLogoutTime(cid)
return doCreatureSetStorage(cid, 62668, os.time())
end

 

Link to post
Share on other sites
  • 2 weeks later...

Pra qual versão de tfs @JcA?

🛠️ Projeto NTO NS 🛠️

📝 Detalhes 📝

🗺️ Mapa próprio em produção 🗺️

🖱️ Versão: 8.60 🖱️

🔥 War System 🔥

⚔️ Jutsus Próprios baseado no anime ⚔️

🔰 Itens com as características e efeitos do anime 🔰

💻 Para mais detalhes acesse as redes sociais do servidor abaixo 💻

💡 Usando como referencias Anime/Jogos/Wallpapers etc... para trazer algo mais próximo possível do universo de Naruto 💡

 

💎 Redes Sociais 💎

🌀 Facebook 🌀

🎒 Youtube 🎒
🌌 Discord 🌌

 

📚 Tutoriais / Conteúdos 📥

♨️ Clique Aqui ♨️

Link to post
Share on other sites
21 minutos atrás, JcA disse:

 

0.4

8.60

#Edited

🛠️ Projeto NTO NS 🛠️

📝 Detalhes 📝

🗺️ Mapa próprio em produção 🗺️

🖱️ Versão: 8.60 🖱️

🔥 War System 🔥

⚔️ Jutsus Próprios baseado no anime ⚔️

🔰 Itens com as características e efeitos do anime 🔰

💻 Para mais detalhes acesse as redes sociais do servidor abaixo 💻

💡 Usando como referencias Anime/Jogos/Wallpapers etc... para trazer algo mais próximo possível do universo de Naruto 💡

 

💎 Redes Sociais 💎

🌀 Facebook 🌀

🎒 Youtube 🎒
🌌 Discord 🌌

 

📚 Tutoriais / Conteúdos 📥

♨️ Clique Aqui ♨️

Link to post
Share on other sites
3 minutos atrás, JcA disse:

Você cheirou orégano mano? Isso é uma dúvida, na área de suporte. puta merda :facepalm:

nossa mano to cansadão desde as 5:30 acordado nem percebi falta de atenção minha desculpa :facepalm:

🛠️ Projeto NTO NS 🛠️

📝 Detalhes 📝

🗺️ Mapa próprio em produção 🗺️

🖱️ Versão: 8.60 🖱️

🔥 War System 🔥

⚔️ Jutsus Próprios baseado no anime ⚔️

🔰 Itens com as características e efeitos do anime 🔰

💻 Para mais detalhes acesse as redes sociais do servidor abaixo 💻

💡 Usando como referencias Anime/Jogos/Wallpapers etc... para trazer algo mais próximo possível do universo de Naruto 💡

 

💎 Redes Sociais 💎

🌀 Facebook 🌀

🎒 Youtube 🎒
🌌 Discord 🌌

 

📚 Tutoriais / Conteúdos 📥

♨️ Clique Aqui ♨️

Link to post
Share on other sites
  • Solution
Em 30/08/2017 em 15:58, JcA disse:

Você cheirou orégano mano? Isso é uma dúvida, na área de suporte. puta merda :facepalm:

-- config, in percent of normal training with 2 trainers and player vocation mana regeneration [by food]
OfflineTraining_rates = {
[SKILL_CLUB] = 25,
[SKILL_SWORD] = 25,
[SKILL_AXE] = 25,
[SKILL_DISTANCE] = 25,
[SKILL_SHIELD] = 25,
[SKILL__MAGLEVEL] = 25
}
-- function that you should edit to make it add other skill etc.
function OfflineTraining_canStartTraining(cid) -- return bool
return getCreatureStorage(cid, 62669) > 0
end
function OfflineTraining_onStartTraining(cid)
-- maybe someone will need
-- to save your time, this: doPlayerPopupFYI(cid, "You started offline training.")
-- NOT WORK :(
end
function OfflineTraining_onEndTraining(cid)
doCreatureSetStorage(cid, 62669, 0)
end
function OfflineTraining_addTrainedSkills(cid, trainTime) -- time in minutes!
local timeInSeconds = trainTime * 60
local vocInfo = getVocationInfo(getPlayerVocation(cid))
if(getCreatureStorage(cid, 62669) == SKILL_SWORD) then
doPlayerAddSkillTry(cid, SKILL_SWORD, ((timeInSeconds * 1000) / vocInfo["attackSpeed"]) * OfflineTraining_rates[SKILL_SWORD] / 100, true)
elseif(getCreatureStorage(cid, 62669) == SKILL_AXE) then
doPlayerAddSkillTry(cid, SKILL_AXE, ((timeInSeconds * 1000) / vocInfo["attackSpeed"]) * OfflineTraining_rates[SKILL_AXE] / 100, true)
elseif(getCreatureStorage(cid, 62669) == SKILL__MAGLEVEL) then
doPlayerAddSpentMana(cid, ((timeInSeconds / vocInfo["manaGainTicks"]) * vocInfo["manaGain"]) * OfflineTraining_rates[SKILL__MAGLEVEL] / 100, true)
elseif(getCreatureStorage(cid, 62669) == SKILL_CLUB) then
doPlayerAddSkillTry(cid, SKILL_CLUB, ((timeInSeconds * 1000) / vocInfo["attackSpeed"]) * OfflineTraining_rates[SKILL_CLUB] / 100, true)
elseif(getCreatureStorage(cid, 62669) == SKILL_DISTANCE) then
doPlayerAddSkillTry(cid, SKILL_DISTANCE, ((timeInSeconds * 1000) / vocInfo["attackSpeed"]) * OfflineTraining_rates[SKILL_DISTANCE] / 100, true)
end
doPlayerAddSkillTry(cid, SKILL_SHIELD, timeInSeconds * OfflineTraining_rates[SKILL_SHIELD] / 100, true)
end
 
-- 4 functions to show right values on 'bar' in Tibia 9.6
function OfflineTraining_getTime(cid)
return getCreatureStorage(cid, 62666)
end
function OfflineTraining_setTime(cid, newTime)
-- set values only between 0 - 720 [12 hours]
doCreatureSetStorage(cid, 62666, math.max(0, math.min(newTime, 720)))
-- now code to force server to send 'PlayerStats' (including Offline Time)
-- we must change any stat: hp,mana,stamina,cap,soul,exp,level
doPlayerAddSoul(cid, 1)
doPlayerAddSoul(cid, -1)
end
function OfflineTraining_addTime(cid, addTime)
OfflineTraining_setTime(cid, OfflineTraining_getTime(cid) + addTime)
end
function OfflineTraining_removeTime(cid, removeTime)
OfflineTraining_setTime(cid, OfflineTraining_getTime(cid) - removeTime)
end
 
-- functions for library to add skills/mlvl
function OfflineTraining_initialize(cid)
if(OfflineTraining_getTime(cid) == -1) then
OfflineTraining_setLogoutTime(cid) -- block problem with first login 'add time'
end
end
function OfflineTraining_isTraining(cid)
return (getCreatureStorage(cid, 62667) > 0)
end
function OfflineTraining_turnOnTraining(cid)
doCreatureSetStorage(cid, 62667, 1)
end
function OfflineTraining_turnOffTraining(cid)
doCreatureSetStorage(cid, 62667, 0)
end
function OfflineTraining_getOfflineTime(cid)
return math.floor((os.time() - getCreatureStorage(cid, 62668)) / 60)
end
function OfflineTraining_setLogoutTime(cid)
return doCreatureSetStorage(cid, 62668, os.time())
end

usa essa Lib.

O rei de seu proprio destino é aquele que luta pela gloria do amanhã!
Discord : ZoR#9373


 

Link to post
Share on other sites
1 hora atrás, ZikaLord disse:

-- config, in percent of normal training with 2 trainers and player vocation mana regeneration [by food]
OfflineTraining_rates = {
[SKILL_CLUB] = 25,
[SKILL_SWORD] = 25,
[SKILL_AXE] = 25,
[SKILL_DISTANCE] = 25,
[SKILL_SHIELD] = 25,
[SKILL__MAGLEVEL] = 25
}
-- function that you should edit to make it add other skill etc.
function OfflineTraining_canStartTraining(cid) -- return bool
return getCreatureStorage(cid, 62669) > 0
end
function OfflineTraining_onStartTraining(cid)
-- maybe someone will need
-- to save your time, this: doPlayerPopupFYI(cid, "You started offline training.")
-- NOT WORK :(
end
function OfflineTraining_onEndTraining(cid)
doCreatureSetStorage(cid, 62669, 0)
end
function OfflineTraining_addTrainedSkills(cid, trainTime) -- time in minutes!
local timeInSeconds = trainTime * 60
local vocInfo = getVocationInfo(getPlayerVocation(cid))
if(getCreatureStorage(cid, 62669) == SKILL_SWORD) then
doPlayerAddSkillTry(cid, SKILL_SWORD, ((timeInSeconds * 1000) / vocInfo["attackSpeed"]) * OfflineTraining_rates[SKILL_SWORD] / 100, true)
elseif(getCreatureStorage(cid, 62669) == SKILL_AXE) then
doPlayerAddSkillTry(cid, SKILL_AXE, ((timeInSeconds * 1000) / vocInfo["attackSpeed"]) * OfflineTraining_rates[SKILL_AXE] / 100, true)
elseif(getCreatureStorage(cid, 62669) == SKILL__MAGLEVEL) then
doPlayerAddSpentMana(cid, ((timeInSeconds / vocInfo["manaGainTicks"]) * vocInfo["manaGain"]) * OfflineTraining_rates[SKILL__MAGLEVEL] / 100, true)
elseif(getCreatureStorage(cid, 62669) == SKILL_CLUB) then
doPlayerAddSkillTry(cid, SKILL_CLUB, ((timeInSeconds * 1000) / vocInfo["attackSpeed"]) * OfflineTraining_rates[SKILL_CLUB] / 100, true)
elseif(getCreatureStorage(cid, 62669) == SKILL_DISTANCE) then
doPlayerAddSkillTry(cid, SKILL_DISTANCE, ((timeInSeconds * 1000) / vocInfo["attackSpeed"]) * OfflineTraining_rates[SKILL_DISTANCE] / 100, true)
end
doPlayerAddSkillTry(cid, SKILL_SHIELD, timeInSeconds * OfflineTraining_rates[SKILL_SHIELD] / 100, true)
end
 
-- 4 functions to show right values on 'bar' in Tibia 9.6
function OfflineTraining_getTime(cid)
return getCreatureStorage(cid, 62666)
end
function OfflineTraining_setTime(cid, newTime)
-- set values only between 0 - 720 [12 hours]
doCreatureSetStorage(cid, 62666, math.max(0, math.min(newTime, 720)))
-- now code to force server to send 'PlayerStats' (including Offline Time)
-- we must change any stat: hp,mana,stamina,cap,soul,exp,level
doPlayerAddSoul(cid, 1)
doPlayerAddSoul(cid, -1)
end
function OfflineTraining_addTime(cid, addTime)
OfflineTraining_setTime(cid, OfflineTraining_getTime(cid) + addTime)
end
function OfflineTraining_removeTime(cid, removeTime)
OfflineTraining_setTime(cid, OfflineTraining_getTime(cid) - removeTime)
end
 
-- functions for library to add skills/mlvl
function OfflineTraining_initialize(cid)
if(OfflineTraining_getTime(cid) == -1) then
OfflineTraining_setLogoutTime(cid) -- block problem with first login 'add time'
end
end
function OfflineTraining_isTraining(cid)
return (getCreatureStorage(cid, 62667) > 0)
end
function OfflineTraining_turnOnTraining(cid)
doCreatureSetStorage(cid, 62667, 1)
end
function OfflineTraining_turnOffTraining(cid)
doCreatureSetStorage(cid, 62667, 0)
end
function OfflineTraining_getOfflineTime(cid)
return math.floor((os.time() - getCreatureStorage(cid, 62668)) / 60)
end
function OfflineTraining_setLogoutTime(cid)
return doCreatureSetStorage(cid, 62668, os.time())
end

usa essa Lib.

 

Parece que funcionou, obrigado

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

Confirmação de Termo