Author Topic: Creating a new object  (Read 650 times)

Legacy_WhiteTiger

  • Hero Member
  • *****
  • Posts: 889
  • Karma: +0/-0
Creating a new object
« on: December 14, 2014, 09:05:22 pm »


               

When NPCs are created by encounters they are free to walk away. When NPCs are created by scripting, they are not able to walk away. NPCs created by function "CreateObject()" does not walk. 


 


How to make NPCs created by "CreateObject()" walk like NPCs created by encounters?



               
               

               
            

Legacy_Proleric

  • Hero Member
  • *****
  • Posts: 1750
  • Karma: +0/-0
Creating a new object
« Reply #1 on: December 14, 2014, 11:09:47 pm »


               Are you using the same NPC template for both the encounter and the script?


By walking, do you mean walk waypoints, ambient animation or simply combat movement?


If walk waypoints, check that the creature tag (as specified in CreateObject, if any, or else the template) matches the waypoints. It definitely works.
               
               

               
            

Legacy_WhiteTiger

  • Hero Member
  • *****
  • Posts: 889
  • Karma: +0/-0
Creating a new object
« Reply #2 on: December 14, 2014, 11:36:08 pm »


               

Are you using the same NPC template for both the encounter and the script?


By walking, do you mean walk waypoints, ambient animation or simply combat movement?


If walk waypoints, check that the creature tag (as specified in CreateObject, if any, or else the template) matches the waypoints. It definitely works.



 


Yes, I am sure that I am using both template for the encounter and the script. 


[...] By walking, do you mean walk waypoints? No. I mean the normal random walk onheartbeat (not in combat)


 


The npc just does not walk  '<img'>


 


 


 


-edited


 


This is like when you create a creature using DM client. the creature stays stopped



               
               

               
            

Legacy_Proleric

  • Hero Member
  • *****
  • Posts: 1750
  • Karma: +0/-0
Creating a new object
« Reply #3 on: December 15, 2014, 07:20:30 am »


               Ah, I understand.

For scripted and placed creatures, ambient animations will only play if the spawn condition NW_FLAG_AMBIENT_ANIMATIONS is set. However, the Lexicon tells us that "these animations will play automatically for encounter creatures".

You could set the local integer X2_L_SPAWN_USE_AMBIENT on the creature template to force these animations in all cases.

That switch tells the standard spawn script to do this:


SetSpawnInCondition(NW_FLAG_IMMOBILE_AMBIENT_ANIMATIONS);

               
               

               
            

Legacy_WhiteTiger

  • Hero Member
  • *****
  • Posts: 889
  • Karma: +0/-0
Creating a new object
« Reply #4 on: December 15, 2014, 03:21:27 pm »


               
 




Ah, I understand.


For scripted and placed creatures, ambient animations will only play if the spawn condition NW_FLAG_AMBIENT_ANIMATIONS is set. However, the Lexicon tells us that "these animations will play automatically for encounter creatures".


You could set the local integer X2_L_SPAWN_USE_AMBIENT on the creature template to force these animations in all cases.


That switch tells the standard spawn script to do this:

 


SetSpawnInCondition(NW_FLAG_IMMOBILE_AMBIENT_ANIMATIONS);

 




 


 


Had not worked =(


 


I tried this...


 


   object oMonster = CreateObject(OBJECT_TYPE_CREATURE, "creature038", lLoc, TRUE);

    DelayCommand(2.0, SetLocalInt(oMonster, "X2_L_SPAWN_USE_AMBIENT", TRUE));

 

 

And after that I tried this on nw_c2_default9 (onspawn)

 


    if(GetTag(OBJECT_SELF) == "creature_038_TAG")

    {

        SetLocalInt(OBJECT_SELF, "X2_L_SPAWN_USE_AMBIENT", TRUE);

 

        //After I tried to set NW_FLAG_IMMOBILE_AMBIENT_ANIMATIONS to false

        //SetSpawnInCondition(NW_FLAG_IMMOBILE_AMBIENT_ANIMATIONS, FALSE);

    }


 


help me  '<img'>


 



               
               

               
            

Legacy_Proleric

  • Hero Member
  • *****
  • Posts: 1750
  • Karma: +0/-0
Creating a new object
« Reply #5 on: December 15, 2014, 04:44:40 pm »


               I tested this... it works for me:

Creature template > Advanced Tab > Variables > X2_L_SPAWN_USE_AMBIENT > 1 > Add

This is assuming you're using the default Bioware AI scripts, of course.

If you need to set it by script, remove the delay. Setting local variables immediately after CreateObject works fine (contrary to a popular myth). In this case, it's essential, because you want to set the switch before the OnSpawn script, which runs almost immediately after the script in which you CreateObject.

With the switch set, OnSpawn will do this:
 
SetSpawnInCondition(NW_FLAG_AMBIENT_ANIMATIONS);
I quoted the wrong spawn in condition above, apologies.
               
               

               
            

Legacy_WhiteTiger

  • Hero Member
  • *****
  • Posts: 889
  • Karma: +0/-0
Creating a new object
« Reply #6 on: December 15, 2014, 11:31:07 pm »


               

I tested this... it works for me:


Creature template > Advanced Tab > Variables > X2_L_SPAWN_USE_AMBIENT > 1 > Add


This is assuming you're using the default Bioware AI scripts, of course.


If you need to set it by script, remove the delay. Setting local variables immediately after CreateObject works fine (contrary to a popular myth). In this case, it's essential, because you want to set the switch before the OnSpawn script, which runs almost immediately after the script in which you CreateObject.


With the switch set, OnSpawn will do this:

 



SetSpawnInCondition(NW_FLAG_AMBIENT_ANIMATIONS);

I quoted the wrong spawn in condition above, apologies.

 



 


Yes, I'm using default nw scripts.


 


I just tested now...   Not worked =/

 

I tried to use the procedure you said  Creature template > Advanced Tab > Variables > X2_L_SPAWN_USE_AMBIENT > 1 > Add and had no effect on my creature



               
               

               
            

Legacy_kalbaern

  • Hero Member
  • *****
  • Posts: 1531
  • Karma: +0/-0
Creating a new object
« Reply #7 on: December 16, 2014, 04:26:17 am »


               

Make a custom OnSpawn script to test in a few select NPCs using this:


 


 


 


#include "x0_i0_anims"

void main()

{

SetSpawnInCondition(NW_FLAG_SHOUT_ATTACK_MY_TARGET);

SetSpawnInCondition(NW_FLAG_AMBIENT_ANIMATIONS);

SetListeningPatterns();

//WalkWayPoints();

}

 


You can also just overwrite "nw_c2_default9" for a test instead. You can restore the original version by simply deleting the custom one.


 


I commented out "WalkWayPoints();" as its wasteful to use if the NPCs do not stand a post or walk a route. I have a seperate version with it uncommented out that I use for NPCs with actual walk points.



               
               

               
            

Legacy_WhiteTiger

  • Hero Member
  • *****
  • Posts: 889
  • Karma: +0/-0
Creating a new object
« Reply #8 on: December 16, 2014, 04:56:44 am »


               


Make a custom OnSpawn script to test in a few select NPCs using this:


 


 


 


 


You can also just overwrite "nw_c2_default9" for a test instead. You can restore the original version by simply deleting the custom one.


 


I commented out "WalkWayPoints();" as its wasteful to use if the NPCs do not stand a post or walk a route. I have a seperate version with it uncommented out that I use for NPCs with actual walk points.




 


I have a bad... That does not work too =/


 


I think you guys does not understand properly the problem. I would like to make the creature move randomly onheartbeat. do the problem is onheartbeat script?



               
               

               
            

Legacy_kalbaern

  • Hero Member
  • *****
  • Posts: 1531
  • Karma: +0/-0
Creating a new object
« Reply #9 on: December 16, 2014, 05:44:52 am »


               

You said you were using Bioware scripts. If they are unmodified, then what I posted will work. The Bioware heartbeat scripts require you enable the AI variables either in the OnSpawn event or set as Proleric discribed. Perhaps you have modified versions. If the Bioware scripts show up in the module list when you open your script editor, they would be suspect.


 


If your module is experiencing lag, the "X2" scripts given to a new creature are prone to failure. This is because you are first firing one script that merely fires the original Bioware defaults. For some folks, especially if testing while in the toolset, these scripts fail. Make a script template using the scripts in the standard bandit and try that (along with my OnSpawn) as a test.


Heres the list of Events and scripts you should use.


 


OnBlocked - nw_c2_defaulte


OnCombatRoundEnd - nw_c2_default3


OnConversation - nw_c2_default4


OnDamaged - nw_c2_default6


OnDeath - nw_c2_default7


OnDisturbed - nw_c2_default8


OnHeartbeat - nw_c2_default1


OnPerception - nw_c2_default2


OnPhysicalAttacked - nw_c2_default5


OnRested - nw_c2_defaulta (you can leave this event blank if creature resting is not desired)


OnSpawn - nw_c2_default9 (either set the variable as Proleric explained or use my script in place of the default)


OnSpellCastAt - nw_c2_defaultb


OnUserDefined - nw_c2_defaultd (the Bioware default here is a null script so the event field can be left empty for any creature actually calling it)


 


If you are using NESS to spawn creatures, make certain that it isn't adding different AIs to your creatures.



               
               

               
            

Legacy_WhiteTiger

  • Hero Member
  • *****
  • Posts: 889
  • Karma: +0/-0
Creating a new object
« Reply #10 on: December 17, 2014, 02:07:34 pm »


               

I am with all Bioware standard scripts and I did exactly what you said. I created a onspawn script with the following code:



#include "x0_i0_anims"
void main()
{
SetSpawnInCondition(NW_FLAG_SHOUT_ATTACK_MY_TARGET);
SetSpawnInCondition(NW_FLAG_AMBIENT_ANIMATIONS);
SetListeningPatterns();
//WalkWayPoints();
}

Both ways, not worked. Creating NPC by function "CreateObject()" or creating by DM does not work, npc does not walk.


 


Have you tested it?



               
               

               
            

Legacy_Proleric

  • Hero Member
  • *****
  • Posts: 1750
  • Karma: +0/-0
Creating a new object
« Reply #11 on: December 17, 2014, 11:19:52 pm »


               I tested it using the Bioware onspawn. It works for me.


Are you sure you don't have a local version of any AI scripts?


What event is creating your objects? What's the script?
               
               

               
            

Legacy_WhiteTiger

  • Hero Member
  • *****
  • Posts: 889
  • Karma: +0/-0
Creating a new object
« Reply #12 on: December 18, 2014, 05:08:29 am »


               


I tested it using the Bioware onspawn. It works for me.


Are you sure you don't have a local version of any AI scripts?


 




 


Yes, I'm sure about that. 


 


 


"What event is creating your objects? What's the script?


 


OnHeartBeat is used to create my creature. the script is object oMonster = CreateObject(OBJECT_TYPE_CREATURE, "creature038", lLoc, TRUE);


 


--edited


 


after I give high AI (SetAILevel(oMonster, AI_...HIGH)



               
               

               
            

Legacy_Proleric

  • Hero Member
  • *****
  • Posts: 1750
  • Karma: +0/-0
Creating a new object
« Reply #13 on: December 18, 2014, 06:40:16 am »


               Which object's OnHeartBeat?

Might help to post the full script.
               
               

               
            

Legacy_WhiteTiger

  • Hero Member
  • *****
  • Posts: 889
  • Karma: +0/-0
Creating a new object
« Reply #14 on: December 18, 2014, 04:25:24 pm »


               


Which object's OnHeartBeat?


Might help to post the full script.




 


Is OnAreaHeartBeat... I just do some checks and start CreateObject(); nothing more else, and even creating the creature with the DM palette, it does not move automatically.