• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

c++ timed event script need help

Status
Not open for further replies.

darksoke

OnTop500
well tried to make thins in the past but ended up crashing the server BAD can annyone provide me a clean script with a timed event a custom script something like

spawn a creature once 30 minutes ?
 
Last edited:

Kaev

Super Moderator
World.cpp
Code:
 m_timers[WUPDATE_CORPSES].SetInterval(20 * MINUTE * IN_MILLISECONDS);
//erase corpses every 20 minutes
m_timers[WUPDATE_CLEANDB].SetInterval(m_int_configs[CONFIG_LOGDB_CLEARINTERVAL]*MINUTE*IN_MILLISECONDS);
// clean logs table every 14 days by default
m_timers[WUPDATE_AUTOBROADCAST].SetInterval(getIntConfig(CONFIG_AUTOBROADCAST_INTERVAL));
+	m_timers[WUPDATE_YOUREVENT].SetInterval(2 * HOUR * IN_MILLISECONDS); // your time will be 30 * MINUTES * IN_MILLISECONDS
m_timers[WUPDATE_DELETECHARS].SetInterval(DAY*IN_MILLISECONDS); // check for chars to delete every day

Also World.cpp
Code:
LoginDatabase.Execute(stmt);
}

+	if (m_timers[WUPDATE_YOUREVENT].Passed())
+	{
+           // Your stuff, you want to spawn a NPC here
+	}

/// <li> Clean logs table

World.h
Code:
WUPDATE_MAILBOXQUEUE,
WUPDATE_DELETECHARS,
WUPDATE_PINGDB,
+	WUPDATE_YOUREVENT,
WUPDATE_COUNT

I can't give your the correct linenumbers atm, but i think you can find them with this informations. (+ they don't have to be the exact lines as i used xD)
 

darksoke

OnTop500
World.cpp
Code:
 m_timers[WUPDATE_CORPSES].SetInterval(20 * MINUTE * IN_MILLISECONDS);
//erase corpses every 20 minutes
m_timers[WUPDATE_CLEANDB].SetInterval(m_int_configs[CONFIG_LOGDB_CLEARINTERVAL]*MINUTE*IN_MILLISECONDS);
// clean logs table every 14 days by default
m_timers[WUPDATE_AUTOBROADCAST].SetInterval(getIntConfig(CONFIG_AUTOBROADCAST_INTERVAL));
+	m_timers[WUPDATE_YOUREVENT].SetInterval(2 * HOUR * IN_MILLISECONDS); // your time will be 30 * MINUTES * IN_MILLISECONDS
m_timers[WUPDATE_DELETECHARS].SetInterval(DAY*IN_MILLISECONDS); // check for chars to delete every day

Also World.cpp
Code:
LoginDatabase.Execute(stmt);
}

+	if (m_timers[WUPDATE_YOUREVENT].Passed())
+	{
+           // Your stuff, you want to spawn a NPC here
+	}

/// <li> Clean logs table

World.h
Code:
WUPDATE_MAILBOXQUEUE,
WUPDATE_DELETECHARS,
WUPDATE_PINGDB,
+	WUPDATE_YOUREVENT,
WUPDATE_COUNT

I can't give your the correct linenumbers atm, but i think you can find them with this informations. (+ they don't have to be the exact lines as i used xD)

i'm sorry i forgot to mention i want a custom script not core mod
 

Rochet2

Moderator / Eluna Dev
Here is a small template if someone wants to continue.
Im unable to right now, but decided to post this small code.
Made it able to handle multiple timed events as well.

Code:
class TestScript : public WorldScript
{
public:
    TestScript(): WorldScript("TestScript")
    {
        events.ScheduleEvent(1, 30 * MINUTE * IN_MILLISECONDS);
    }

    void OnUpdate(uint32 diff) override
    {
        while (uint32 id = events.ExecuteEvent())
        {
            switch (id)
            {
            case 1:
                // spawn code here
                break;
            }
        }
    }

    EventMap events;
};
 

darksoke

OnTop500
Here is a small template if someone wants to continue.
Im unable to right now, but decided to post this small code.
Made it able to handle multiple timed events as well.

Code:
class TestScript : public WorldScript
{
public:
    TestScript(): WorldScript("TestScript")
    {
        events.ScheduleEvent(1, 30 * MINUTE * IN_MILLISECONDS);
    }

    void OnUpdate(uint32 diff) override
    {
        while (uint32 id = events.ExecuteEvent())
        {
            switch (id)
            {
            case 1:
                // spawn code here
                break;
            }
        }
    }

    EventMap events;
};

oh thank you that's what i wanted :D
 
Status
Not open for further replies.
Top