Dahan Posted September 2, 2010 Share Posted September 2, 2010 I need help finding the best way to handle my AI packages in my mod. I've been working on controling the NPCs living in my mod. The NPCs can work on one of many shifts (day, night, etc) and can have one of many jobs (like doctor, shopkeeper, security, etc). All of the NPCs inherit their AI packages from a singule, unused NPC. NPC inventory is used to assign profession and shift in the form of a token (an unplayable armor object) that the NPC has or doesn't have. These tokens are handy for setting dialogue and package conditions. To set up an AI package for an NPC's work shift, I know I can create ( # shifts ) x ( # jobs ) packages where each package has conditions set checking on each combination of job and shift. I don't want to do this. I want each job's package to do the same thing no matter which shift is up, so having one per shift means a chance of having two job packages be inconsistant with one other. What I want to do is use a third type of token in the NPC's inventory that determines if the NPC should be working or not. Dialogue options to test if the NPC is on duty can test for that on-duty token. Likewise I would only need a single AI package per job, whose conditions would test if the NPC is on-duty and has that specific job. The new package would have to be always-on and placed in the main NPC's AI package list below meals which double as on-off duty changes. It has a lot of potiental if I can get it to work. I can make NPCs change jobs or shifts easily while using just one package for any given job or activity. So what is the best way to change these activity tokens and make sure the NPC is running the right package once they are changed? Is it better to remove/add or simply have it in standard gear that is then equipped/unequipped? Can you equip something with no selected bipod object? I've tried a gamemode script on the NPCs that changes their activity using setav in which the NPC equips or unequips the on-duty token that doubles at a hat. The hat form isn't perfect, but makes it easy to see who should be working or not. It works for dialogue and in cheat mode, but it doesn't seem to kick in when I use setav Variable06 2 in the mealtime shift change Begin/End scripts. When meals come around, no one takes off or puts on the hat at the start or end of the meal like they should. Link to comment Share on other sites More sharing options...
Dahan Posted September 2, 2010 Author Share Posted September 2, 2010 I think I figured out my mistake. The setav command works off the NPC's gamemode script. I was trying to use it in a package end to change a condition checked at the start of a package starting at the same time. My fix is to use setav at the start of a meal using the package begin scrip, giving setav an hour to set up the activity token before it's checked by a profession AI package conditions. I've simplifed things a little. Below is the begin script for my PkgMeal06. TokenOnDuty is an item all my NPCs start off with. It's scheduled to occur each day at 06 for 1 hour and is set MustComplete and MustReachLocation. ; The begin script of PkgMeal06 if ( getItemCount TokenShiftDay == 1 ) equipItem TokenOnDuty 1 0 else unEquipItem TokenOnDuty 1 0 endif If I watch the NPCs from 5:59am to 6:00am, many but not all of them will put on or take off their hats appropriately. If I use the Wait option to jump that period, it's much less likely for the NPCs to wear or not wear the TokenOnDuty hats aopropriately. What's going on? Link to comment Share on other sites More sharing options...
Dahan Posted September 2, 2010 Author Share Posted September 2, 2010 I've experimented and found that AI package scripts are a little difficult to use. I've also found that using getEquipped for tokens runs into problems of NPCs wearing or not wearing the items. It's best just to add or remove item in such cases. I got shift changes working using the NPC script's gamemode block. The packages only check for things like getItemCount TokenOnDuty to see if someone should be working or not. Anyways, here is the solution I ended up using. scn HavenDweller04Script ; Look into making this an hourly update for shift. Allow changing play and study modes as needed and adding shower. float nextHour ; If currentTime >= this, update shift data. float currentHour ; if currentTime < this, update shift data. short currentHour ; Ranges from 0 to 23. short myHour ; Ranges from 0 to 23. short currentTask ; 1 to 6 for shower, eat, work, study, play, sleep. short lastTask ; Records last currentTask. short stage1 ; What stage the variable01 script is in. float timer1 ; Timer used for variable01 stuff. begin gamemode . if ( getCurrentTime < currentHour ) || ( getCurrentTime >= nextHour ) || ( currentHour == nextHour ) set currentHour to getCurrentTime / 1 set nextHour to currentHour + 1 ; Determine relative hour in the day for the processing NPC if getItemCount TokenShiftDusk > 0 set myHour to (( 6 + currentHour ) % 24 ) elseif getItemCount TokenShiftNight > 0 set myHour to (( 12 + currentHour ) % 24 ) elseif getItemCount TokenShiftDawn > 0 set myHour to (( 18 + currentHour ) % 24 ) else set myHour to currentHour endif ; Determine currentTask based on the relative hour. if ( myHour == 6 ) ; shower set currentTask to 1 elseif ( myHour == 7 ) || ( myHour == 12 ) || ( myHour == 19 ) ; eat set currentTask to 2 elseif ( myHour >= 13 ) && ( myHour < 19 ) ; work set currentTask to 3 elseif ( myHour >= 8 ) && ( myHour < 12 ) ; study set currentTask to 4 elseif ( myHour >= 20 ) && ( myHour < 23 ) ; play set currentTask to 5 else ; sleep set currentTask to 6 endif ; Only if the task changes or if the task is play do we change tasks. if ( lastTask != currentTask ) || ( currentTask == 5 ) ; add/remove task tokens. ; Remove any tokens issued by a leveled item. if ( getItemCount TokenAuditorium > 0 ) removeItem TokenAuditorium 1 endif if ( getItemCount TokenTest > 0 ) removeItem TokenTest 1 endif if ( getItemCount TokenCLab > 0 ) removeItem TokenCLab 1 endif if ( getItemCount TokenLibrary > 0 ) removeItem TokenLibrary 1 endif if ( getItemCount TokenJogging > 0 ) removeItem TokenJogging 1 endif if ( getItemCount TokenParty > 0 ) removeItem TokenParty 1 endif if ( getItemCount TokenSwim > 0 ) removeItem TokenSwim 1 endif if ( getItemCount TokenWalk > 0 ) removeItem TokenWalk 1 endif ; The following tokens have a 1 to 1 relationship with a task. if ( getItemCount TokenShower == 0 ) && ( currentTask == 1 ) addItem TokenShower 1 elseif ( getItemCount TokenShower > 0 ) && ( currentTask != 1 ) removeItem TokenShower 1 endif if ( getItemCount TokenEat == 0 ) && ( currentTask == 2 ) addItem TokenEat 1 elseif ( getItemCount TokenEat > 0 ) && ( currentTask != 2 ) removeItem TokenEat 1 endif if ( getItemCount TokenOnDuty == 0 ) && ( currentTask == 3 ) addItem TokenOnDuty 1 elseif ( getItemCount TokenOnDuty > 0 ) && ( currentTask != 3 ) removeItem TokenOnDuty 1 endif if ( getItemCount TokenSleep == 0 ) && ( currentTask == 6 ) addItem TokenSleep 1 elseif ( getItemCount TokenSleep > 0 ) && ( currentTask != 6 ) removeItem TokenSleep 1 endif ; These tasks issue leveled item tokens. if ( currentTask == 4 ) addItem TokenStudy 1 elseif ( currentTask == 5 ) addItem TokenPlay 1 endif ; Make sure NPC is doing what they are supposed to be doing. EvaluatePackage ; Mind your history. set lastTask to currentTask endif endif ; Insert variable0# checks here. ; variable01 is used for doctor animation. if ( getAV Variable01 == 0 ) ; do nothing elseif ( timer1 <= 6 ) && ( stage1 == 1 ) IMod FadeToBlackISFX set stage1 to 2 elseif ( timer1 > 0 ) set timer1 to ( timer1 - getSecondsPassed ) elseif ( stage1 == 0 ) disablePlayerControls sayto player MegDocChurchMedicalChatter set timer1 to 8 set stage1 to 1 PlayIdle LooseDoctorHealPlayer resetai elseif ( IsImagespaceActive FadeToBlackISFX == 0 ) enablePlayerControls if ( getav Variable01 == 1 ) setstage Doctors 10 elseif ( getav Variable01 == 2 ) setstage Doctors 20 elseif ( getav Variable01 == 3 ) setstage Doctors 30 endif setav Variable01 0 resetai set stage1 to 0 endif ; A variable04 change means changing clothing. if getav Variable04 != 0 ; Remove inappropriate attire if ( getEquipped BlueSuitHaven == 1 ) && ( getav Variable04 != 2 ) unequipItem BlueSuitHaven 0 0 elseif ( getEquipped RedSuitHaven == 1 ) && ( getav Variable04 != 2 ) unequipItem RedSuitHaven 0 0 elseif ( getEquipped VaultLabCoat == 1 ) && ( getav Variable04 != 2 ) unequipItem VaultLabCoat 0 0 elseif ( getEquipped OutfitPrewarNegligee == 1 ) && ( getav Variable04 != 3 ) unequipItem OutfitPrewarNegligee 0 0 endif ; Put on appropriate attire if ( getav Variable04 == 2 ) && ( getItemCount BlueSuitHaven > 0 ) equipItem BlueSuitHaven 0 0 elseif ( getav Variable04 == 2 ) && ( getItemCount RedSuitHaven > 0 ) equipItem RedSuitHaven 0 0 elseif ( getav Variable04 == 2 ) && ( getItemCount VaultLabCoat > 0 ) equipItem VaultLabCoat 0 0 elseif ( getav Variable04 == 3 ) && ( getItemCount OutfitPrewarNegligee > 0 ) equipItem OutfitPrewarNegligee 0 0 endif setav Variable04 0 endif end Link to comment Share on other sites More sharing options...
ExtremeTurdball Posted September 9, 2010 Share Posted September 9, 2010 hey man i was wondering if you could assist me in an incredibly easy ai package? i have been trying to make a package that has the selected npc wander the wasteland (not just from point a to point b, and not just one cell) during the day, and then return to a base that i made when it is 8 pm. if you can help thanks and i will of course give credit if i upload it. Link to comment Share on other sites More sharing options...
Quetzlsacatanango Posted September 10, 2010 Share Posted September 10, 2010 I don't know how you would go about that if you just want them to randomly wander the whole wasteland. I would pick a few locations. I don't know what the max radius is so maybe you could make it big enough to cover the whole wasteland this way. Not sure. On the NPC put a script with a variable named something like "location". On the end result of the package where they are at your base, add the line set mynpcref.location to getrandompercentevp Give each NPC a package to go to each location. Say there are 10 locations, put a condition on each one . Location 1:If location >= 0 && location < 10 Location 2:if location >=10 && location < 20 etc.. for all 10. You could go up to a hundred locations this way, or virtually unlimited with a couple math tricks, and it would be random. Maybe there is an easier way but that's what comes to mind for me. Link to comment Share on other sites More sharing options...
Dahan Posted September 11, 2010 Author Share Posted September 11, 2010 hey man i was wondering if you could assist me in an incredibly easy ai package? i have been trying to make a package that has the selected npc wander the wasteland (not just from point a to point b, and not just one cell) during the day, and then return to a base that i made when it is 8 pm. if you can help thanks and i will of course give credit if i upload it. I think I can help. You'll want to create at least two AI packages. In the Object Window, go to Actor Data -> Package. Right click and select New to create a new package. One package should cover the wandering the wasteland behavior. Another will be the return to base package. You can use the Schedule tab to set when they run, and/or use the Condition tab and check getCurrentTime (the time in hours where 20 = 8 p.m.) Check http://geck.bethsoft.com/index.php/Category:Packages for the details about packages. Once the packages are set up, go to Actors -> NPCs and make or copy your character that will use these packages. On that actor, edit it and go to the AI Packages tab. If it's greyed out, uncheck the "Use AI Packages" radio button so it isn't inheriting AI packages from its ActorBase. Add your new packages, putting the ones with the more specific conditions or scheduling at the top. Now put your actor into the world if you haven't before, and you're all set. Suggested Packages ETReturn2Base: Package type Travel. Destination: In Cell (your home base cell). Flags: Must Complete, Must Reach Location, Always RunSchedule: Time: 20Conditions: IsInCell <your home cell> != 1. ETSleep: Package type: Sleep. Destination: In Cell (your home base cell). Flags: Must Complete, Must Reach LocationSchedule: Time: 20, Duration 8Conditions: IsInCell <your home cell> = 1. (optional) ETWanderPackage type: Sandbox or WanderDestination: Somewhere outside with a very wide radius.Schedule: any time (must place low on actor list to avoid conflicts) Link to comment Share on other sites More sharing options...
Recommended Posts