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

GameObject Change State Trigger

Tommy

Founder
Hello guys, I'm here with another script.. pointless maybe? I THINK NOT! I was going to add more gameobjects to this, but I couldn't find any good ones that changed their state. :/


.: Features :.


  • [*=1]A trigger that spawns two gameobjects y+15 and y-15. Before the trigger spawns the gameobjects, it yells "BEHOLD!". Afterwards, the gameobject state will change.

.: Notes :.


  • The player(s) must be within 10.0f feet from the trigger before activation.

.: Screenshots :.

lgt7b6d.png

lgt85f9.png


.: Source :.


EmuDevs:
Code:
/*
 *╔═╦═╦═╦╦╦══╦═╦╗─╔╦══╗ 
 *║╦╣║║║║║╠╗╗║╦╣╚╦╝║══╣
 *║╩╣║║║║║╠╩╝║╩╬╗║╔╬══║
 *╚═╩╩═╩╩═╩══╩═╝╚═╝╚══╝
 *            www.emudevs.com
*/
class npc_gameobject_state : public CreatureScript
{
public:
    npc_gameobject_state() : CreatureScript("npc_gameobject_state") { }

    struct npc_gameobject_stateAI : public ScriptedAI
    {
        npc_gameobject_stateAI(Creature* creature) : ScriptedAI(creature) { }

        int objectCount;
        uint32 spawnObjectTimer;
        uint32 activateObjectTimer;
        uint32 activateCleanUpTimer;

        void Reset()
        {
            objectCount = 0;
        }

        void UpdateAI(uint32 diff)
        {
            if (objectCount == 0)
            {
                Player* player = me->SelectNearestPlayer(10.0f);
                if (!player)
                    return;
                objectCount = 1;
                spawnObjectTimer = 1000;
            }

            if (spawnObjectTimer <= diff)
            {
                if (objectCount == 1)
                {
                    gameObject = me->SummonGameObject(187669, me->GetPositionX(), me->GetPositionY() + 15, me->GetPositionZ() + 2, me->GetOrientation(), 0, 0, 0, 0, 0);
                    gameObjectTwo = me->SummonGameObject(187669, me->GetPositionX(), me->GetPositionY() - 15, me->GetPositionZ() + 2, me->GetOrientation(), 0, 0, 0, 0, 0);
                    SetGoState(gameObject, gameObjectTwo, GO_STATE_READY);
                    CreatureYell("BEHOLD!", EMOTE_ONESHOT_EXCLAMATION);
                    activateObjectTimer = 3000;
                    spawnObjectTimer = 10000;
                    objectCount = 2;
                }
            }
            else
                spawnObjectTimer -= diff;

            if (activateObjectTimer <= diff && objectCount == 2)
            {
                SetGoState(gameObject, gameObjectTwo, GO_STATE_ACTIVE);
                objectCount = 3;
                activateCleanUpTimer = 5000;
            }
            else
                activateObjectTimer -= diff;

            if (activateCleanUpTimer <= diff && objectCount == 3)
            {
                if (gameObject && gameObject->IsInWorld())
                    gameObject->Delete();
                if (gameObjectTwo && gameObjectTwo->IsInWorld())
                    gameObjectTwo->Delete();
                objectCount = 0;
            }
            else
                activateCleanUpTimer -= diff;
        }

        void SetGoState(GameObject* gameObject, GameObject* gameObjectTwo, GOState goState)
        {
            if (!gameObject || !gameObjectTwo)
                return;

            gameObject->SetGoState(goState);
            gameObjectTwo->SetGoState(goState);
        }

        void CreatureYell(const char* text, uint32 anim_id)
        {
            me->MonsterYell(text, LANG_UNIVERSAL, 0);
            me->HandleEmoteCommand(anim_id);
        }
    private:
        GameObject* gameObject;
        GameObject* gameObjectTwo;
    };

    CreatureAI* GetAI(Creature* creature) const
    {
        return new npc_gameobject_stateAI(creature);
    }
};

void AddSC_go_state()
{
    new npc_gameobject_state;
}


ENJOY!
 
Top