NPC inventory & AI manipulation

Discussion in 'General Modification' started by Livonya, Oct 25, 2007.

Remove all ads!
  1. Livonya

    Livonya Established Member

    Joined:
    Sep 25, 2003
    Messages:
    773
    Likes Received:
    0
    Sorry to be spamming new threads, but I want to get feedback on this, so this is the easiest way to contain the discussion.

    In the last few days I made some major break throughs with AI scripting. Unfortunately, it opens a pandora's box of possibility which is a little over whelming... I will get to that later.


    Part One: (fully implemented and working)

    I wrote a series of universal scripts which I will call "Tag & Bag"

    Here is how it works.

    1) If the NPC has a melee weapon and a ranged weapon that uses ammo (not a thrown weapon) then the script internalizes those weapons to the NPC and then makes them disappear.

    2) In the NPC's script you tell the NPC to hold either ranged, melee, or no weapon when standing around. You can change this at any time.

    3) When you enter combat the NPC can be told to use the ranged weapon or the melee weapon depending on the situation. Each round they will switch back and forth.

    4) When the NPC dies both weapons appear in the inventory.

    I used unique internal integer flags that seem unused to do this. So no global flags or variables are used at all. And it works with all weapons and all ranged weapons that use ammo. So even if the weapons are created randomly when the NPC is spawned then this script will work.

    Question:
    What are the other situations where these items should appear in the NPC's inventory. I was thinking the list would be Unconscious, Charmed, Suggestion.... are there others?


    Things to add:

    1) I need to add a tag for the shield, so that if you tell the NPC to stand around with no weapons then their shield will also unequip. An easy add.

    2) A script that will handle thrown weapons and their quantity.

    3) A check for out of ammo which will prevent the NPC from switching to the ranged weapon.


    Part Two: (the system seems to work, but I still need to write the AI parameters, and do a lot more testing)

    This is where it gets crazy. I figured out how to change the strategy for an NPC on the fly. This means that when the NPC changes from their ranged weapon to their melee weapon then I can ALSO change their AI routine from a melee AI routine to a ranged AI routine.

    So for example NPC X is a melee fighter with melee skills. She enters combat. She is too far away to advance to a target. So she switches weapons and switches to a ranged AI routine that could Ready vs. spell, or just fire at will.

    The change could be randomized. So NPCs will no longer behave the same in every battle, though Ready vs spell is fantastic... if you try to attack enemy units from a distance and pick them off one by one then you will have to deal with a hail of arrows/bolts/bullets when casting a spell.

    When a target enters a range that allows an advance to target, then her AI will be changed to her original combat AI and she uses her skills and talents as normal.

    In addition if NPC X has a potion of healing and is injured then the AI combat routine can be changed to one that will take a 5' foot step before drinking the potion, on the next round the AI combat routine goes back to her original routine.

    So for example, a single NPC armed with a ranged weapon and a melee weapon could perform many, many, many different actions depending on the situation. Let's say Ready vs. Spell on round one, fire at a target on round two, enter melee on round 3, flank on round 4, take 5' step and drink potion on round 5, enter melee on round 6, etc, etc, etc... each action according to the situation needed.

    This will also allow tighter control of spells like Fireball.

    For instance my NPC has a fireball spell. At the beginning of his round a script runs to determine distance to an enemy, distance of any allies to an enemy, and enemy that has the most number of other enemy units in a certain range. The script finds a good candidate for a Fireball that will hit several enemy units at once. The script then changes the NPC's combat AI to one that will cast Fireball.

    The possibilities are only limited by a scripters energy/desire to write scripts.

    Again, I have implemented the framework for implementing this system, but I still have to write some scripts and do some testing. So far it appears to be working in my test environment. I will do more experiments tonight.


    Conclusion:

    Part one is finished. I will post the scripts for this later tonight, or tomorrow night. So people can test it and find problems so that I can fix them. I am sure there will be a few issues, though I have yet to see have any problems with it.

    Part two is a work in progress. Once I have some working changes I will post the whole system so that scripters can start taking advantage of the system. It could take years for one person to script every possible change. So if it works well I hope some scripters will start to expand the system. I am trying to write a system that easily allows for people to contribute new AI routines without breaking the old ones.... as user friendly as possible.

    Anyway, I will post everything soon with detailed explanations on how to get it working and then scripters can use it for KoTB if they choose. Using it does not impact NPCs that don't use it. So it is a completely optional system.

    At this point if anyone can think of concerns or problems then please post your ideas. Or any ideas in general.

    Thanks.

    - Livonya
     
  2. Cuchulainn

    Cuchulainn Windmill Tilter

    Joined:
    Jan 16, 2006
    Messages:
    611
    Likes Received:
    0
    WOW!!

    This sounds bloody awesome. The AI handling for this game definitely needed improvement.

    :clap:

    Cuchulainn.
     
  3. Shiningted

    Shiningted I want my goat back Global Moderator

    Joined:
    Oct 23, 2004
    Messages:
    11,840
    Likes Received:
    48
    This sounds fantastic Liv :)

    I nearly went mad trying to work out a way to unequip NPCs so you don't have clerics standing around the church with their cudgels in their hand (so to speak) and poor Darmagon was never seen again after I asked him for help - we really needed this stuff! :thumbsup:

    EDIT: Btw, I will expect people making the various Caves of Chaos to use this stuff to the max: sensible tactics such as a tribe of belligerent humanoids would have will mean we can make them extremely tough encounters while keeping the monsters 1st level.
     
    Last edited: Oct 26, 2007
  4. Lord_Spike

    Lord_Spike Senior Member Veteran

    Joined:
    Mar 25, 2005
    Messages:
    3,151
    Likes Received:
    0
    The very thing needed, especially for the Kobolds & their trapped entrance way. Ought to make the whole series of caves just the way they should be!

    Damn; I hate to imagine revised combat against the bugbears in ToEE. :yikes:
     
  5. lord_graywolfe

    lord_graywolfe Wolfman

    Joined:
    Apr 30, 2004
    Messages:
    739
    Likes Received:
    0
    oh boy more stuff for me to figure out lol ;) ah well.

    it does sound great Liv :)
     
  6. maggit

    maggit Zombie RipTorn Wonka

    Joined:
    Oct 20, 2005
    Messages:
    1,944
    Likes Received:
    0
    Such revised tactics would surely improve Co8 5.0.0 in
    terms of rebalancing. I remember one bugbear from the
    Moathouse who would improved trip my characters and
    practically kill them at the first round, and at the same
    time he was really hard to hit. Now, that was a bugger. ;)
    If every monster would be like that... then wow... intelligent
    behaviour!
     
  7. Livonya

    Livonya Established Member

    Joined:
    Sep 25, 2003
    Messages:
    773
    Likes Received:
    0
    Here is an update from last nights work.

    The ironic thing is that I ran into a serious problem with Part One, but had no problems with Part Two.

    I created a crash situation on game save with my item tag & switch weapons system. But it isn't universal and may be an annomaly. I have to do some tests. I think I know exactly what caused it but I haven't had time to re-create the situation. The problem seems to be based on how an NPC was armed via the ToEE World Builder.... but I haven't had time to verify it. Again it may have just been an annomaly. Once I have that isolated then I will post it as it does work smoothly.

    As for Part Two. That is definitely going to work.

    I only had time for some simple test runs last night.

    I attack my test subject at range. The NPC changes to ranged weapon, and changes to an AI script that involves Ready Vs. Spell. Once I get in range he switches back to his original AI script and advances to melee.

    I have more tests of course, but I think it will all work. I just have to get the scripting right.

    Some scripting commands work differently in and out of combat, and I have spent some time looking at code that I know works but doesn't work...

    Anyway, I should have it worked out soon.

    - Livonya
     
  8. Shiningted

    Shiningted I want my goat back Global Moderator

    Joined:
    Oct 23, 2004
    Messages:
    11,840
    Likes Received:
    48
    Now we can play with deeper parts of the game via ToEEWB, we seem to be creating more and more situations where we need to start a new game to get things working. Even when I was implementing your secret door fix, by the time I had moved the cats arround and edited the sector to replace the secret door with a DONT_DRAW model, I had to start a new game to get it working.

    Don't worry if your mods need a new game, the public just have to wear that :)
     
  9. Livonya

    Livonya Established Member

    Joined:
    Sep 25, 2003
    Messages:
    773
    Likes Received:
    0
    ----------------------------

    :tombstone WARNING: :tombstone

    I warn you now. The system I designed WILL crash the game upon save if you use the system on weapons or shields that were created in the TOEE World Builder using the ADD EXIST button rather than the ADD NEW button.

    This system will work fine for weapons/shields spawned in game, and it will work fine with weapons/shields spawned with TOEE World Builder using the ADD NEW button.

    So if you try to add this system to an NPC that is already in KoTB or in ToEE it might crash depending on how the weapons/shields were placed into the game.

    You have been warned.

    -------------------------------

    With that out of the way...

    I have completed the system for tracking an NPC's weapons and changing them at will via scripting. It was a lot harder than I thought. A lot of scripting, and a lot of room for variation problems. But I think I have all the bugs cleared out.

    And I think it works great, though I will be shocked if it is bug free.

    I have created 2 folders. One is for scripters/moders and the other is for testing.


    FOR TESTERS:

    If you would just like to see how it works. Then simple put the two files in the "test scripts" folder in your data.koTB/scr folder.

    Then start up a game in KoTB. Find a place where you would like to test/fight.

    Open the Console

    In the console type:

    from Livonya import*

    hit enter and then type:

    start_test(5)

    You can change the number to whatever you like. It will create that number of enemy NPCs that will be holding various weapon configurations at random.

    You can enter a fight with them and see how it works. But be warned the AI script is stupid. This is ONLY a test to see how switching weapons works. During combat go close range to get them to go melee and go to distance for them to go ranged. When they run out of ammo they should only go melee.

    If you encounter errors then please post exactly what happened. Especially what weapons the NPCs were using when the errors occurred.

    Just for fun open the console again and type:

    falldown()

    when you do this all the NPC's should go unconscious. You can then change their weapons around, hit rest, and then see what happens. You might have to do it more than once to knock them all out.


    FOR SCRIPTERS/MODDERS:

    In the "templet scripts" folder you will find two files.

    The file called "add to utilities" has all the scripts that need to go in whatever utilities import file you want.

    The py0000script is just a dummy script that you can cut and paste into any NPC py script.

    I have tried to note what everything does. So anyone interested in how it works should be able to figure it out.

    There are some rules:

    1) Every NPC that gets this script routine MUST have only ONE melee weapon and only ONE ranged weapon that uses ammo. A shield is optional. It won't make any difference, but only ONE shield should be used. Don't forget to give your NPC ammo.

    2) Any weapon that is used MUST have a unique entry in the OBJECT NAME (per oname.mes) column that matches the protos line number for that item.

    3) All ranged weapons used MUST have an entry in the WEAPON FLAGS (OWF *) column that says OWF_RANGED_WEAPON. Any ranged weapon that doesn't say that won't work.

    4) This is the bare bones of my new AI scripting system. The format for this new system will fit right into this templet. So feel free to change these scripts around, but be warned that some of the formatting will be necessary for my new AI scripting system.

    5) Don't forget about the warning!!! (see top of this post!!!!)


    And in the just so you know department.

    When an NPC is Charmed the system turns off and all weapons/shields will appear in the NPC's inventory. When Charm wears off the system turns back on.

    When an NPC is Suggested the system turns off and all weapons/shields will appear in the NPC's inventory. When Suggestion wears off the system turns back on. If the player changes the NPC's inventory during Suggestion then whatever items were left will be tagged and bagged. This may cause problems. I have no idea. If a player puts a bunch of weapons in the NPC's inventory before Suggestion wears off then bad shit might happen... I am not sure. Most likely the NPC will just go hostile and be killed so it won't matter much.

    When an NPC is knocked unconscious the system turns off and all weapons/shields will appear in the inventory. When they wake up the system turns back on. Again, if a player puts strange stuff in the NPC's inventory then bad shit might happen.

    And lastly, this system can be used out of combat as well.

    Once an NPC has their items tagged and bagged, then you can bring them back via scripting at any time.

    For instance if you decide your guards should be on high alert just tell them to:

    get_melee_weapon(attachee)

    When you are ready for them to put their weapons away again use:

    get_everything(attachee)
    tag_weapons(attachee)

    And for future reference I am using the 4 following unique variable flags:

    obj_f_pad_i_7 (used for ranged swap)
    obj_f_pad_i_8 (used for shield swap)
    obj_f_pad_i_9 (used for melee weapon swap)
    obj_f_pad_i_0 (used for strategy swap)

    The obj_f_pad_i_0 variable flag doesn't appear in these scripts, but it is the variable flag that I will be using when I upgrade to the strategy AI swap system.

    Okay, have fun and let me know how it works.

    I poured sweat and tears into this, so I hope it works reasonably well.

    - Livonya

    PS: My new AI strategy swap system is up and running. It works great, but I want to release this first part and get feedback and error data before moving on to the next stage. I have already used my new AI system to build some amazing battles. For instance I have one battle where the enemy Pikemen all hold ground and go Ready vs. Charge. The enemy mage then casts fireball. Once the fireball is cast the Pikeman advance for combat.
     
    Last edited: Nov 7, 2007
  10. Shiningted

    Shiningted I want my goat back Global Moderator

    Joined:
    Oct 23, 2004
    Messages:
    11,840
    Likes Received:
    48
    [picks jaw up off floor]

    nice work? :eek:
     
  11. Livonya

    Livonya Established Member

    Joined:
    Sep 25, 2003
    Messages:
    773
    Likes Received:
    0
    As an update.

    I wrote a routine to handle an NPC that has 1 melee weapon and some # of thrown weapons. It doesn't allow for a shield, however.

    It works similar to the above scripts, but handles thrown weapons.

    I will post that soon, plus some improvements to the script I already posted.

    Also, on the AI front I am writing commands for pets. So you can control the pet's attack scripts via dialog.

    For instance the 1st one I am doing you can tell your pet to ready vs. attack and only attack if something attacks it... this will hold for as many rounds as you tell it to hold. And then the script will revert to the normal attack script.

    This way you can keep your pets from rushing into combat.

    [edit] Pet control is in. It works perfectly. You will have the following options:

    1) attack at will (default)

    2) hold ground -- will not charge... will only attack if enemy enters attack zone

    3) hold ground until attacked... will hold ground until attacked and then will attack at will

    4) hold ground for 1 to 4 rounds.... will hold ground for # of rounds you choose

    More can be added but that is all I have written so far.

    Everything is coming along nicely. The game combat is much better with more random elements and more logical behavior.

    Also, I think I will write dialog script change routines for the Mercenaries that you can hire in the pub. It should be easy to do.

    By Monday I should have everything together and then I will post an explanation of how to do it and how it all works.

    As long as scripters/modders maintain the strategy.tab format that I have worked on then an unlimited # of new scripts can be written and added on without interfering with existing AI scripts.

    It is very clean and very simple. The only trick is maintaining the strategy.tab correctly.

    Anyway, back to work I go...

    - Livonya
     
    Last edited: Oct 29, 2007
  12. Shiningted

    Shiningted I want my goat back Global Moderator

    Joined:
    Oct 23, 2004
    Messages:
    11,840
    Likes Received:
    48
    Liv, I never use familiars or pets so I don't know about this, but can it be used on any follower (mercenaries / commanded undead)?

    Limited control of those folks would be fantastic :clap:
     
  13. Half Knight

    Half Knight Gibbering Mouther

    Joined:
    May 16, 2007
    Messages:
    2,148
    Likes Received:
    0
    If my wolf companion heard that...they're companions...pets are for WoW :mrhappy:

    And also, that's exactly the way that they should work :yes:
     
  14. Livonya

    Livonya Established Member

    Joined:
    Sep 25, 2003
    Messages:
    773
    Likes Received:
    0
    The script I did is only intended for the Animal Companions that Druids and Rangers can have.

    It doesn't give you control. It just allows you to give them very primitive instructions. It is 100% better than they were, but it is a far cry from total control. I think it fits within the scope of their brains as well.

    The familiars are actually put into your party, and you already have 100% control over them. So they don't need it.

    For the mercenaries I will write a more complicated script that allows you to give them pre-battle instructions such as:

    use range weapon
    use melee weapon
    ready vs. approach
    ready vs. spell

    Again these aren't exact instructions but just basic principles that the mercenaries will follow.

    A lot can be done.

    Right now I am just fine tunning the system.

    - Livonya

    PS: I would think the undead should just be mindless undead. But if someone wants to write a script for them it will take about 10 minutes. Once I am done building the system then adding stuff for other monsters/NPCs will be relatively easy and painless.
     
  15. Shiningted

    Shiningted I want my goat back Global Moderator

    Joined:
    Oct 23, 2004
    Messages:
    11,840
    Likes Received:
    48
    I'd just suggest 'stay' and 'charge' for undead (perhaps with a 50% chance they ignore 'stay'). But thats just me :) Otherwise, this sounds great :mrhappy:
     
Our Host!