Author Topic: How to get npc's dancing  (Read 224 times)

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
How to get npc's dancing
« on: March 18, 2011, 10:25:41 am »


               I found a dancing script on the vault, which pretty much told the NPC it was attached to, to run a bunch of random animations.


The animation looks good, infact, it goes well with my music, however...

I experience some lag etc, when trying to run the script of Heartbeat etc.

I thought I could do it on a heartbeat, to get the dancers to never stop dancing.

However,
I think it lags because it fires again, within 6 seconds, adding more and more actions to the action queue of the npc's

(Adding Actions to the queue, is non blocking, which potentially means that the npc could end up with dozens of pending actions, receiving more and more.)

In any case,
I was wondering if anyone had any idea's for good methods of getting permanent dancers?


I've tried heartbeat, - on NPC's
Pseudo-Heartbeats - Fire the animations, then fire the function again.
and using Area Heartbeats, same as above, but triggered by area hb once, and then go into the pseudo hb.


I need the non-laggiest method possible, as I intend to have about 7 dancers in this area, all dancing together.

Its a Brothel etc, and the music suits it very much.
               
               

               
            

Legacy_Xenovant

  • Full Member
  • ***
  • Posts: 182
  • Karma: +0/-0
How to get npc's dancing
« Reply #1 on: March 18, 2011, 12:05:36 pm »


               You can use it as "onspawn" and "ondisturbed". It will fire once when it has spawned and again if someone attacks, talks or whatever to him
               
               

               
            

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
How to get npc's dancing
« Reply #2 on: March 18, 2011, 01:03:35 pm »


               but surely that would face the same problem, that the Animation commands are not blocking, and would result in stacking actions in the queue when I try to loop it?
               
               

               
            

Legacy_Xenovant

  • Full Member
  • ***
  • Posts: 182
  • Karma: +0/-0
How to get npc's dancing
« Reply #3 on: March 18, 2011, 02:12:38 pm »


               Let's say that, for example, the dance loop takes 20 seconds to execute all the animations. You could add this in the script:

At the beginning:

ClearAllActions();

At the end of the script:

DelayCommand (20.0, ExecuteScript("name_of_this_script",OBJECT_SELF));


EDIT: If you want, you could create 2 scripts: 1 for onspawn and other for ondisturbed. The one of onspawn like I said, and the other one, just your script with the "clearallactions"(the onspawn script will loop later)
               
               

               


                     Modifié par Xenovant, 18 mars 2011 - 03:16 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
How to get npc's dancing
« Reply #4 on: March 18, 2011, 03:58:27 pm »


               Set the commandable flag to false.  To stop anything else from being added to the NPC's action que.  Have the NPC as its last action set the flag back to true and run the script to add more actions to his ACTION QUE.

Example  with a script called  "dance"



void main()
{
    // code to load the action with some dance moves

    // last two things in action que will be making the NPc comandable...
    ActionDoCommand(SetCommandable(TRUE));
    //..and running the script to add more moves.
    ActionDoCommand(ExecuteScript("dance",OBJECT_SELF));

    // Stop anything else from being added to the que as a precaution.
    SetCommandable(FALSE);
}

               
               

               


                     Modifié par Lightfoot8, 18 mars 2011 - 03:58 .
                     
                  


            

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
How to get npc's dancing
« Reply #5 on: March 18, 2011, 04:22:54 pm »


               I dont think this will work.

ExecuteScript, yes, is blocking, in that it will run through all of the items in that script until it exits, and returns to the calling script, but the ActionDoAnimation or PlayAnimation etc,
dont block execution for 1 second etc.
Infact, if I had 20 PlayAnimation commands in the dance script, all 20 would be added to the action queue in an instant, and then the calling script would take over and finish before those actions have been finished.
The Commandable flag would be overwrote by the next iteration of this script, regardless of whether the actions in the queue have been executed or not- Meaning that more and more would be added.

Does anyone else see this?
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
How to get npc's dancing
« Reply #6 on: March 18, 2011, 05:04:25 pm »


               1 The npc loads dance moves into his action Que.

2 The NPC loads a SetCommandable(TRUE); to his Action Que that will happen after the dance Moves.

3. The NPC loads a ExecuteScript("dance",OBJECT_SELF); To his action Que. The script will run as the last Action in his que. Not untill all the Actions from step 1 and 2 are finished.

4 the NPC stops anything else from being added to his Action Que. SetCommandable(FALSE); this is the only command that gets excuted before the sctipt finishes. all of the others are just loaded to the Action Que of the NPC to be ran in turn. This is what the ActionDoCommand does. It turns the command into an action.

Now since I have not tested it. If the blocking becomes a problem. And yes it might. the solution would be to assign the command to run.

ActionDoCommand(AssignCommand(OBJECT_SELF,ExecuteScript("dance",OBJECT_SELF)));

But I do not think it will be a problem. Before useing the line above line. I would trun the whole thing into an action returning function and add that to the Que to reload itsself.
               
               

               


                     Modifié par Lightfoot8, 18 mars 2011 - 05:04 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
How to get npc's dancing
« Reply #7 on: March 18, 2011, 05:34:07 pm »


               Ok, Now tested.   It works with no problens.   Here is the code i used for testing places in the OnSpawn of the creature.

void main()
{
    SpeakString("Script running");
    ActionPlayAnimation(ANIMATION_FIREFORGET_BOW);
    ActionPlayAnimation(ANIMATION_FIREFORGET_DODGE_DUCK);
    ActionPlayAnimation(ANIMATION_FIREFORGET_DRINK);
    ActionPlayAnimation(ANIMATION_FIREFORGET_GREETING);
    ActionPlayAnimation(ANIMATION_FIREFORGET_PAUSE_SCRATCH_HEAD);
 
    // last two things in action que will be making the NPc comandable...
    ActionDoCommand(SetCommandable(TRUE));
    //..and running the script to add more moves.
    ActionDoCommand(ExecuteScript("dance",OBJECT_SELF));
 
    // Stop anthing else from being added to the que as a precaution.
    SetCommandable(FALSE);
}


No dance moves by any means.   The NPC ran through  que then ran the script.   There was no blocking problem.