BioWare Forums: View Post For Code Display


You are viewing a single post. Please do not take this post out of context.
Read the full topic: The Dancing NPC - I had hoped

Author The Dancing NPC - I had hoped
Maglazar Posted: Monday, 19 August 04:11PM
This code still runs on the OnHeartbeat event, but it checks to make sure that a player character is in the same area, and checks a local variable to see whether or not it's time to start "re-adding" the delay commands to the npc's action queue. Doing it this way should prevent too many delaycommands from stacking up on the npc, and should save cpu cycles by not running the "dance routine" portion if the nearest player character isn't in the same area. Hopefully this will help you along. Good luck.

NWScript:
// Determine if I'm "is dancing", and if not, to start (check local variable)
    if(GetLocalInt(OBJECT_SELF, "iIsDancing") != 1)
    {
        // Find the Player Character closest to me
        object oClosestPC = GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC);
        // Find the tag of the area I'm currently in
        string sMyCurrArea = GetTag(GetArea(OBJECT_SELF));
        // Find the tag of the area oClosestPC is in
        string sClosePCArea = GetTag(GetArea(oClosestPC));
        // Make sure that the closest player is in the same area as me
        if(sClosePCArea == sMyCurrArea)
        {
            // Remember that I'm dancing
            SetLocalInt(OBJECT_SELF, "iIsDancing", 1);
            ActionPlayAnimation(ANIMATION_FIREFORGET_VICTORY2);
            DelayCommand(3.0, ActionPlayAnimation( ANIMATION_LOOPING_TALK_LAUGHING, 3.0, 2.0));
            DelayCommand(3.0, PlayVoiceChat(VOICE_CHAT_LAUGH));
            DelayCommand(5.0, ActionPlayAnimation( ANIMATION_FIREFORGET_VICTORY1));
            DelayCommand(8.5, ActionPlayAnimation( ANIMATION_FIREFORGET_VICTORY3));
            DelayCommand(11.0, ActionPlayAnimation( ANIMATION_LOOPING_GET_MID, 3.0, 2.0));
            DelayCommand(14.5, PlayVoiceChat(VOICE_CHAT_LAUGH));
            DelayCommand(13.0, ActionPlayAnimation( ANIMATION_FIREFORGET_VICTORY3));
            // Wait until I'm almost finished with my dance, then reset my
            // iIsDancing local int so the process will restart. This
            // should prevent an npc's action queues from recieving too
            // many commands, by waiting until most of them have finished
            // before restarting the sequence. It doesn't wait for all
            // the animations to complete, otherwise 'pauses' between
            // the animation sequences will happen while waiting for
            // the next heartbeat to run.
            DelayCommand(12.0, SetLocalInt(OBJECT_SELF, "iIsDancing", 0));
        }
    }


_________________
Maglazar
Scripter-in-training

This post taken from the BioWare Forums
Powered by BioBoards Version 2.06.001
Please read our Copyright and Trademark Information