Advertisement
Guest User

EmuDevs - GameObject State Change Trigger

a guest
May 19th, 2013
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.36 KB | None | 0 0
  1. /*
  2.  *╔═╦═╦═╦╦╦══╦═╦╗─╔╦══╗
  3.  *║╦╣║║║║║╠╗╗║╦╣╚╦╝║══╣
  4.  *║╩╣║║║║║╠╩╝║╩╬╗║╔╬══║
  5.  *╚═╩╩═╩╩═╩══╩═╝╚═╝╚══╝
  6.  *            www.emudevs.com
  7. */
  8. class npc_gameobject_state : public CreatureScript
  9. {
  10. public:
  11.     npc_gameobject_state() : CreatureScript("npc_gameobject_state") { }
  12.  
  13.     struct npc_gameobject_stateAI : public ScriptedAI
  14.     {
  15.         npc_gameobject_stateAI(Creature* creature) : ScriptedAI(creature) { }
  16.  
  17.         int objectCount;
  18.         uint32 spawnObjectTimer;
  19.         uint32 activateObjectTimer;
  20.         uint32 activateCleanUpTimer;
  21.  
  22.         void Reset()
  23.         {
  24.             objectCount = 0;
  25.         }
  26.  
  27.         void UpdateAI(uint32 diff)
  28.         {
  29.             if (objectCount == 0)
  30.             {
  31.                 Player* player = me->SelectNearestPlayer(10.0f);
  32.                 if (!player)
  33.                     return;
  34.                 objectCount = 1;
  35.                 spawnObjectTimer = 1000;
  36.             }
  37.  
  38.             if (spawnObjectTimer <= diff)
  39.             {
  40.                 if (objectCount == 1)
  41.                 {
  42.                     gameObject = me->SummonGameObject(187669, me->GetPositionX(), me->GetPositionY() + 15, me->GetPositionZ() + 2, me->GetOrientation(), 0, 0, 0, 0, 0);
  43.                     gameObjectTwo = me->SummonGameObject(187669, me->GetPositionX(), me->GetPositionY() - 15, me->GetPositionZ() + 2, me->GetOrientation(), 0, 0, 0, 0, 0);
  44.                     SetGoState(gameObject, gameObjectTwo, GO_STATE_READY);
  45.                     CreatureYell("BEHOLD!", EMOTE_ONESHOT_EXCLAMATION);
  46.                     activateObjectTimer = 3000;
  47.                     spawnObjectTimer = 10000;
  48.                     objectCount = 2;
  49.                 }
  50.             }
  51.             else
  52.                 spawnObjectTimer -= diff;
  53.  
  54.             if (activateObjectTimer <= diff && objectCount == 2)
  55.             {
  56.                 SetGoState(gameObject, gameObjectTwo, GO_STATE_ACTIVE);
  57.                 objectCount = 3;
  58.                 activateCleanUpTimer = 5000;
  59.             }
  60.             else
  61.                 activateObjectTimer -= diff;
  62.  
  63.             if (activateCleanUpTimer <= diff && objectCount == 3)
  64.             {
  65.                 if (gameObject && gameObject->IsInWorld())
  66.                     gameObject->Delete();
  67.                 if (gameObjectTwo && gameObjectTwo->IsInWorld())
  68.                     gameObjectTwo->Delete();
  69.                 objectCount = 0;
  70.             }
  71.             else
  72.                 activateCleanUpTimer -= diff;
  73.         }
  74.  
  75.         void SetGoState(GameObject* gameObject, GameObject* gameObjectTwo, GOState goState)
  76.         {
  77.             if (!gameObject || !gameObjectTwo)
  78.                 return;
  79.  
  80.             gameObject->SetGoState(goState);
  81.             gameObjectTwo->SetGoState(goState);
  82.         }
  83.  
  84.         void CreatureYell(const char* text, uint32 anim_id)
  85.         {
  86.             me->MonsterYell(text, LANG_UNIVERSAL, 0);
  87.             me->HandleEmoteCommand(anim_id);
  88.         }
  89.     private:
  90.         GameObject* gameObject;
  91.         GameObject* gameObjectTwo;
  92.     };
  93.  
  94.     CreatureAI* GetAI(Creature* creature) const
  95.     {
  96.         return new npc_gameobject_stateAI(creature);
  97.     }
  98. };
  99.  
  100. void AddSC_go_state()
  101. {
  102.     new npc_gameobject_state;
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement