Skip to content

Commit

Permalink
Scripting: Update Lake Frog Script to use Events.
Browse files Browse the repository at this point in the history
  • Loading branch information
malcrom committed Jun 13, 2013
1 parent 1c9a3d5 commit 8031aa4
Showing 1 changed file with 39 additions and 42 deletions.
81 changes: 39 additions & 42 deletions src/server/scripts/Northrend/zone_grizzly_hills.cpp
Expand Up @@ -717,6 +717,15 @@ enum LakeFrog
SAY_MAIDEN_1 = 1
};

enum LakeFrogEvents
{
EVENT_SCRIPT_1 = 1,
EVENT_SCRIPT_2 = 2,
EVENT_SCRIPT_3 = 3,
EVENT_SCRIPT_4 = 4,
EVENT_SCRIPT_5 = 5
};

class npc_lake_frog : public CreatureScript
{
public:
Expand All @@ -730,7 +739,6 @@ class npc_lake_frog : public CreatureScript
{
_following = false;
_runningScript = false;
_phase = 0;
if (me->GetEntry() == NPC_LAKE_FROG_QUEST)
me->RemoveFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GOSSIP);
}
Expand All @@ -739,48 +747,38 @@ class npc_lake_frog : public CreatureScript
{
if (_following)
if (!me->HasAura(SPELL_FROG_LOVE))
me->DespawnOrUnsummon(0);
me->DespawnOrUnsummon(1000);

_events.Update(diff);

if (_runningScript)
while (uint32 eventId = _events.ExecuteEvent())
{
if (_scriptTimer <= diff)
switch (eventId)
{
switch (_phase)
{
case 0:
DoCast(me, SPELL_MAIDEN_OF_ASHWOOD_LAKE_TRANSFORM);
me->SetEntry(33220);
_scriptTimer = 2000;
++_phase;
break;
case 1:
Talk(SAY_MAIDEN_0);
_scriptTimer = 3000;
++_phase;
break;
case 2:
me->SetFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GOSSIP);
_scriptTimer = 25000;
++_phase;
break;
case 3:
me->RemoveFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GOSSIP);
_scriptTimer = 2000;
++_phase;
break;
case 4:
Talk(SAY_MAIDEN_1);
_scriptTimer = 4000;
++_phase;
break;
case 5:
_runningScript = false;
me->DespawnOrUnsummon(0);
break;
}
case EVENT_SCRIPT_1:
DoCast(me, SPELL_MAIDEN_OF_ASHWOOD_LAKE_TRANSFORM);
me->SetEntry(33220);
_events.ScheduleEvent(EVENT_SCRIPT_2, 2000);
break;
case EVENT_SCRIPT_2:
Talk(SAY_MAIDEN_0);
_events.ScheduleEvent(EVENT_SCRIPT_3, 3000);
break;
case EVENT_SCRIPT_3:
me->SetFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GOSSIP);
_events.ScheduleEvent(EVENT_SCRIPT_4, 25000);
break;
case EVENT_SCRIPT_4:
me->RemoveFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GOSSIP);
_events.ScheduleEvent(EVENT_SCRIPT_5, 2000);
break;
case EVENT_SCRIPT_5:
Talk(SAY_MAIDEN_1);
me->DespawnOrUnsummon(4000);
break;
default:
break;
}
else if (_scriptTimer)
_scriptTimer -= diff;
}
}

Expand Down Expand Up @@ -808,7 +806,7 @@ class npc_lake_frog : public CreatureScript
me->GetMotionMaster()->MoveIdle();
me->SetFacingToObject(player);
_runningScript = true;
_scriptTimer = 2000;
_events.ScheduleEvent(EVENT_SCRIPT_1, 2000);
}
}
}
Expand All @@ -820,10 +818,9 @@ class npc_lake_frog : public CreatureScript
}

private:
EventMap _events;
bool _following;
bool _runningScript;
uint32 _scriptTimer;
uint8 _phase;
};

CreatureAI* GetAI(Creature* creature) const
Expand Down

3 comments on commit 8031aa4

@Subv
Copy link
Contributor

@Subv Subv commented on 8031aa4 Jun 13, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks much better.

@vendethiel
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great!

@baric
Copy link

@baric baric commented on 8031aa4 Jun 14, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work! I suggest that the new version be posted as a simple tutorial on whatever TC wiki page exists for writing scripts, with the related sql statement to assign the script in the db :)

Please sign in to comment.