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

TFS 0.X [7.72] Globalevent that starts an event

potinho

Advanced OT User
Joined
Oct 11, 2009
Messages
1,402
Solutions
17
Reaction score
150
Location
Brazil
Good morning guys, I have a MOD that is an event for my server, it works perfectly, but I always have to start it manually, typing "! start". I would like to put a globalevent that would start this event for me every day, at 8:00 PM. Could you show me how to do it?
 
Solution
You can also use this file that I modify for you, and then you can use the following function to execute the event: StartRushEvent()

example:
Lua:
function onTime()
    StartRushEvent()
    return true
end
XML:
<globalevent name="startEvent" time="20:00" event="script" value="startEvent.lua"/>
Lua:
function onTime() -- might be onTimer.. not sure
    -- do whatever you need to do to start the event
    return true
end
 
XML:
<globalevent name="startEvent" time="20:00" event="script" value="startEvent.lua"/>
Lua:
function onTime() -- might be onTimer.. not sure
    -- do whatever you need to do to start the event
    return true
end
Got error:

[26/3/2021 12:14:26] [Error - LuaInterface::loadFile] data/globalevents/scripts/startEvent.lua:2: unexpected symbol near '!'
[26/3/2021 12:14:26] [Error - Event::checkScript] Cannot load script (data/globalevents/scripts/startEvent.lua)
[26/3/2021 12:14:26] data/globalevents/scripts/startEvent.lua:2: unexpected symbol near '!'

I guess my code is not just like bellow, i dont understand too much about LUA

Lua:
function onTime() -- might be onTimer.. not sure
 doCreatureExecuteTalkAction(cid, "!start", true) 
    return true
end
 
Last edited:
Got error:

[26/3/2021 12:14:26] [Error - LuaInterface::loadFile] data/globalevents/scripts/startEvent.lua:2: unexpected symbol near '!'
[26/3/2021 12:14:26] [Error - Event::checkScript] Cannot load script (data/globalevents/scripts/startEvent.lua)
[26/3/2021 12:14:26] data/globalevents/scripts/startEvent.lua:2: unexpected symbol near '!'

I guess my code is not just like bellow, i dont understand too much about LUA

Lua:
function onTime() -- might be onTimer.. not sure
    !start
    return true
end
Try this.
Lua:
function onTime() -- might be onTimer.. not sure
    for _, pid in ipairs(players) do
		doCreatureExecuteTalkAction(pid, "!start", true)
		return true
	end
    return true
end
 
Try this.
Lua:
function onTime() -- might be onTimer.. not sure
    for _, pid in ipairs(players) do
        doCreatureExecuteTalkAction(pid, "!start", true)
        return true
    end
    return true
end
Got error too:

[26/3/2021 12:24:0] [Error - GlobalEvent Interface]
[26/3/2021 12:24:0] data/globalevents/scripts/startEvent.lua:eek:nTime
[26/3/2021 12:24:0] Description:
[26/3/2021 12:24:0] data/globalevents/scripts/startEvent.lua:2: bad argument #1 to 'ipairs' (table expected, got nil)
[26/3/2021 12:24:0] stack traceback:
[26/3/2021 12:24:0] [C]: in function 'ipairs'
[26/3/2021 12:24:0] data/globalevents/scripts/startEvent.lua:2: in function <data/globalevents/scripts/startEvent.lua:1>
[26/3/2021 12:24:0] [Error - GlobalEvents::timer] Couldn't execute event: startEvent
 
Got error too:

[26/3/2021 12:24:0] [Error - GlobalEvent Interface]
[26/3/2021 12:24:0] data/globalevents/scripts/startEvent.lua:eek:nTime
[26/3/2021 12:24:0] Description:
[26/3/2021 12:24:0] data/globalevents/scripts/startEvent.lua:2: bad argument #1 to 'ipairs' (table expected, got nil)
[26/3/2021 12:24:0] stack traceback:
[26/3/2021 12:24:0] [C]: in function 'ipairs'
[26/3/2021 12:24:0] data/globalevents/scripts/startEvent.lua:2: in function <data/globalevents/scripts/startEvent.lua:1>
[26/3/2021 12:24:0] [Error - GlobalEvents::timer] Couldn't execute event: startEvent
oops.
change players for getPlayersOnline()
 
Now nothing happens. Console get no error but not happens in game.
Alright new plan.
Lua:
function onTime() -- might be onTimer.. not sure
    for _, pid in ipairs(getPlayersOnline()) do
		doCreatureExecuteTalkAction(pid, "!start", true)
		print("" .. getCreatureName(pid) .. " started the event!")
		return true
	end
	print("Unable to start the event, as no players are online.")
    return true
end
 
Alright new plan.
Lua:
function onTime() -- might be onTimer.. not sure
    for _, pid in ipairs(getPlayersOnline()) do
        doCreatureExecuteTalkAction(pid, "!start", true)
        print("" .. getCreatureName(pid) .. " started the event!")
        return true
    end
    print("Unable to start the event, as no players are online.")
    return true
end
Nothing happens in game, but my console got this:

[26/3/2021 12:36:0] Aldebaron started the event!

Aldebaron is a player. No message appear for him or in the game.
 
Nothing happens in game, but my console got this:

[26/3/2021 12:36:0] Aldebaron started the event!

Aldebaron is a player. No message appear for him or in the game.
Should work.

Just to make sure that the creature is actually using a talkaction.. try with some other known talkaction.. like this I guess
Lua:
function onTime() -- might be onTimer.. not sure
    for _, pid in ipairs(getPlayersOnline()) do
		doCreatureExecuteTalkAction(pid, "/x 1", true) -- should do the spray of projectiles
		print("" .. getCreatureName(pid) .. " started the event!")
		return true
	end
	print("Unable to start the event, as no players are online.")
    return true
end

If the above works.. then !start isn't a known talkaction.. I guess?

If the above doesn't work... then you'll need to put all of the event's start functions into the script.
 
It is better that you look in your MOD, the function that triggers the start of the event and call this function directly, instead of simulating that an Admin writes and says the command, there is not always a player with privileges online
 
Should work.

Just to make sure that the creature is actually using a talkaction.. try with some other known talkaction.. like this I guess
Lua:
function onTime() -- might be onTimer.. not sure
    for _, pid in ipairs(getPlayersOnline()) do
        doCreatureExecuteTalkAction(pid, "/x 1", true) -- should do the spray of projectiles
        print("" .. getCreatureName(pid) .. " started the event!")
        return true
    end
    print("Unable to start the event, as no players are online.")
    return true
end

If the above works.. then !start isn't a known talkaction.. I guess?

If the above doesn't work... then you'll need to put all of the event's start functions into the script.


Not work, here's the talkaction (inside my MOD file), who i use to starts event.



XML:
<talkaction words="!start" event="script"><![CDATA[
    domodlib('eventConfig')
    function onSay(cid, words, param, channel)
        if getPlayerGroupId(cid) > 3 then
            setGlobalStorageValue(rushConfig.stateIndice, 1)
            setGlobalStorageValue(rushConfig.scoreBlue, 0)
            setGlobalStorageValue(rushConfig.scoreRed, 0)
            setGlobalStorageValue(rushConfig.stateSignup, 1)
            setGlobalStorageValue(rushConfig.stateAttend, 0)
            setGlobalStorageValue(rushConfig.stateBegun, 0)
            local message = string.format("Attention! %s will start in %s minutes. %s", rushConfig.eventName, rushConfig.preamble, rushConfig.joinHow)
            doBroadcastMessage(message, MESSAGE_STATUS_WARNING)

            local function broadcaster( minutes )
                if(minutes == 1) then
                    doBroadcastMessage(rushConfig.eventName .. ", starts in a minute. Last chance to join: !battle", MESSAGE_STATUS_WARNING)
                    return true;
                end
                doBroadcastMessage(rushConfig.eventName .. ", starts in " .. minutes .. rushConfig.joinHow, MESSAGE_STATUS_WARNING)
            end

            if(rushConfig.preamble > 5) then addEvent(broadcaster, (rushConfig.preamble - 4) * 1000 * 60, 4) end
            if(rushConfig.preamble > 4) then addEvent(broadcaster, (rushConfig.preamble - 3) * 1000 * 60, 3) end
            if(rushConfig.preamble > 3) then addEvent(broadcaster, (rushConfig.preamble - 2) * 1000 * 60, 2) end
            if(rushConfig.preamble > 2) then addEvent(broadcaster, (rushConfig.preamble - 1) * 1000 * 60, 1) end
            addEvent(start, rushConfig.preamble * 1000 * 60)
            return true
        end
        return true
    end

    function results()
        if(getGlobalStorageValue(rushConfig.stateSignup) == 1) then
            local red = getGlobalStorageValue(rushConfig.scoreRed)
            local blue = getGlobalStorageValue(rushConfig.scoreBlue)          
            doBroadcastMessage(rushConfig.eventName .. " results:\nRed Team scored: ".. red .." frags.\nBlue Team scored: ".. blue .." frags.\nMatch is under way to ".. rushConfig.scoreWin .." frags.", MESSAGE_STATUS_WARNING)
            addEvent(results, rushConfig.results * 1000 * 60)
        end
    end

    function start()
        if(getGlobalStorageValue(rushConfig.stateSignup) == 1 and getGlobalStorageValue(rushConfig.stateAttend) >= rushConfig.minAttend) then
            doBroadcastMessage(rushConfig.announce, MESSAGE_STATUS_WARNING)
            setGlobalStorageValue(rushConfig.stateBegun, 1)
            addEvent(results, rushConfig.results * 1000 * 60)
            for _, pid in ipairs(getPlayersOnline()) do
                local myOutfit = getCreatureOutfit(pid)
                local red = {lookType = myOutfit.lookType, lookHead = 94, lookBody = 94, lookLegs = 94, lookFeet = 94, lookTypeEx = 0, lookAddons = myOutfit.lookAddons}
                local blue = {lookType = myOutfit.lookType, lookHead = 86, lookBody = 86, lookLegs = 86, lookFeet = 86, lookTypeEx = 0, lookAddons = myOutfit.lookAddons}
                if getPlayerStorageValue(pid, rushConfig.registered) == 1 then
                    doCreatureAddHealth(pid, getCreatureMaxHealth(pid))
                    doCreatureAddMana(pid, getCreatureMaxMana(pid))
                    if((getPlayerStorageValue(pid, rushConfig.stateIndice) % 2) == 1) then
                        doCreatureChangeOutfit(pid, red)
                        setPlayerStorageValue(pid, rushConfig.inArena, 1)
                        doTeleportThing(pid, rushConfig.posTeamRed)
                        setPlayerStorageValue(pid, rushConfig.registered, 1)
                        setPlayerStorageValue(pid, rushConfig.onTeamBlue, 0)
                        setPlayerStorageValue(pid, rushConfig.onTeamRed, 1)
                        doSendMagicEffect(getCreaturePosition(pid), 10)
                        doPlayerSendTextMessage(pid, MESSAGE_EVENT_ADVANCE, "You are in RED TEAM!\nThis battle will continue up to ".. rushConfig.scoreWin .." frags!")
                    else
                        doCreatureChangeOutfit(pid, blue)
                        doTeleportThing(pid, rushConfig.posTeamBlue)
                        setPlayerStorageValue(pid, rushConfig.inArena, 1)
                        setPlayerStorageValue(pid, rushConfig.registered, 1)
                        setPlayerStorageValue(pid, rushConfig.onTeamBlue, 1)
                        setPlayerStorageValue(pid, rushConfig.onTeamRed, 0)
                        doSendMagicEffect(getCreaturePosition(pid), 10)
                        doPlayerSendTextMessage(pid, MESSAGE_EVENT_ADVANCE, "You are in BLUE TEAM!\nThis battle will continue up to ".. rushConfig.scoreWin .." frags!")
                    end
                end
            end
        elseif(getGlobalStorageValue(rushConfig.stateAttend) < rushConfig.minAttend) then
            doBroadcastMessage(rushConfig.whyBother, MESSAGE_STATUS_WARNING)
            setGlobalStorageValue(rushConfig.stateSignup, -1)
            for _, pid in ipairs(getPlayersOnline()) do
                if getPlayerStorageValue(pid, rushConfig.registered) == 1 then
                    setPlayerStorageValue(pid, rushConfig.registered, -1)
                    doTeleportThing(pid, getTownTemplePosition(getPlayerTown(pid)))
                    doSendMagicEffect(getCreaturePosition(pid), CONST_ME_TELEPORT)
                end
            end
        end
    end
]]></talkaction>
Post automatically merged:

It is better that you look in your MOD, the function that triggers the start of the event and call this function directly, instead of simulating that an Admin writes and says the command, there is not always a player with privileges online
u can show me how? Attaching my complete MOD file
 

Attachments

It is better that you look in your MOD, the function that triggers the start of the event and call this function directly, instead of simulating that an Admin writes and says the command, there is not always a player with privileges online
That's what 'true' is for. It ignores the access required.

XML:
<talkaction words="!start" access="5" event="script"><![CDATA[
    domodlib('eventConfig')
    function onSay(cid, words, param, channel)
        setGlobalStorageValue(rushConfig.stateIndice, 1)
        setGlobalStorageValue(rushConfig.scoreBlue, 0)
        setGlobalStorageValue(rushConfig.scoreRed, 0)
        setGlobalStorageValue(rushConfig.stateSignup, 1)
        setGlobalStorageValue(rushConfig.stateAttend, 0)
        setGlobalStorageValue(rushConfig.stateBegun, 0)
        local message = string.format("Attention! %s will start in %s minutes. %s", rushConfig.eventName, rushConfig.preamble, rushConfig.joinHow)
        doBroadcastMessage(message, MESSAGE_STATUS_WARNING)

        local function broadcaster( minutes )
            if(minutes == 1) then
                doBroadcastMessage(rushConfig.eventName .. ", starts in a minute. Last chance to join: !battle", MESSAGE_STATUS_WARNING)
                return true;
            end
            doBroadcastMessage(rushConfig.eventName .. ", starts in " .. minutes .. rushConfig.joinHow, MESSAGE_STATUS_WARNING)
        end

        if(rushConfig.preamble > 5) then addEvent(broadcaster, (rushConfig.preamble - 4) * 1000 * 60, 4) end
        if(rushConfig.preamble > 4) then addEvent(broadcaster, (rushConfig.preamble - 3) * 1000 * 60, 3) end
        if(rushConfig.preamble > 3) then addEvent(broadcaster, (rushConfig.preamble - 2) * 1000 * 60, 2) end
        if(rushConfig.preamble > 2) then addEvent(broadcaster, (rushConfig.preamble - 1) * 1000 * 60, 1) end
        addEvent(start, rushConfig.preamble * 1000 * 60)
        return true
    end

    function results()
        if(getGlobalStorageValue(rushConfig.stateSignup) == 1) then
            local red = getGlobalStorageValue(rushConfig.scoreRed)
            local blue = getGlobalStorageValue(rushConfig.scoreBlue)           
            doBroadcastMessage(rushConfig.eventName .. " results:\nRed Team scored: ".. red .." frags.\nBlue Team scored: ".. blue .." frags.\nMatch is under way to ".. rushConfig.scoreWin .." frags.", MESSAGE_STATUS_WARNING)
            addEvent(results, rushConfig.results * 1000 * 60)
        end
    end

    function start()
        if(getGlobalStorageValue(rushConfig.stateSignup) == 1 and getGlobalStorageValue(rushConfig.stateAttend) >= rushConfig.minAttend) then
            doBroadcastMessage(rushConfig.announce, MESSAGE_STATUS_WARNING)
            setGlobalStorageValue(rushConfig.stateBegun, 1)
            addEvent(results, rushConfig.results * 1000 * 60)
            for _, pid in ipairs(getPlayersOnline()) do
                local myOutfit = getCreatureOutfit(pid)
                local red = {lookType = myOutfit.lookType, lookHead = 94, lookBody = 94, lookLegs = 94, lookFeet = 94, lookTypeEx = 0, lookAddons = myOutfit.lookAddons}
                local blue = {lookType = myOutfit.lookType, lookHead = 86, lookBody = 86, lookLegs = 86, lookFeet = 86, lookTypeEx = 0, lookAddons = myOutfit.lookAddons}
                if getPlayerStorageValue(pid, rushConfig.registered) == 1 then
                    doCreatureAddHealth(pid, getCreatureMaxHealth(pid))
                    doCreatureAddMana(pid, getCreatureMaxMana(pid))
                    if((getPlayerStorageValue(pid, rushConfig.stateIndice) % 2) == 1) then
                        doCreatureChangeOutfit(pid, red)
                        setPlayerStorageValue(pid, rushConfig.inArena, 1)
                        doTeleportThing(pid, rushConfig.posTeamRed)
                        setPlayerStorageValue(pid, rushConfig.registered, 1)
                        setPlayerStorageValue(pid, rushConfig.onTeamBlue, 0)
                        setPlayerStorageValue(pid, rushConfig.onTeamRed, 1)
                        doSendMagicEffect(getCreaturePosition(pid), 10)
                        doPlayerSendTextMessage(pid, MESSAGE_EVENT_ADVANCE, "You are in RED TEAM!\nThis battle will continue up to ".. rushConfig.scoreWin .." frags!")
                    else
                        doCreatureChangeOutfit(pid, blue)
                        doTeleportThing(pid, rushConfig.posTeamBlue)
                        setPlayerStorageValue(pid, rushConfig.inArena, 1)
                        setPlayerStorageValue(pid, rushConfig.registered, 1)
                        setPlayerStorageValue(pid, rushConfig.onTeamBlue, 1)
                        setPlayerStorageValue(pid, rushConfig.onTeamRed, 0)
                        doSendMagicEffect(getCreaturePosition(pid), 10)
                        doPlayerSendTextMessage(pid, MESSAGE_EVENT_ADVANCE, "You are in BLUE TEAM!\nThis battle will continue up to ".. rushConfig.scoreWin .." frags!")
                    end
                end
            end
        elseif(getGlobalStorageValue(rushConfig.stateAttend) < rushConfig.minAttend) then
            doBroadcastMessage(rushConfig.whyBother, MESSAGE_STATUS_WARNING)
            setGlobalStorageValue(rushConfig.stateSignup, -1)
            for _, pid in ipairs(getPlayersOnline()) do
                if getPlayerStorageValue(pid, rushConfig.registered) == 1 then
                    setPlayerStorageValue(pid, rushConfig.registered, -1)
                    doTeleportThing(pid, getTownTemplePosition(getPlayerTown(pid)))
                    doSendMagicEffect(getCreaturePosition(pid), CONST_ME_TELEPORT)
                end
            end
        end
    end
]]></talkaction>
 
That's what 'true' is for. It ignores the access required.

XML:
<talkaction words="!start" access="5" event="script"><![CDATA[
    domodlib('eventConfig')
    function onSay(cid, words, param, channel)
        setGlobalStorageValue(rushConfig.stateIndice, 1)
        setGlobalStorageValue(rushConfig.scoreBlue, 0)
        setGlobalStorageValue(rushConfig.scoreRed, 0)
        setGlobalStorageValue(rushConfig.stateSignup, 1)
        setGlobalStorageValue(rushConfig.stateAttend, 0)
        setGlobalStorageValue(rushConfig.stateBegun, 0)
        local message = string.format("Attention! %s will start in %s minutes. %s", rushConfig.eventName, rushConfig.preamble, rushConfig.joinHow)
        doBroadcastMessage(message, MESSAGE_STATUS_WARNING)

        local function broadcaster( minutes )
            if(minutes == 1) then
                doBroadcastMessage(rushConfig.eventName .. ", starts in a minute. Last chance to join: !battle", MESSAGE_STATUS_WARNING)
                return true;
            end
            doBroadcastMessage(rushConfig.eventName .. ", starts in " .. minutes .. rushConfig.joinHow, MESSAGE_STATUS_WARNING)
        end

        if(rushConfig.preamble > 5) then addEvent(broadcaster, (rushConfig.preamble - 4) * 1000 * 60, 4) end
        if(rushConfig.preamble > 4) then addEvent(broadcaster, (rushConfig.preamble - 3) * 1000 * 60, 3) end
        if(rushConfig.preamble > 3) then addEvent(broadcaster, (rushConfig.preamble - 2) * 1000 * 60, 2) end
        if(rushConfig.preamble > 2) then addEvent(broadcaster, (rushConfig.preamble - 1) * 1000 * 60, 1) end
        addEvent(start, rushConfig.preamble * 1000 * 60)
        return true
    end

    function results()
        if(getGlobalStorageValue(rushConfig.stateSignup) == 1) then
            local red = getGlobalStorageValue(rushConfig.scoreRed)
            local blue = getGlobalStorageValue(rushConfig.scoreBlue)          
            doBroadcastMessage(rushConfig.eventName .. " results:\nRed Team scored: ".. red .." frags.\nBlue Team scored: ".. blue .." frags.\nMatch is under way to ".. rushConfig.scoreWin .." frags.", MESSAGE_STATUS_WARNING)
            addEvent(results, rushConfig.results * 1000 * 60)
        end
    end

    function start()
        if(getGlobalStorageValue(rushConfig.stateSignup) == 1 and getGlobalStorageValue(rushConfig.stateAttend) >= rushConfig.minAttend) then
            doBroadcastMessage(rushConfig.announce, MESSAGE_STATUS_WARNING)
            setGlobalStorageValue(rushConfig.stateBegun, 1)
            addEvent(results, rushConfig.results * 1000 * 60)
            for _, pid in ipairs(getPlayersOnline()) do
                local myOutfit = getCreatureOutfit(pid)
                local red = {lookType = myOutfit.lookType, lookHead = 94, lookBody = 94, lookLegs = 94, lookFeet = 94, lookTypeEx = 0, lookAddons = myOutfit.lookAddons}
                local blue = {lookType = myOutfit.lookType, lookHead = 86, lookBody = 86, lookLegs = 86, lookFeet = 86, lookTypeEx = 0, lookAddons = myOutfit.lookAddons}
                if getPlayerStorageValue(pid, rushConfig.registered) == 1 then
                    doCreatureAddHealth(pid, getCreatureMaxHealth(pid))
                    doCreatureAddMana(pid, getCreatureMaxMana(pid))
                    if((getPlayerStorageValue(pid, rushConfig.stateIndice) % 2) == 1) then
                        doCreatureChangeOutfit(pid, red)
                        setPlayerStorageValue(pid, rushConfig.inArena, 1)
                        doTeleportThing(pid, rushConfig.posTeamRed)
                        setPlayerStorageValue(pid, rushConfig.registered, 1)
                        setPlayerStorageValue(pid, rushConfig.onTeamBlue, 0)
                        setPlayerStorageValue(pid, rushConfig.onTeamRed, 1)
                        doSendMagicEffect(getCreaturePosition(pid), 10)
                        doPlayerSendTextMessage(pid, MESSAGE_EVENT_ADVANCE, "You are in RED TEAM!\nThis battle will continue up to ".. rushConfig.scoreWin .." frags!")
                    else
                        doCreatureChangeOutfit(pid, blue)
                        doTeleportThing(pid, rushConfig.posTeamBlue)
                        setPlayerStorageValue(pid, rushConfig.inArena, 1)
                        setPlayerStorageValue(pid, rushConfig.registered, 1)
                        setPlayerStorageValue(pid, rushConfig.onTeamBlue, 1)
                        setPlayerStorageValue(pid, rushConfig.onTeamRed, 0)
                        doSendMagicEffect(getCreaturePosition(pid), 10)
                        doPlayerSendTextMessage(pid, MESSAGE_EVENT_ADVANCE, "You are in BLUE TEAM!\nThis battle will continue up to ".. rushConfig.scoreWin .." frags!")
                    end
                end
            end
        elseif(getGlobalStorageValue(rushConfig.stateAttend) < rushConfig.minAttend) then
            doBroadcastMessage(rushConfig.whyBother, MESSAGE_STATUS_WARNING)
            setGlobalStorageValue(rushConfig.stateSignup, -1)
            for _, pid in ipairs(getPlayersOnline()) do
                if getPlayerStorageValue(pid, rushConfig.registered) == 1 then
                    setPlayerStorageValue(pid, rushConfig.registered, -1)
                    doTeleportThing(pid, getTownTemplePosition(getPlayerTown(pid)))
                    doSendMagicEffect(getCreaturePosition(pid), CONST_ME_TELEPORT)
                end
            end
        end
    end
]]></talkaction>
Changed, same thing. Console says "player initiate event" but nothing happens
 
You can also use this file that I modify for you, and then you can use the following function to execute the event: StartRushEvent()

example:
Lua:
function onTime()
    StartRushEvent()
    return true
end
 

Attachments

Solution
Back
Top