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

[Advanced] Training System with anti-bot protection !

Status
Not open for further replies.

slaw

Software Developer
Joined
Aug 27, 2007
Messages
3,670
Solutions
125
Reaction score
1,117
Location
Germany
GitHub
slawkens
HOW IT WORKS?

Player ENTER a special training room. After some time he'll get message with 4-letter anti-bot code. If he'll write !train "xxxx training will be extented. If code wont be valid, or he wont wrote it he'll be teleported (configurable).

Some screen at START: :p
Example room:
howtotrainersvm2.jpg


train1bi6.jpg


OK. GOGO !

First we'll add somefunctions if we still havent.

functions.lua (end of file)

Add:
Lua:
function getNextPosFromDir(fromPos, dir, size)
	local newPos =
	{
		[0]={x=fromPos.x,	y=fromPos.y-size,	z=fromPos.z}, 
		[1]={x=fromPos.x+size,	y=fromPos.y,		z=fromPos.z}, 
		[2]={x=fromPos.x,	y=fromPos.y+size,	z=fromPos.z}, 
		[3]={x=fromPos.x-size,	y=fromPos.y,		z=fromPos.z}
	}
	return newPos[dir]
end

function isPlayerTraining(cid)
	return (getPlayerStorageValue(cid, STORAGEVALUE_TRAINING) > 0)
end

function getMinExtend(time)
	min = 'minutes'
	if time == 1 then
		min = 'minute'
	end
	return  time..' '..min
end

function doPlayerEndTraining(cid)
	if isPlayerTraining(cid) == TRUE then
		doTeleportThing(cid, TRAIN_EXIT_POS, FALSE)
		doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
		if getPlayerStorageValue(cid, STORAGEVALUE_TRAIN_CODE) > 1 then
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, '(TrainMod): You didnt wrote code...')
		else
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, '(TrainMod): Its end of your training.')
		end
		setPlayerStorageValue(cid, STORAGEVALUE_TRAINING, 0)
		setPlayerStorageValue(cid, STORAGEVALUE_TRAIN_CODE, 0)

	end
end

function setPlayerTrainCode(cid)
	if isPlayerTraining(cid) == TRUE then
		code = math.random(1000, 9999)
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, '(TrainMod): If you want still train you need to write !train 

"'.. code ..'. You have 20 seconds to write it.')
		setPlayerStorageValue(cid, STORAGEVALUE_TRAIN_CODE, code)
	end
end

function isItEndOfTraining(cid)
	if getPlayerStorageValue(cid, STORAGEVALUE_TRAIN_CODE) ~= 1 then
		doPlayerEndTraining(cid)
	end
end

function doPlayerExtendTraining(cid)
	addEvent(setPlayerTrainCode, TRAIN_TIME * 1000 * 60, cid)
	addEvent(isItEndOfTraining, (TRAIN_TIME * 1000 * 60) + 20000, cid)
end

actions.xml

Add:
Lua:
	<!-- Training by slawkens -->
	<action fromaid="20000" toaid="20003" script="training.lua"/>

Create new file data/actions/scripts/training.lua
Lua:
--------CONFIG--------
local fromActionId = 20000 -- actions id used. (default: 20000). If you change it, you also need change in actions.xml

local function playerStartTraining(cid)
	local text = '(TrainMod): Your training started. After '.. getMinExtend(TRAIN_TIME) ..' you\'ll need to write code to extend training'
	if TRAIN_PRICE > 0 then
		text = text..', and you have to pay '.. TRAIN_PRICE ..' gp to continue this training'
	end
	text = text..'.'
	doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, text)
	setPlayerStorageValue(cid, STORAGEVALUE_TRAINING, 1)
	doPlayerExtendTraining(cid)
	return TRUE
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
	if item.actionid >= fromActionId and item.actionid <= (fromActionId + 3) then
		dir = item.actionid - fromActionId
		arenaPos = getNextPosFromDir(fromPosition, (item.actionid - fromActionId), 1)
		arenaPos.stackpos = STACKPOS_TOP_CREATURE
		if isPlayerTraining(cid) ~= TRUE then
			if getThingfromPos(arenaPos).uid ~= 0 then
				doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, '(TrainMod): Room is full.')
				doSendMagicEffect(getCreaturePosition(cid), 2)
			else
				if playerStartTraining(cid) == TRUE then
					doTeleportThing(cid, arenaPos, FALSE)
					doSendMagicEffect(getThingPos(item.uid), 21)
				end
			end
		else
			doPlayerEndTraining(cid)
		end
	end
	return TRUE
end

data/talkactions/talkactions.xml

Add:
PHP:
<talkaction words="!train" script="training.lua"/>

Create new file data/talkactions/scripts/training.lua
Lua:
function onSay(cid, words, param)
	if isPlayerTraining(cid) == TRUE then
		if getPlayerStorageValue(cid, STORAGEVALUE_TRAIN_CODE) ~= 1 then
			if tonumber(param) == getPlayerStorageValue(cid, STORAGEVALUE_TRAIN_CODE) then
				if TRAIN_PRICE > 0 then
					if doPlayerRemoveMoney(cid, TRAIN_PRICE) == FALSE then
						doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, '(TrainMod): Sorry, training 

cost '.. TRAIN_PRICE ..' gp for every '.. getMinExtend(TRAIN_TIME) ..'.')
						doPlayerEndTraining(cid)
						return FALSE
					end
				end
				doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, '(TrainMod): Training extended. Next code 

after: '.. getMinExtend(TRAIN_TIME) ..'.')
				setPlayerStorageValue(cid, STORAGEVALUE_TRAIN_CODE, 1)
				doPlayerExtendTraining(cid)
			else
				doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, '(TrainMod): Code is wrong!')
			end
		else
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, '(TrainMod): Code is no need now...')
		end
	end
return FALSE
end

Last part. Configuration :D

global.lua (end of file)

Add:
Lua:
STORAGEVALUE_TRAINING = 9011

STORAGEVALUE_TRAIN_CODE = 9012
-- how often player will be asked for CODE ( in MINUTES )
TRAIN_TIME = 15 --in minutes
-- POSITION where player will be teleported after LEAVING room
TRAIN_EXIT_POS = {x=167, y=53, z=7}
TRAIN_PRICE = 500

Changelog:
[v1.0.0]
- First relase.
[v1.0.1]
- Added configurable TRAIN_PRICE. Set to 0 if train will be free.
- Fixed bug with not reseted storage value with code after leaving room
- Files affected: all ; o (That means that you need to update them all without actions.xml)
[v1.0.2]
- Fixed wrong TIME counting.
- Files affected: functions.lua. Function: doPlayerExtendTraining(cid)
 
Last edited:
Thank you man. I think about clicking on laver but this idea rox ;D
 
This is so great! What i needed, thanks mate!
 
Oh, Slawkens, I was just about to ask you about sharing that ;D Nice ;)

@Slawkens - a co z wodzi?
 
What is the diffrence between the action ids? Is it depending on how the door is placed? etc: north/south, or west/east? Or how many training rooms you got?
 
Yes it can lagg the server a bit. Even Traning room laggs ur server, try to walk around traning room and u can feel the laggs. I think that this will lagg since everyplayer gets a new code every 5 minutes.

On Xml Servers laggs when gm write all the time on broadcast :p but i dont know how is it on sql :p

@Znote
It depends where the doors are placed ( on what position ) :p
 
Well, I've test it and I think it isn't save cuz if player enter to the train room and he logout there then event stopped, and when he login again he can stay here without entering code etc..
 
Yyy, sorry, but i thought that in training you cant logout :p Or maybe you have changed it on your server?
 
Last edited:
Just make it non-logoutable, dunno if there is a tile for that, but it can be done with mayNotLogout(cid, 1)(?)
 
Yes you cant logout since u get pz locked after "traning monk" see you :p
but well on some 8.0 otservers is it possible to logout while having pz or even beeing attacked, If you dont move then u are gonna be kicked afer 15 minutes, dont know if its work on TFS :)
 
Opps my bad, sry man :p, anyway.. you can give "exit" ;) and after login you'll be in training room :).

#edit

doSendMagicEffect(getCreaturePosition(cid), 21)
(action) I think it doesnt send effect..
 
Last edited:
pretty each to counter this, I can write a blackd script in less then 3 mins that totally makes the code thing useless
 
Actually there are not things which peoples cant cheat, crack. Of course now peoples know that its possible to do with blackd as you said, and more will try it :rolleyes:
 
Just use macro if there are a lever, if you need to write !train just put spell caster or smth
 
slawkens very nice script.

i wonder if you can edit this script so after x minutes / hours the player will pay x gold to train.

(Traninmode) your traning started. after x minutes you'll need to write a code to extend training and you have to pay x gold to continue this traning.
 
slawkens, there is any protection against that if someone exit from the game and if login again anti-afk will started again ?
 
Status
Not open for further replies.
Back
Top