slaw
Software Developer
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:
Example room:
OK. GOGO !
First we'll add somefunctions if we still havent.
functions.lua (end of file)
Add:
actions.xml
Add:
Create new file data/actions/scripts/training.lua
data/talkactions/talkactions.xml
Add:
Create new file data/talkactions/scripts/training.lua
Last part. Configuration
global.lua (end of file)
Add:
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)
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:
Example room:
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
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: