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

Stop Event

zednem

New Member
Joined
Nov 15, 2008
Messages
108
Reaction score
0
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


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
 
You can put what you want. And it was just example. In script there is already addEvent, you need a little knowledge to edit it. Currently i can't.
 
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)
     stopEvent(setPlayerTrainCode)
     stopEvent(isItEndOfTraining)
     stopEvent(doRemoveCreature)     
    end
end

Test it ;D
 
Didn't work, one question the addevent must be in the same script?

I have this addEvent in script

event1 = addEvent(setPlayerTrainCode, TRAIN_TIME * 1000 * 60, cid)
event2 = addEvent(isItEndOfTraining, (TRAIN_TIME * 1000 * 60) + 30000, cid)
event3 = addEvent(doRemoveCreature, 1 * 60 * 1000, getThingfromPos({x = getPlayerPosition(cid).x - 1, y = getPlayerPosition(cid).y - 1, z = getPlayerPosition(cid).z, stackpos = 253}).uid)
event4 = addEvent(doRemoveCreature, 1 * 60 * 1000, getThingfromPos({x = getPlayerPosition(cid).x + 1, y = getPlayerPosition(cid).y - 1, z = getPlayerPosition(cid).z, stackpos = 253}).uid)
event5 = addEvent(doRemoveCreature, 1 * 60 * 1000, getThingfromPos({x = arenaPos.x - 1, y = arenaPos.y - 1, z = arenaPos.z, stackpos = 253}).uid)
event6 = addEvent(doRemoveCreature, 1 * 60 * 1000, getThingfromPos({x = arenaPos.x + 1, y = arenaPos.y - 1, z = arenaPos.z, stackpos = 253}).uid)

How would be the stopEvents?
 
Last edited:
I put it that way, but the event still running

This function is in functions.lua and the addEvent are there too, but still doesn't stop the events

function doPlayerEndTraining(cid)
local event1 = addEvent(setPlayerTrainCode, TRAIN_TIME * 1000 * 60, cid)
local event2 = addEvent(isItEndOfTraining, (TRAIN_TIME * 1000 * 60) + 30000, cid)
local event3 = addEvent(doRemoveCreature, 1 * 60 * 1000, getThingfromPos({x = getPlayerPosition(cid).x - 1, y = getPlayerPosition(cid).y - 1, z = getPlayerPosition(cid).z, stackpos = 253}).uid)
local event4 = addEvent(doRemoveCreature, 1 * 60 * 1000, getThingfromPos({x = getPlayerPosition(cid).x + 1, y = getPlayerPosition(cid).y - 1, z = getPlayerPosition(cid).z, stackpos = 253}).uid)
local event5 = addEvent(RemoveMonk, 1 * 60 * 1000, cid)

if isPlayerTraining(cid) == TRUE then
stopEvent(event1)
stopEvent(event2)
stopEvent(event3)
stopEvent(event4)
stopEvent(event5)
doTeleportThing(cid, TRAIN_EXIT_POS)
doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
if getPlayerStorageValue(cid, STORAGEVALUE_TRAIN_CODE) ~= 1 then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, '(TrainBot): Você 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
 
Back
Top