Author Topic: Noobish Scripting Woes  (Read 637 times)

Legacy_HarmlessLittleGnome

  • Jr. Member
  • **
  • Posts: 58
  • Karma: +0/-0
Noobish Scripting Woes
« on: September 04, 2015, 05:00:05 am »


               

I am having major trouble with what should be some simple scripting. Sadly, I truly am a noob.


I've got a zone and I want pedestrians. Imagine a street in Victorian England...


I want some npcs (soldiers) to move with purpose, patrolling diligigently.

I want some npcs to wander in a really random fashion. Imagine a little mouse scurrying about...


I want some npcs to wander at random, but change directions less often than the mice...


But at present I can't get anyone to move at all.


I've tried a few things online and they don't seem to function...or even to be complete.

 


I've also tried Lilac Soul's script gen but it doesn't seem to work.


 


Script is included here.


This zone is basically one big wide north south corridor with doors leading out to other zones.


PumpN and PumpS tags refer to water pumps at the far north and south end.

 


   /*   Script generated by

Lilac Soul's NWN Script Generator, v. 2.3

 

For download info, please visit:

http://nwvault.ign.c...&id=4683&id=625   */

 

//Put this script OnEnter

void main()

{

 

object oPC = GetEnteringObject();

 

if (!GetIsPC(oPC)) return;

 

if (d100()>50)

   return;

 

object oTarget;

oTarget = GetObjectByTag("GoblinPed");

 

AssignCommand(oTarget, ActionMoveToObject(GetObjectByTag("PumpN")));

 

AssignCommand(oTarget, ActionMoveAwayFromObject(GetObjectByTag("PumpN")));

 

AssignCommand(oTarget, ActionMoveToObject(GetObjectByTag("PumpS")));

 

AssignCommand(oTarget, ActionMoveAwayFromObject(GetObjectByTag("PumpS")));

 

AssignCommand(oTarget, ActionMoveToObject(GetObjectByTag("TorchC")));

 

}


               
               

               
            

Legacy_The Mad Poet

  • Hero Member
  • *****
  • Posts: 715
  • Karma: +0/-0
Noobish Scripting Woes
« Reply #1 on: September 04, 2015, 07:54:15 pm »


               

I can tell you a few things. For one you can use the WalkWaypoints system for the guards. You can find what you need here.


 


http://www.neverwint...xewaypoints.htm


 


For wandering seemingly aimlessly all you should have to do is call ActionRandomWalk(); in the onSpawn script, though if you talk to them or anything it will stop them from moving.


 


If you are looking for a VERY easy way to do this you can look at the default onSpawn and uncomment the Ambient Animations lines, that should make EVERYONE default to that if you overwrite the default script.


 


However the easiest way is to just add the 'X2_L_SPAWN_USE_AMBIENT int 1' variable to the creatures you want to wander aimlessly and use animations. This has to be done with each creature though.



               
               

               
            

Legacy_HarmlessLittleGnome

  • Jr. Member
  • **
  • Posts: 58
  • Karma: +0/-0
Noobish Scripting Woes
« Reply #2 on: September 05, 2015, 06:46:05 am »


               

All right! TYVM for the reply.

Actually, I found some problems with the script I showed. Good as it may appear, as I say...everyone stands stock still. 

The script is a zone script... and it *does* work except...it animates one person. I missed them at first, so I thought it was a total failure instead of 95 percent. If this script is to be salvaged, I have to figure out how to get it to call many with the same tag. Or maybe similar tags (dude1, dude2, dude3...)

However the easiest way is to just add the 'X2_L_SPAWN_USE_AMBIENT int 1' variable to the creatures you want to wander aimlessly and use animations. This has to be done with each creature though.


Good to know. This question is going to sound like I'm not listening... I am, I'm just learning...

Can I... Build a custom npc, drop this in, plant a decent size crowd of them, and then edit each individually to customize appearance? Or must it truly be added to each regardless?


Thank you again.


 



               
               

               
            

Legacy_The Mad Poet

  • Hero Member
  • *****
  • Posts: 715
  • Karma: +0/-0
Noobish Scripting Woes
« Reply #3 on: September 05, 2015, 06:54:23 am »


               

Any creature you edit in the palette, or in the game world can have the variable attached. You just need to use the default creature scripts when doing this (which will always be default unless you change them anyway). You can have them have any appearance you want. They can look like unicorns, dragons, monkeys and elves. Doesn't matter. As long as that variable is attached and the default scripts are loaded. 


 


In other words yes you can create a palette NPC with the variable, and then drop dozens of them and edit each. 


 


If the script you posted is meant for an Area script then likely in order to make it work you need to loop through all the creatures in the area checking for the tag. Though that's unnecessary if you use the variable method, or alter the default scripts. Plus as long as that variable is attached they will heartbeat and start walking like normal if a conversation ends. Other ways they might just sit still after being talked to.


 


Your choice, boss. '<img'>



               
               

               
            

Legacy_HarmlessLittleGnome

  • Jr. Member
  • **
  • Posts: 58
  • Karma: +0/-0
Noobish Scripting Woes
« Reply #4 on: September 05, 2015, 07:46:39 am »


               

Ahahahahah!!! Thanks! It worked! For... about five seconds.


I'm going to invest in learning the patrol system but... I have a tough time with scripting.

I think I need to figure out if there is anywhere I can go to learn the language from the ground up.


For now I set up some rats, chickens and pedestrians with 
ActionRandomWalk()

and it worked! But the rats attacked the pedestrians and well... no more walking.


I'll have to figure out how to make commoner rats I expect. Should be simple.


 


Again, thank you so much.


               
               

               
            

Legacy_Proleric

  • Hero Member
  • *****
  • Posts: 1750
  • Karma: +0/-0
Noobish Scripting Woes
« Reply #5 on: September 05, 2015, 12:05:24 pm »


               

Rats - change faction to Commoner on the Advanced tab of the creature template


 


See this thread for a discussion on random NPC appearances.


 


Strangely, crowd scenes can be amongst the most difficult to get exactly right. NPCs tend to walk into corners then get stuck. In my experience, random walk and ambient animations are especially prone to this. There are some configurable scripts (this, for example) but that might be more than you need.


 


I prefer WalkWaypoints. You don't have to stick to the simple circuit or back-and-forth pattern used for guards. A long crazy path through the area with digressions, backtracking and path crossing can start to look completely random. Just ensure that there is a clear line of sight between consecutive waypoints, with no obstructions, and lots of room at crossings for the NPCs to avoid one another.



               
               

               
            

Legacy_The Mad Poet

  • Hero Member
  • *****
  • Posts: 715
  • Karma: +0/-0
Noobish Scripting Woes
« Reply #6 on: September 05, 2015, 05:56:44 pm »


               

If you are trying to learn scripting the best suggestion I can give is to make scripts. Anything and every simple thing you can think of. Triggers that open doors, switches that spawn creatures, whatever. Read other scripts and try and make them do the same thing differently. Just play around enough and things will start to make a lot more sense slowly.



               
               

               
            

Legacy_HarmlessLittleGnome

  • Jr. Member
  • **
  • Posts: 58
  • Karma: +0/-0
Noobish Scripting Woes
« Reply #7 on: September 06, 2015, 02:44:58 am »


               

Not to press you but I'm getting to a point where I know my problem is a failure of understanding the "grammar" of scripting.


As you and I write each other, we use a language that has a strong tendency toward Noun-verb-subject(object?)


It can be reversed... instead of 'Mark hit Joe' we can say 'Joe was hit by Mark' but it tends to have a number of pitfalls... more words, more confusion...and once it a while...a poetic home run.


But scripting is far more exacting. I'm just now learning those code references "on spawn", "on enter" "on use" "on heartbeat" tell me where the script goes.

Someone was instructing me and somehow we ended up placing it in one place, coding it for another...and on reflection needing it to be in a third.

I changed the "onuse" to an "onopen"...put it there and everything was great.


Baby's first coding steps, lol...


So I'm on a quest to learn what all those oTags and Gets and oPC's mean and why does a void main matter anyways? Why {} and why more than one?


At any rate, that's a big quest and until I have a simple question, I think this is where I fade into the sunset. 

Thank you for all of the wonderful info you've shared. There were many pearls I would not have found anytime soon.



               
               

               
            

Legacy_HarmlessLittleGnome

  • Jr. Member
  • **
  • Posts: 58
  • Karma: +0/-0
Noobish Scripting Woes
« Reply #8 on: September 06, 2015, 03:21:16 am »


               

One last silly question.


When setting way points I note there are "color options". Default is blue.

Do they matter? What is a color's function?



               
               

               
            

Legacy_The Mad Poet

  • Hero Member
  • *****
  • Posts: 715
  • Karma: +0/-0
Noobish Scripting Woes
« Reply #9 on: September 06, 2015, 06:03:09 am »


               

There is none. Just to look different.



               
               

               
            

Legacy_Proleric

  • Hero Member
  • *****
  • Posts: 1750
  • Karma: +0/-0
Noobish Scripting Woes
« Reply #10 on: September 06, 2015, 10:00:57 am »


               

Color options are a visual aid to the builder in the toolset. For example, if you make walk points blue and map pins red, you can easily see which is which, even if the area becomes cluttered with many waypoints.



               
               

               
            

Legacy_HarmlessLittleGnome

  • Jr. Member
  • **
  • Posts: 58
  • Karma: +0/-0
Noobish Scripting Woes
« Reply #11 on: September 06, 2015, 01:05:29 pm »


               

I've got a whole new noobish problem, but I'm beginning to suspect the issue may not be me.


Simple thing... and I've done this before, admittedly years ago.

You are whisked into a room via a teleport function to a waypoint... done. works like a charm.


An npc perceives you, runs up and starts a conversation...done...works like a charm.

 


However, that first conversation is different from any subsequent conversations... and this is making me crazy.

So far I've tried the in game scriptor, Lilac Soul's scriptor, and I've tackled it on my own...all to no success.


I'm starting to feel like the game was recently updated in a way that renders all previous knowledge invalid.


How do I do this?



               
               

               
            

Legacy_HarmlessLittleGnome

  • Jr. Member
  • **
  • Posts: 58
  • Karma: +0/-0
Noobish Scripting Woes
« Reply #12 on: September 06, 2015, 01:41:25 pm »


               

Whoops! Never mind. Just when I had given up all hope, I solved it! '<img'>