Friday, September 23, 2011

Working on Behavior ...

After getting the wandering monster scripts to spawn the critters when and where I wanted, the next step was getting those critters to behave as respectable critters should. 

I am using ‘Experience Points’ (XP) to record the Player’s score as they progress through the game; mainly because it is convenient for both me and the Player.  So, I turned off the XP given for killing things to prevent folks from running around killing birds and deer and such in lieu of exploring the caves.  The wandering monsters (except for the goblins) all span in as “neutral” to the Player; and as long as the Player does not attack them, they should remain so.  The rats, badger and bear being ‘omnivores’ will become hostile toward the Player if they approach too closely.  I really wanted the animals to attempt to stay clear of the Player, much as animals in the wild tend to do, if they are given the opportunity.

This modification is really pretty easy in the toolset as Bioware has made it possible to execute custom OnEvent scripts for creatures by simply removing the “//” in front of one line of code in the OnSpawn script which triggers an event and directs the engine to look for any custom code for that event in the UserDefined slots.  This allows the default Bioware scripts for each of the events to run as normal, while also running any additional scripts the designer wanted to include.

For these animals, the Event of interest is the OnPercieved event, which will run when the animal first detects the presence of another.  We are only interested in doing something special if the creature detected is the Player, in which case we have the animal move away and then disappear (destroy it).  Yes, it is pretty basic, but remember. these wandering monsters are “add-ins” and not part of the original text adventure; so I don’t want them doing much other than add a bit of ‘realism’ as the Player explores the areas.

The Pirate required a bit more scripting though.  He was to appear next to the Player, steal any treasures the Player may have in their inventory and then run off.  Getting him in and running off with a bit of ‘dialog’ was easy enough … ‘stealing’ the treasures was a lot more effort than it should have been (often the case).  I started out by having the Pirate ‘take’ any treasures the Player had with the intention of then having him ‘give’ them to the Pirate Chest (where the Player can recover them later); but, in spite of the script running, the items were not getting removed.  I still don’t know why (but I suspect it has something to do with the Pirate’s Inventory).  So, I decided just to destroy the objects and create another copy of them in the chest.  This got rid of the objects, but object removed this way do not trigger their OnUnAquire scripts and I was depending on those scripts to track inventory as well as trigger states of other objects in the game.  After a bit of head scratching I realized I didn’t need the Pirate to take the items at all, I could just have the Pirate’s Chest take the items, adding them to its inventory (where I wanted them to be anyway) and be done with it, heh.  That worked like a charm.  J

No comments:

Post a Comment