Aller au contenu

Photo

[solved] overriding the ambient animation pattern and frequency of a npc through scripting (can't use variables)


  • Veuillez vous connecter pour répondre
7 réponses à ce sujet

#1
LukaCrosszeria

LukaCrosszeria
  • Members
  • 1 304 messages
Hello everyone,

I want to modify the ambient animation of an npc but I can't use his variables in the creature file because I'm spawning him through scripting + he's to be a follower so I don't want him to act like he's browsing books throughout the game :blink:

on the toolset wiki I found this:

The script sys_ambient_h contains the implementation of the ambient behaviour system. The AMBIENT_* local variables should never be directly modified at run-time. Instead, use the following functions to customize a creature's ambient behaviour through script.
 
// Normally this function is called automatically to begin or resume ambient behaviour when a
// creature perceives the player. However, it can be called explicitly to force a creature to begin
// performing ambient behaviour or, if nAmbientEnable is 1, to enable ambient behaviour on a creature.
void Ambient_Start(object oCreature = OBJECT_SELF, int nAmbientEnable = 0, int nMovePattern = 0, string sMovePrefix = "");
 
// Normally this function is called automatically to pause ambient behaviour after the party has
// been out of the creature's sight for a while. However, this function can be used to force a
// creature to temporarily cease ambient behaviour. Note that the creature will automatically
// resume ambient behaviour when it perceives the player again.
void Ambient_Pause(object oCreature = OBJECT_SELF, int bCheckVisibility = TRUE);
 
// Turns off ambient behaviour on a creature. The creature will resume ambient behaviour only
// after Ambient_Start() is called.
void Ambient_Stop(object oCreature = OBJECT_SELF);
 
// Overrides the ambient animation pattern and animation frequency defined by the creature's template.
void Ambient_OverrideBehaviour(object oCreature, int nAnimPattern, float fAnimFreq);
 
// Restores a creature's ambient animation behaviour to that defined in the creature's template.
void Ambient_RestoreBehaviour(object oCreature);


A couple of questions:

1) I used this: Ambient_OverrideBehaviour(oMaethan, 69, 0.0f, 0);;

Nothing happens, but I'm not sure how to define fAnimFreq

2) What's the values of fAnimFreq

The wiki doesn't say which values are possible for float fAnimFreq, I thought it might have to with ths

Animation frequency. The part left of the decimal specifies the minimum and the part right of the decimal specifies the maximum number of random animations to play during an animation phase. So, for example, a value of 1.3 will play between 1 and 3 random animations from the animation pattern listed in ambient_ai.xls. A value of -1.0 plays all animations in the animation pattern in the order they are listed in ambient_ai.xls. Animation pattens that are highlighted in green on the worksheeet should always be played in order (i.e. AMBIENT_ANIM_FREQ is -1.0).

I don't want to play any random animations, only the one I specified.

Thanks for any help

Modifié par LukaCrosszeria, 02 février 2011 - 10:33 .


#2
Proleric

Proleric
  • Members
  • 2 350 messages
The toolset help for the function suggests that the last two parameters should normally be -1.0 and -1 respectively.

If that doesn't work, try this:

SetLocalInt(oMaethan, "AMBIENT_SYSTEM_STATE", 1);
SetLocalInt(oMaethan, "AMBIENT_SYSTEM_PATTERN", 69);
Ambient_Start(oMaethan);


I haven't used sequence 69 (browse_books_1) myself. There are a few that don't seem to work outside of cutscenes. If you need one for test purposes that will reliably demonstrate whether the script is working, try 119.

Alternatively, could you place your creature in the toolset, with the above variables, flag it as Active=FALSE, then activate it at the appropriate time by script? That works a treat (and causes much less engine lag than spawning dynamically).

#3
LukaCrosszeria

LukaCrosszeria
  • Members
  • 1 304 messages
Hi there. Thanks for the help. I've tried the scripting solutions, but none seem to work. They seem good though, I don't get it.

I haven't tried your second solution yet, do you mean placing him in the area in the toolset? The problem is he has to appear in the Lothering chantry, and modifying the .are is what I'm trying to avoid.

Modifié par LukaCrosszeria, 01 février 2011 - 07:46 .


#4
Proleric

Proleric
  • Members
  • 2 350 messages
Ah, sorry, didn't appreciate you were modding the OC. Now I understand why you're spawning the creature.

On reflection, there can be timing issues with newly-spawned creatures. If you can't change the variables on the creature template, you might try

DelayEvent(1.0, oMaethan, Event(EVENT_TYPE_INVALID), "my_script");

where "my_script" is a script containing the animation commands.

I'd especially recommend the Ambient_Start function, as I've used that in several situations to kick-start a reluctant bunny.

#5
LukaCrosszeria

LukaCrosszeria
  • Members
  • 1 304 messages
Hi there, I tried that with ambient animation 119 but nothing happens :(. This is my script:

#include "utility_h"
#include "wrappers_h"
#include "plt_gen00pt_party_sng"
#include "plt_genpt_maethan_main2"
#include "sng_2da_constants_h"
#include "sys_ambient_h"

void main()
{
    object oPC = GetHero();
    object oArea = GetObjectByTag("lot110ar_chantry");
// Maethan
    vector vLocation1 = Vector(-37.4274f, 15.7448f, 0.0f);
    location lLocation1 = Location(oArea, vLocation1, 15.4f);
    int bDoOnce = GetLocalInt(OBJECT_SELF, AREA_DO_ONCE_A);
    if(!bDoOnce)   // this part of the script can only run if the party hasn't entered the Lothering chantry yet
    {
        SetLocalInt(OBJECT_SELF, AREA_DO_ONCE_A, TRUE);
        WR_SetPlotFlag(PLT_GENPT_MAETHAN_MAIN2, MAETHAN_QUEST_ACTIVE, TRUE);
// sets Maethan's quest to active
        WR_SetPlotFlag(PLT_GENPT_MAETHAN_MAIN2, MAETHAN_ADDED_TO_TOWN, FALSE);

        if (WR_GetPlotFlag(PLT_GENPT_MAETHAN_MAIN2, MAETHAN_ADDED_TO_TOWN) == FALSE)
// this part of the script will only run if Maethan hasn't been created yet
        {
            WR_SetPlotFlag(PLT_GENPT_MAETHAN_MAIN2, MAETHAN_ADDED_TO_TOWN, TRUE);
// sets the flag that Maethan has been created
            WR_SetPlotFlag(PLT_GEN00PT_PARTY_SNG, GEN_MAETHAN_RECRUITED, FALSE);
// sets Maethan's recruitment flag to negative, in order to make him recruitable

            object oMaethan = CreateObject(OBJECT_TYPE_CREATURE, R"gen00fl_maethan.utc", lLocation1);
//creates Maethan
            SetLocation(oMaethan, lLocation1);
// orients Maethan to the book case
            DelayEvent(1.0, oMaethan, Event(EVENT_TYPE_INVALID), "sng_maethan_animation");
      }
    }
}

And sng_maethan_animation contains:

#include "utility_h"
#include "wrappers_h"
#include "sys_ambient_h"


void main()
{
    object oMaethan = GetObjectByTag("gen00fl_maethan");
    SetLocalInt(oMaethan, "AMBIENT_SYSTEM_STATE", 1);
    SetLocalInt(oMaethan, "AMBIENT_SYSTEM_PATTERN", 119); //69
    Ambient_Start(oMaethan);
}
:crying:

Modifié par LukaCrosszeria, 01 février 2011 - 05:17 .


#6
Proleric

Proleric
  • Members
  • 2 350 messages
Apologies, that doesn't seem to work, but this does:

Ambient_Start(oMaethan, AMBIENT_SYSTEM_ENABLED, AMBIENT_MOVE_INVALID, AMBIENT_MOVE_PREFIX_NONE, 119);

Modifié par Proleric1, 01 février 2011 - 08:28 .


#7
Nattfodd

Nattfodd
  • Members
  • 321 messages
This last one should work because you have to start the ambient system for the NPC.

#8
LukaCrosszeria

LukaCrosszeria
  • Members
  • 1 304 messages
 :wizard: That did the trick, thank you guys!