My trainer room script. Work with more then one training room place! Tested on TFS 0.2
In data/actions/actions.xml add under <actions>
Create file data/actions/scripts/others/trainer.lua and paste:
In data/movements/movements.xml add under <movements> (2 training centers):
Create file data/movements/scripts/trainer.lua and paste:
Now open data/actions/scripts/other/doors.lua and in place of:
paste:
It doesn't let 2 players enter 1 train room.
Scripts are ready! Now map.
Tiles:
Action IDs:
Remember to set Action ID 1000+level required to enter on trainer room doors.
Players can login/logout in trainer room.
In data/actions/actions.xml add under <actions>
PHP:
<action actionid="39000" script="other/trainer.lua"/>
PHP:
max_afk_time = 300
function onUse(cid, item, fromPosition, itemEx, toPosition)
setPlayerStorageValue(cid, 39000, os.time()+max_afk_time)
doPlayerSendCancel(cid, 'Now is ' .. os.date("%H:%M:%S", os.time()) .. '. You will be kicked from train room at ' .. os.date("%H:%M:%S", os.time()+max_afk_time) .. '!')
if item.itemid == 1945 then
doTransformItem(item.uid, 1946, 1)
elseif item.itemid == 1946 then
doTransformItem(item.uid, 1945, 1)
end
return TRUE
end
PHP:
<movevent event="StepIn" actionid="39001" script="trainer.lua"/>
<movevent event="StepOut" actionid="39001" script="trainer.lua"/>
<movevent event="StepIn" actionid="39002" script="trainer.lua"/>
<movevent event="StepOut" actionid="39002" script="trainer.lua"/>
PHP:
kick_position = {}
players_train = {}
check_train = 0
max_afk_time = 300
kick_position[1] = {x=1027,y=1046,z=7}
kick_position[2] = {x=1027,y=1047,z=6}
function onStepIn(cid, item, pos)
if check_train == 0 then
check_train = addEvent(checkTrainRooms, 1000, {action=1})
end
setPlayerStorageValue(cid, 39000, os.time()+max_afk_time)
setPlayerStorageValue(cid, 39001, item.actionid-39000)
table.insert(players_train,cid)
doPlayerSendTextMessage(cid,MESSAGE_EVENT_DEFAULT,'You must push lever every 10 minutes or you will be kicked from train room!')
return TRUE
end
function onStepOut(cid, item, pos)
setPlayerStorageValue(cid, 39000, 0)
setPlayerStorageValue(cid, 39001, 0)
for targetID,creature in ipairs(players_train) do
if creature == cid then
table.remove(players_train,targetID)
end
end
return TRUE
end
function checkTrainRooms(param)
local cid = param.cid
if param.action == 1 then
for targetID,creature in ipairs(players_train) do
if isPlayer(creature) == TRUE then
local player_storage = getPlayerStorageValue(creature, 39000)
if player_storage <= os.time() then
doTeleportThing(creature, kick_position[getPlayerStorageValue(creature, 39001)], TRUE)
setPlayerStorageValue(creature, 39000, 0)
setPlayerStorageValue(creature, 39001, 0)
table.remove(players_train,targetID)
doPlayerSendTextMessage(creature,MESSAGE_STATUS_CONSOLE_ORANGE,'You were kicked from train room! Come back later!')
elseif player_storage - 10 <= os.time() then
doPlayerSendTextMessage(creature,MESSAGE_EVENT_DEFAULT,'You got ' .. player_storage - os.time() .. ' seconds to push lever or you will be kicked from train room!')
end
else
table.remove(players_train,targetID)
end
end
addEvent(checkTrainRooms, 1000, {action=1})
end
end
PHP:
elseif isInArray(horizontalOpenDoors, item.itemid) == TRUE then
local newPosition = toPosition
newPosition.y = newPosition.y + 1
local doorPosition = fromPosition
doorPosition.stackpos = STACKPOS_TOP_MOVEABLE_ITEM_OR_CREATURE
local doorCreature = getThingfromPos(doorPosition)
if doorCreature.itemid ~= 0 then
if getTilePzInfo(doorPosition) == TRUE and getTilePzInfo(newPosition) == FALSE and doorCreature.uid ~= cid then
doPlayerSendCancel(cid, "Sorry, not possible.")
else
doTeleportThing(doorCreature.uid, newPosition, TRUE)
if isInArray(openSpecialDoors, item.itemid) ~= TRUE then
doTransformItem(item.uid, item.itemid - 1)
end
end
return TRUE
end
doTransformItem(item.uid, item.itemid - 1)
return TRUE
elseif isInArray(verticalOpenDoors, item.itemid) == TRUE then
local newPosition = toPosition
newPosition.x = newPosition.x + 1
local doorPosition = fromPosition
doorPosition.stackpos = STACKPOS_TOP_MOVEABLE_ITEM_OR_CREATURE
local doorCreature = getThingfromPos(doorPosition)
if doorCreature.itemid ~= 0 then
if getTilePzInfo(doorPosition) == TRUE and getTilePzInfo(newPosition) == FALSE and doorCreature.uid ~= cid then
doPlayerSendCancel(cid, "Sorry, not possible.")
else
doTeleportThing(doorCreature.uid, newPosition, TRUE)
if isInArray(openSpecialDoors, item.itemid) ~= TRUE then
doTransformItem(item.uid, item.itemid - 1)
end
end
return TRUE
end
doTransformItem(item.uid, item.itemid - 1)
return TRUE
PHP:
elseif isInArray(horizontalOpenDoors, item.itemid) == TRUE then
local newPosition = toPosition
newPosition.y = newPosition.y + 1
local doorPosition = fromPosition
doorPosition.stackpos = STACKPOS_TOP_CREATURE
local doorCreature = getThingfromPos(doorPosition)
if doorCreature.itemid ~= 0 then
if getTilePzInfo(doorPosition) == TRUE and getTilePzInfo(newPosition) == FALSE and (isCreature(doorCreature.uid) == TRUE) then
doPlayerSendCancel(cid, "Someone block doors.")
else
doTeleportThing(doorCreature.uid, newPosition, TRUE)
if isInArray(openSpecialDoors, item.itemid) ~= TRUE then
doTransformItem(item.uid, item.itemid - 1)
end
end
return TRUE
end
doTransformItem(item.uid, item.itemid - 1)
return TRUE
elseif isInArray(verticalOpenDoors, item.itemid) == TRUE then
local newPosition = toPosition
newPosition.x = newPosition.x + 1
local doorPosition = fromPosition
doorPosition.stackpos = STACKPOS_TOP_CREATURE
local doorCreature = getThingfromPos(doorPosition)
if doorCreature.itemid ~= 0 then
if getTilePzInfo(doorPosition) == TRUE and getTilePzInfo(newPosition) == FALSE and (isCreature(doorCreature.uid) == TRUE) then
doPlayerSendCancel(cid, "Sorry, not possible.")
else
doTeleportThing(doorCreature.uid, newPosition, TRUE)
if isInArray(openSpecialDoors, item.itemid) ~= TRUE then
doTransformItem(item.uid, item.itemid - 1)
end
end
return TRUE
end
doTransformItem(item.uid, item.itemid - 1)
return TRUE
Scripts are ready! Now map.
Tiles:
Action IDs:
Remember to set Action ID 1000+level required to enter on trainer room doors.
Players can login/logout in trainer room.
Last edited by a moderator: