I have a script of training, but it has a problema, he works with addevent, so if a player left the training the addevent still run and when he come back, bugs the script, so how do a make to stop that events when the players get out of the trainer
function doPlayerEndTraining below
Code:
--------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 = '(TrainBot): Seu treino começou. Após '.. getMinExtend(TRAIN_TIME) ..' vc precisará escrever o código para extender o treino.'
if TRAIN_PRICE > 0 and getPlayerSkillLevel(cid, 1) >= 100 or getPlayerSkillLevel(cid, 2) >= 100 or getPlayerSkillLevel(cid, 3) >= 100 or getPlayerSkillLevel(cid, 4) >= 100 or getPlayerSkillLevel(cid, 5) >= 100 or getPlayerMagLevel(cid) >= 100 then
text = text..', e vc terá que pagar '.. TRAIN_PRICE ..' gp para continuar treinando.'
end
text = text..'.'
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, text)
setPlayerStorageValue(cid, STORAGEVALUE_TRAINING, 1)
addEvent(setPlayerTrainCode, TRAIN_TIME * 1000 * 60, cid)
addEvent(isItEndOfTraining, (TRAIN_TIME * 1000 * 60) + 30000, 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, '(TrainBot): Trainer em uso.')
doSendMagicEffect(getCreaturePosition(cid), 2)
else
if playerStartTraining(cid) == TRUE then
setPlayerStorageValue(cid, 8765, 1)
doTeleportThing(cid, arenaPos, FALSE)
doSummonCreature("Trainer", {x = arenaPos.x - 1, y = arenaPos.y - 1, z = arenaPos.z})
doSummonCreature("Trainer", {x = arenaPos.x + 1, y = arenaPos.y - 1, z = arenaPos.z})
doSendMagicEffect(getThingPos(item.uid), 21)
addEvent(doRemoveCreature, 1 * 60 * 1000, getThingfromPos({x = arenaPos.x - 1, y = arenaPos.y - 1, z = arenaPos.z, stackpos = 253}).uid)
addEvent(doRemoveCreature, 1 * 60 * 1000, getThingfromPos({x = arenaPos.x + 1, y = arenaPos.y - 1, z = arenaPos.z, stackpos = 253}).uid)
end
end
else
local doorPos = getThingPos(item.uid)
doRemoveCreature(getThingfromPos({x = arenaPos.x - 1, y = arenaPos.y - 1, z = arenaPos.z, stackpos = 253}).uid)
doRemoveCreature(getThingfromPos({x = arenaPos.x + 1, y = arenaPos.y - 1, z = arenaPos.z, stackpos = 253}).uid)
local charName = getCreatureName(cid)
doSetItemSpecialDescription(getThingfromPos({x = arenaPos.x, y = arenaPos.y + 1, z = arenaPos.z, stackpos = 1}).uid, "(TrainBot): Último player a usar esta cabine:\n" .. charName .. ".")
doPlayerEndTraining(cid)
end
end
return TRUE
end
function doPlayerEndTraining below
Code:
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, '(TrainBot): Vc não digitou o codigo...')
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, '(TrainBot): Acabou o seu treino.')
end
setPlayerStorageValue(cid, STORAGEVALUE_TRAINING, 0)
setPlayerStorageValue(cid, STORAGEVALUE_TRAIN_CODE, 0)
end
end