[C++] TimedEvents menu

User Tag List

Results 1 to 4 of 4
  1. #1
    Gastricpenguin's Avatar Legendary
    Reputation
    980
    Join Date
    Feb 2007
    Posts
    2,236
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [C++] TimedEvents

    Timed Events

    Ever wanted to make an efficient way of hooking events in a script? I'll show you how, but you need to have a BASIC knowledge of C++. I recommend you read up on the definitions of a: Class, pointer, void, typedef, callback. If you already know what they are, then making a timed event will be easy! Before we begin, TIMED EVENT ARE A HARD TOPIC. Most of you won't get it on your first try so just look at examples and PRACTICE.

    First we will start off by defining the class we want to hook to. For this demonstration, we are going to make players resurrect 5 seconds after they die. The class and void for the script looks like this:
    Remember the color codes!

    Code:
    class OurClass
    {
    public:
            void Revive(Player * pPlayer)
            {
            pPlayer->ResurrectPlayer();
            pPlayer->SetUInt32Value(UNIT_FIELD_HEALTH, pPlayer->GetUInt32Value(UNIT_FIELD_MAXHEALTH));
            pPlayer->SetUInt32Value(UNIT_FIELD_POWER1, pPlayer->GetUInt32Value(UNIT_FIELD_MAXPOWER1));
            pPlayer->CastSpell(pPlayer, 46165, 0);
            }
    };
    Now in order to link to our script, we will have to make a hook when the player dies. The hook when a player is sent to the graveyard (after releasing spirit) is called OnRepop. The hook looks like this:

    Code:
    void Repop(Player *pPlayer)
    {
        //Our code
    }
    In order to hook the two, we need to define the class we want to be executed. We can do this simply by typing the class name, followed with a variable. Then, I will give you the structure of the timed event. Just know that there will be numerous arguments in the parenthesis. Our product looks like this:
    Code:
    void Repop(Player *pPlayer)
    {
        OurClass oc;
        TimedEvent * pointer = TimedEvent::Allocate(&class, new CallbackPX<Class, ClassPointer>(&class, &Class::Void, Pointer), 0, delay, repeats);
    }
    The color coding is pretty self-explanatory, but I want to go over the CallBackPX. The X is the amount of pointers you have in your void. In our demonstration, we only have 1 pointer. So it will become CallBackP1. delay is the wait time IN MILLISECONDS before executing the function. Since we will wait 5 seconds, delay becomes 5000. And for repeats, since we only want this happening once, it becomes 1. Now all you have to do is fill in the blanks. Our product now looks like this:

    Code:
    void Repop(Player *pPlayer)
    {
        OurClass oc;
        TimedEvent * ReviveMe = TimedEvent::Allocate(&oc, new CallbackP1<OurClass, Player>(&oc, &OurClass::Revive, pPlayer), 0, 5000, 1);
    }
    Last but not least, we want to add the event to the player. This can be done with a simple function called event_addEvent. Our final product, all together, will look like this:

    Code:
     class OurClass
    {
    public:
            void Revive(Player * pPlayer)
            {
            pPlayer->ResurrectPlayer();
            pPlayer->SetUInt32Value(UNIT_FIELD_HEALTH, pPlayer->GetUInt32Value(UNIT_FIELD_MAXHEALTH));
            pPlayer->SetUInt32Value(UNIT_FIELD_POWER1, pPlayer->GetUInt32Value(UNIT_FIELD_MAXPOWER1));
            pPlayer->CastSpell(pPlayer, 46165, 0);
            }
    };
    
     void Repop(Player *pPlayer)
    {
        OurClass oc;
        TimedEvent * ReviveMe = TimedEvent::Allocate(&oc, new CallbackP1<OurClass, Player>(&oc, &OurClass::Revive, pPlayer), 0, 5000, 1);
        pPlayer->event_AddEvent(ReviveMe);
    }
    


    Last edited by Gastricpenguin; 02-11-2009 at 01:35 PM.
    Life Puzzler WoW - Website | Forums

    [C++] TimedEvents
  2. #2
    Hellgawd's Avatar Member
    Reputation
    710
    Join Date
    Jun 2007
    Posts
    2,480
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Very nice guide, actually.
    I would rep you, but i've already repped you like 2 hours ago D:

  3. #3
    Pwntzyou's Avatar Contributor
    Reputation
    264
    Join Date
    Dec 2007
    Posts
    393
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nice guide gastric

    <3 MysterioussouL for the sig

  4. #4
    Fireblast's Avatar Contributor
    Reputation
    195
    Join Date
    Aug 2008
    Posts
    883
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    niceee man , ;D

All times are GMT -5. The time now is 08:36 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search