Creating a Timer Inside a Gameobject Script

Everything has been easy for me so far , but i have not yet figured out how to create timers inside a script for example:

1- NPC gets summoned

2- Wait 3 seconds

3- Talk Text 1

4- Wait 1 second

5- Walk to location while still saying Text 1 because creature waited 1 sec only

6- Stop at certain point

7- Wait 2 seconds

8- Cast Spell At Gate

9- Look At Player

10- Talk Text 2

11- Wait 10 seconds

12- Walk Back to Home Location

i know how to do everything , i just don’t know how to make it timed like it is above !

Note:

Please Don’t Say , USE THIS , READ THIS , SEARCH FOR THIS

Just show me an example of this or help me understand how its going to work .

Maybe Create a Method like


void Unit::Delay(Creature* pCreature, int32 delaytime)

{

}
void UpdateAI(const uint32 diff)
{
    if (phase_timer <= diff)
    {
        switch (step)
        {
            case 0:
                NPC gets summoned
                phase_timer = 3000;
                step++;
                break;
            case 1:
                Talk Text 1
                phase_timer = 1000;
                step++;
                break;
        }
    }
}

[/CODE]

so what do i add at void Reset and the unit32 before the reset ?

steps get activated after each other

but , whats the phase_timer’s use ?

what is it good for


void Reset()

{

    phase_timer = 0; //Trigger first event (case 0)

    step = 0;        //Phase controller

}

void UpdateAI(const uint32 diff)

{

    if (phase_timer <= diff)

    {

        switch (step)

        {

            case 0:

                //When NPC gets summoned

                phase_timer = 3000;

                ++step;

                break;

            case 1:

                //Talk Text 1

                phase_timer = 1000;

                ++step;

                break;

        }

    }

    else phase_timer -= diff

}

Fix typo and add some info ;D

Edit: Phase timer is our timer (countdown)

uint32 phase_timer;
uint8 step;

void Reset()
{
    phase_timer = 0;
    step = 0;
}

It was just an example, look at codesamples in the core, you will find similar tasks where you can get ideas

[/CODE]

didn’t work /emoticons/default_sad.png

HERE IS FULL SCRIPT , which is not working


class npc_inner_demon : public CreatureScript

{ public:

	npc_inner_demon() : CreatureScript("npc_inner_demon") { }




#define SAY_JUST_STARTED "text 1";

#define SAY_JUST_STARTED_2 "text 2";



	struct  npc_inner_demonAI : public ScriptedAI

	{

		npc_inner_demonAI(Creature* pCreature) : ScriptedAI(pCreature) {Reset();}


		unit32 phase_timer;

		unit32 step;


		void Reset()

		{

			phase_timer = 1000; //Trigger first event (case 0)

			step = 0;        //Phase controller

		}


		void UpdateAI(const uint32 diff)

		{

			if (phase_timer <= diff)

			{

				switch (step)

				{

					case 0:

						//When NPC gets summoned

						phase_timer = 3000;

						// ACTIONS TO DO :

						pCreature->MonsterSay("Step 0 : Timer = 3 Sec",0,0);

						++step;

					break;

					case 1:

						//Talk Text 1

						phase_timer = 1000;

						// ACTIONS TO DO :

						pCreature->MonsterSay("Step 1 : Timer = 1 Sec",0,0);

						++step;

					break;

					case 2:

						//Talk Text 1

						phase_timer = 19000;

						// ACTIONS TO DO :

							pCreature->MonsterSay("Step 2 : Timer = 19 Sec",0,0);

						++step;

					break;

					case 3:

						//Talk Text 1

						phase_timer = 29000;

						// ACTIONS TO DO :

					pCreature->MonsterSay("Step 3 : Timer = 29 Sec",0,0);

						++step;

					break;

					case 4:

						//Talk Text 1

						phase_timer = 1000;

						// ACTIONS TO DO :

						pCreature->MonsterSay("Step 4 : Timer = 39 Sec",0,0);

						++step;

					break;

				}

			}

			else phase_timer -= diff

		}	// END OF UPDATE	



	};

	CreatureAI* GetAI(Creature* pCreature) const

    {

        return new npc_inner_demonAI (pCreature);

    }

};

errors im getting are :

syntax error : missing ‘;’ before identifier ‘phase_timer’

‘step’ : undeclared identifier

‘phase_timer’ : undeclared identifier

‘pCreature’ : undeclared identifier

i think there is a problem with the top portion of the script but i have no idea , i have used prewritten scripts as examples and still got nothing

============================================= EDIT =============================================

IM AN IDOIT : noticed that i wrote “unit32” instead of “uint32” wtf is a unit32 !!

now only error is pCreature

Replaced “pCreature” with “me” and add a small “;” sign after “else phase_timer -= diff” and script is compiled , im going to test lolz

learning C++ is very fun /emoticons/default_smile.png

add this at the start of the script

#include “ScriptPCH.h”

change all pCreature to “me”

(me->MonsterSay)

Add the script to scriptloader

void AddSC_npc_inner_demon()

{

new npc_inner_demon();

}

see in wiki how to add it

PD:post line error for better lookup ;D

Script works fine , many thanks for Kaelima and Ciclop , this will help a lot of noobs ----> like me !

it should be uint32, not unit32… Change pCreature to me.

After that you can hopes it will help to somebody.

PS learn Java or Ruby. It’s much funnier and easier.