• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

Action [TFS 0.2,0.3,0.4] Working Offline Trainers! 9.6 (no bar)

Hauni

Killer of Giants
Joined
May 8, 2008
Messages
82
Reaction score
1
Location
Åsgård
Hello!

I've decided to release my offline trainer script!

If you decide to use it, please give me some reputation :)

I have not tested this with any other servers than my own, so please don't expect it to work flawlessly.

Also stamina does not work! However you can limit the rate of how fast you advance, and you can also set the max amount of time you can train each time you use the trainers.

This requires the 9.6 items, btw.

So let's go:

To install it, follow these steps:
1. Open up your database, copy and paste this into the sql-query field:
Code:
CREATE TABLE offline_training
(account_id int(11),
name varchar(256),
start_training int(11),
type varchar(256))
(I know its not neccessary to store this in a seperate table, but its a personal preference)

2. Open your data/actions folder.
First go to actions.xml and add the following:
Code:
        <action itemid="18492" script="offline_trainer.lua"/> -- OFFLINE TRAINING STATUE
	<action itemid="18491" script="offline_trainer.lua"/> -- OFFLINE TRAINING STATUE
	<action itemid="18490" script="offline_trainer.lua"/> -- OFFLINE TRAINING STATUE
	<action itemid="18489" script="offline_trainer.lua"/> -- OFFLINE TRAINING STATUE
	<action itemid="18488" script="offline_trainer.lua"/> -- OFFLINE TRAINING STATUE

3. Open data/actions/scripts folder, and create a new file called offline_trainer.lua
There you paste the following:
Code:
-- Offline trainers by Hauni :] 
function onUse(cid, item, frompos, item2, topos)

local 		accid 		= 	getAccountNumberByPlayerName(getCreatureName(cid))
local 		name 		= 	getCreatureName(cid)
local       statueIDs          =  { [18492]=8, [18491]=SKILL_DISTANCE,[18490]=SKILL_CLUB, [18489]=SKILL_AXE,[18488]=SKILL_SWORD}

		if statueIDs[item.itemid] then
			 db.query("INSERT INTO offline_training (`account_id`,`name`,`start_training`,`type`) VALUES(".. accid ..",'".. name .."',".. os.time()..",'".. statueIDs[item.itemid] .." ');")
			 doRemoveCreature(cid)
    return
    end
end

4. Soon done now! Now goto your data/creaturscripts/scripts/ find the file called login.lua.
Scroll down to the bottom of the page, and place your marker on a new line before the
"return true
end" sentence, and paste this:

Code:
	-- CONFIG
local       secondsPerHit       = 	2 			-- THE ATTACKSPEED (1 hit per 2 seconds; default) 
local       manaGenPerSec       =   10 			-- MANA USED PER SEC
local       offlineModifier     =   0.5 		-- FROM 0-1 (or higher if you wish). How fast you are skillin on offline training compared to normal (0.5 = 50%)
local 		maxSecondsTraining  =   60 * 60 * 12 -- (Default 12 hours)
--END of config

local 		accid 				= 	getAccountNumberByPlayerName(getCreatureName(cid))
local 		name 				= 	getCreatureName(cid)
local 		checkTraining 		=   db.storeQuery("SELECT * FROM offline_training WHERE `account_id`=".. accid .." AND `name`='".. name .."';")
local skills 					=   {[8]=MAGIC, [4]=SKILL_DISTANCE,[1]=SKILL_CLUB, [3]=SKILL_AXE,[2]=SKILL_SWORD}
local skillNames 					=   {[8]="Magic Level", [4]="Distance Fighting",[1]="Club Fighting", [3]="AxeFighting",[2]="Sword Fighting"}

	if checkTraining then
	
		local skill							 = 	 result.getDataInt(checkTraining, "type")
		local timeTrained					 = 	 result.getDataInt(checkTraining, "start_training")
		local secondsTrained 				 = 	 os.time()-timeTrained 
		local skillTries       				 =   math.floor((secondsTrained/secondsPerHit)*offlineModifier)
		local skillBefore
		local skillAfter
		
		if timeTrained > maxSecondsTraining then
		timeTrained = maxSecondsTraining 
		end
		
		if skill ~= 8 then
		skillBefore 						 = 	 getPlayerSkillLevel(cid, skills[skill])	
		doPlayerAddSkillTry(cid, skills[skill], skillTries)
		skillAfter		  	        		 =   getPlayerSkillLevel(cid, skills[skill])
		else
		skillBefore 						 = getPlayerMagLevel(cid)
		doPlayerAddSpentMana(cid, manaGenPerSec*secondsTrained)
		skillAfter					         = getPlayerMagLevel(cid)
		end
		
		
		local skillBeforeShield      		 =   getPlayerSkillLevel(cid, 5)
		doPlayerAddSkillTry(cid, 5, skillTries)
		local skillAfterShield		  	   	 =   getPlayerSkillLevel(cid, 5)


		
		doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "Your ".. skillNames[skill] .." skill changed from level ".. skillBefore.."  to level ".. skillAfter ..".")
		doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "Your Shielding skill changed from level ".. skillBeforeShield.."  to level ".. skillAfterShield ..". ")

		db.query("DELETE FROM offline_training WHERE `account_id`=".. accid .." AND `name`='".. name .."';")
			
	end

5. Finally, in the same script but at the very end of the file, create a new line and paste this:
Code:
function round(num, idp)
  local mult = 10^(idp or 0)
  return math.floor(num * mult + 0.5) / mult
end

After you have followed these steps, you should have a decent offline trainer script. Just place the offline trainer statues around on the map, and this will take care of
the rest.


Hope you enjoy it! Have fun!
 
Last edited:
Thanks for releasing.

Horrible tabbing though.
Also:
Lua:
if statueIDs[item.itemid] ~= false then

Should be:
Lua:
if statueIDs[item.itemid] then
Though it doesn't matter in that case because other ids arent registered. But nil is unequal to false and would cause "Attempt to concenate nil value" error.
 
It's possible to make in 8.6?

As this one does not send any packets to the client it should be compatible. You just have to use other statues because these wont exist in 8.6
 
@Summ
Thanks for pointing it out!
I have lots of bad excuses, but I'll save them for another time.

Edited it, and fixed a similar case.

The tabbing is nice in my files, but I messed it up upon copying.*

- - - Updated - - -
@LucasFerraz
Yes! Just pick another item for the statues.
The ids are in the actions lua file.
See this line?
Code:
local       statueIDs          =  { [18492]=8, [18491]=SKILL_DISTANCE,[18490]=SKILL_CLUB, [18489]=SKILL_AXE,[18488]=SKILL_SWORD}

The values represent which statue (item id) gives you which skill. Set [18491] to another ID to change the Offline Statue to another item.
 
Last edited:
Include stamina? The Offline Training bar will not decrease, as I stated in the top.
But it can be walked around by for instance instead of halfing the training speed (in the config), you could make it a quarter(0.25)
This would give the same skill result after 24 hours.
 
Its possible, via source code edit now. I dont think any lua functions can remove offline stamina.
Of course, as I said, you can walk around it by decreasing the amount of skill gained by offline training be even 50% more.
 
'lib'
Lua:
-- 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) to 'client'
	-- 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)
	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 (os.time() - getCreatureStorage(cid, 62668)) / 60
end

function OfflineTraining_setLogoutTime(cid)
	return doCreatureSetStorage(cid, 62668, os.time())
end

function OfflineTraining_addTrainedSkills(cid, trainTime) -- time in minutes!
-- addskill etc.
-- not ready
end

function OfflineTraining_canStartTraining(cid)
	return isPremium(cid)
end
(you can edit function OfflineTraining_canStartTraining(cid) to set if after logout [remove creature by script] script should start training, on login always stop training)

login.lua
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)))
	else
		-- offline trainging time also regenerate when you are offline, but NOT train
		OfflineTraining_setTime(cid, OfflineTraining_getTime(cid) + OfflineTraining_getOfflineTime(cid))
	end
	return true
end
logout.lua
Lua:
-- 0.4 - offline training - logout.lua
function onLogout(cid)
	if(OfflineTraining_canStartTraining(cid)) then
		OfflineTraining_turnOnTraining(cid)
	end
	OfflineTraining_setLogoutTime(cid)
	return true
end
I made part of it [must finish function 'OfflineTraining_addTrainedSkills(cid, trainTime)'], it will remove 'offline time' from 'bar' and regenerate like on real tibia (globalevent to add time every minute is not ready yet).

// C++ change to show it on 'bar' - 9.6 ots only
protocolgame.cpp
Find:
[CPP]msg->put<uint16_t>(720);[/CPP]
and replace with:
[CPP] // offline training minutes
std::string strValue;
if(!player->getStorage("62666", strValue))
{
// no storage
msg->put<uint16_t>(0);
}
else
{
msg->put<uint16_t>((uint16_t) atoi(strValue.c_str()));
}[/CPP]
It will show value of storage '62666' on 'bar'. 0 = 0:00, 720 = 12:00 [12 hours, full] - time in minutes.


// I WILL FINISH TOMMOROW AND POST
 
It will use the rates, however in the config on the top you can edit how fast in relation to the normal training you want it to be.
You also need to set how much mana it uses per second :)
 
'lib'
Lua:
-- 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) to 'client'
	-- 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)
	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 (os.time() - getCreatureStorage(cid, 62668)) / 60
end

function OfflineTraining_setLogoutTime(cid)
	return doCreatureSetStorage(cid, 62668, os.time())
end

function OfflineTraining_addTrainedSkills(cid, trainTime) -- time in minutes!
-- addskill etc.
-- not ready
end

function OfflineTraining_canStartTraining(cid)
	return isPremium(cid)
end
(you can edit function OfflineTraining_canStartTraining(cid) to set if after logout [remove creature by script] script should start training, on login always stop training)

login.lua
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)))
	else
		-- offline trainging time also regenerate when you are offline, but NOT train
		OfflineTraining_setTime(cid, OfflineTraining_getTime(cid) + OfflineTraining_getOfflineTime(cid))
	end
	return true
end
logout.lua
Lua:
-- 0.4 - offline training - logout.lua
function onLogout(cid)
	if(OfflineTraining_canStartTraining(cid)) then
		OfflineTraining_turnOnTraining(cid)
	end
	OfflineTraining_setLogoutTime(cid)
	return true
end
I made part of it [must finish function 'OfflineTraining_addTrainedSkills(cid, trainTime)'], it will remove 'offline time' from 'bar' and regenerate like on real tibia (globalevent to add time every minute is not ready yet).

// C++ change to show it on 'bar' - 9.6 ots only
protocolgame.cpp
Find:
[CPP]msg->put<uint16_t>(720);[/CPP]
and replace with:
[CPP] // offline training minutes
std::string strValue;
if(!player->getStorage("62666", strValue))
{
// no storage
msg->put<uint16_t>(0);
}
else
{
msg->put<uint16_t>((uint16_t) atoi(strValue.c_str()));
}[/CPP]
It will show value of storage '62666' on 'bar'. 0 = 0:00, 720 = 12:00 [12 hours, full] - time in minutes.


// I WILL FINISH TOMMOROW AND POST

No msg->put<uint16_t>(720); in my protocolgame.cpp using the las TFS 0.2 [9.6] ;S
 
Back
Top