Oblis Posted September 12, 2012 Author Share Posted September 12, 2012 The only problem is that the code is too big!I have 20 npcs and I have to put 20 times the lines i mentioned above in the script.Ho i have to create 20 packages for reading (1 for each npc), 20 for drinking, 20 for alchemy etc. Thats all... But ay least it worked :) Link to comment Share on other sites More sharing options...
WarRatsG Posted September 13, 2012 Share Posted September 13, 2012 Im sure I could help you come up with something to make it more dynamic. I reckon you could make it up to 50% smaller. Post your code, and I will try to help you optimize it. Link to comment Share on other sites More sharing options...
Oblis Posted September 13, 2012 Author Share Posted September 13, 2012 (edited) This is general for all package checks: Edited September 26, 2012 by Oblis Link to comment Share on other sites More sharing options...
Oblis Posted September 23, 2012 Author Share Posted September 23, 2012 (edited) Hello again,I noticed a small problem in my mod. If the same script is running on 2 or more npcs, they build a common array right?The result of this is that all the npcs from other cells (where the script is running) come into the cell where the array gathered information about the chairs. Is there any way to fix this?I mean if there is a way to make each npc gather info for himself, whithout creating a seperate script for each one? I used GetInSameCell and GetDistance but it is useless since they run the same script and the array is common. Thanks in advanceOblis Edited September 23, 2012 by Oblis Link to comment Share on other sites More sharing options...
WarRatsG Posted September 24, 2012 Share Posted September 24, 2012 Is this script a quest script? Or is it an object script attached to each NPC? Any extra details will help Link to comment Share on other sites More sharing options...
Oblis Posted September 24, 2012 Author Share Posted September 24, 2012 (edited) Is this script a quest script? Or is it an object script attached to each NPC? Any extra details will help Its an object script running on NPC.Every NPC that I want to do these things, runs the the script.The script is common to every npc. Edited September 26, 2012 by Oblis Link to comment Share on other sites More sharing options...
Oblis Posted September 25, 2012 Author Share Posted September 25, 2012 (edited) Actually I created a seperate PACKAGE script for each npc the way you teached me.But I still i have to call those scripts from the main script (the one running on the npc) for each hour.This seems to work fine but I have sctipt size limit. Maybe the following script can be more dynamic so the script size to be shorter?Of course the script also includes the creation and managemets for classes and birthsigns. Edited September 26, 2012 by Oblis Link to comment Share on other sites More sharing options...
WarRatsG Posted September 25, 2012 Share Posted September 25, 2012 (edited) There is only a common array if the two objects use the exact same script - not just the same FormID, but the same instance. Object scripts are independent of each other, so the array variables will be separate. That said, I dont see an array variable anywhere in your object script. I can only assume that it is contained within the User-defined functions, which are also separate. Even calling ar_Null when you are finished with an array should make it okay. It would help to see those UD functions too ;) Your script is so big because it repeats the same actions several times. First though there are some errors that you need to fix: - NPCs can have a negative number of items. This is usually when an item is set to respawn, but your script removes 9999 items at a time. This does not clear their inventory; it gives them thousands of respawnable items.- GetName returns a string, not a ref. Therefore, "ref Name" should be "string_var Name"- Call requires at least one arguement, in my experience at least. You can just pass an empty string like so: Call Script "%e"- Timezones adjacent to the current one are cleared, but if the player uses wait to skip a few hours then they may be not be turned off.- quote marks usually denote a string. Therefore, when your script asks {If NPC == "NPC01"}, it may not return true, although I cant really be sure. Regardless, you would he better off removing the quote marks. As for shortening, you could easily shorten the package bit. Instead of running separate yet identical blocks, create a block that changes timezones. If any change is detected, it can run the package selection block. That should be enough for now. When that is all done, please repost the edited script, but encase it in spoiler tags please. It's murder trying to scroll through a page on my phone :P Edited September 25, 2012 by WarRatsG Link to comment Share on other sites More sharing options...
WarRatsG Posted September 25, 2012 Share Posted September 25, 2012 (edited) Good news mate, after 30 minutes with your script and the CSE I managed to cut down your script by over 500 lines and made it actually readable :P. It started at 768 lines, but I reduced it to 226, but after that I sanitized it and separated out the blocks to make it easier to read. It's now at 375 lines, but those 150 carriage returns do not add anything to the script size. It's the amount of data in the script that is limited, not the number of lines. They are a personal preference though, so don't think that you have to include quite so many. However, you should always indent your scripts in future. Any time you make an If statement, hit TAB. scriptname NPCScript ;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ String_var Name ref NPC Ref NPCBaseObject float Time short NPCConfidence short NPCEnergy short NPCResponsibility short NPCClass short NPCBirthSign short Dice_Behaviour short Dice_Class short Dice_BirthSign short DoOnceTrigger1 Short ItemCount Short DoOnceTimeZone ;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ begin GameMode Set NPC to GetSelf set Name to NPC.GetName set Time to GameHour player.AddSpell NPCConfortsCushion ;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ if Dice_Behaviour == 0 Set NPCConfidence to Rand 30 100 Set NPCEnergy to Rand 30 100 Set NPCResponsibility to Rand 30 100 NPC.SetActorValue Confidence NPCConfidence NPC.SetActorValue Energy NPCEnergy NPC.SetActorValue Responsibility NPCResponsibility set Dice_Behaviour to 1 endif ;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ IF Dice_Birthsign == 0 Set NPCBirthSign to Rand 1 14 Set Dice_Birthsign to 1 If NPC.GetItemCount NPCBirthApprentice > 0 Set ItemCount to NPC.GetItemCount NPCBirthApprentice > 0 NPC.RemoveItem NPCBirthApprentice ItemCount ElseIf NPC.GetItemCount NPCBirthAtronach > 0 Set ItemCount to NPC.GetItemCount NPCBirthAtronach > 0 NPC.RemoveItem NPCBirthAtronach ItemCount ElseIf NPC.GetItemCount NPCBirthLady > 0 Set ItemCount to NPC.GetItemCount NPCBirthLady > 0 NPC.RemoveItem NPCBirthLady ItemCount ElseIf NPC.GetItemCount NPCBirthLord > 0 Set ItemCount to NPC.GetItemCount NPCBirthLord > 0 NPC.RemoveItem NPCBirthLord ItemCount ElseIf NPC.GetItemCount NPCBirthLover > 0 Set ItemCount to NPC.GetItemCount NPCBirthLover > 0 NPC.RemoveItem NPCBirthLover ItemCount ElseIf NPC.GetItemCount NPCBirthMage > 0 Set ItemCount to NPC.GetItemCount NPCBirthMage > 0 NPC.RemoveItem NPCBirthMage ItemCount ElseIf NPC.GetItemCount NPCBirthRitual > 0 Set ItemCount to NPC.GetItemCount NPCBirthRitual > 0 NPC.RemoveItem NPCBirthRitual ItemCount ElseIf NPC.GetItemCount NPCBirthSerpent > 0 Set ItemCount to NPC.GetItemCount NPCBirthSerpent > 0 NPC.RemoveItem NPCBirthSerpent ItemCount ElseIf NPC.GetItemCount NPCBirthShadow > 0 Set ItemCount to NPC.GetItemCount NPCBirthShadow > 0 NPC.RemoveItem NPCBirthShadow ItemCount ElseIf NPC.GetItemCount NPCBirthSteed > 0 Set ItemCount to NPC.GetItemCount NPCBirthSteed > 0 NPC.RemoveItem NPCBirthSteed ItemCount ElseIf NPC.GetItemCount NPCBirthThief > 0 Set ItemCount to NPC.GetItemCount NPCBirthThief > 0 NPC.RemoveItem NPCBirthThief ItemCount ElseIf NPC.GetItemCount NPCBirthTower > 0 Set ItemCount to NPC.GetItemCount NPCBirthTower > 0 NPC.RemoveItem NPCBirthTower ItemCount ElseIf NPC.GetItemCount NPCBirthWarrior > 0 Set ItemCount to NPC.GetItemCount NPCBirthWarrior > 0 NPC.RemoveItem NPCBirthWarrior ItemCount ElseIf NPC.GetItemCount NPCBirthMage > 0 Set ItemCount to NPC.GetItemCount NPCBirthMage > 0 NPC.RemoveItem NPCBirthMage ItemCount Endif If NPCBirthsign == 1 NPC.AddSpell BSApprentice NPC.AddItem NPCBirthApprentice 1 ElseIf NPCBirthsign == 2 NPC.AddSpell BSAtronach NPC.AddItem NPCBirthAtronach 1 ElseIf NPCBirthsign == 3 NPC.AddSpell BSLadyBlessing NPC.AddItem NPCBirthLady 1 ElseIf NPCBirthsign == 4 NPC.AddSpell BSLordBloodoftheNorth NPC.AddSpell BSLordTrollkin NPC.AddItem NPCBirthLord 1 ElseIf NPCBirthsign == 5 NPC.AddSpell BSLoverKiss NPC.AddItem NPCBirthLover 1 ElseIf NPCBirthsign == 6 NPC.AddSpell BSMage NPC.AddItem NPCBirthMage 1 ElseIf NPCBirthsign == 7 NPC.AddSpell BSRitualBlessedWord NPC.AddSpell BSRitualMaraGift NPC.AddItem NPCBirthRitual 1 ElseIf NPCBirthsign == 8 NPC.AddSpell BSSerpent NPC.AddItem NPCBirthSerpent 1 ElseIf NPCBirthsign == 9 NPC.AddSpell BSShadowMoonshadow NPC.AddItem NPCBirthShadow 1 ElseIf NPCBirthsign == 10 NPC.AddSpell BSSteed NPC.AddItem NPCBirthSteed 1 ElseIf NPCBirthsign == 11 NPC.AddSpell BSThief NPC.AddItem NPCBirthThief 1 ElseIf NPCBirthsign == 12 NPC.AddSpell BSTower NPC.AddSpell BSTowerWarden NPC.AddItem NPCBirthTower 1 ElseIf NPCBirthsign == 13 NPC.AddSpell BSWarrior NPC.AddItem NPCBirthWarrior 1 ElseIf NPCBirthsign == 14 Set Dice_Birthsign to 0 Endif Endif ;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ if Dice_Class == 0 Set NPCClass to Rand 1 15 set Dice_Class to 1 If NPCClass == 1 NPC.SetClass Warrior elseIf NPCClass == 2 NPC.SetClass Warlock elseIf NPCClass == 3 NPC.SetClass Thief elseIf NPCClass == 4 NPC.SetClass Sorcerer elseIf NPCClass == 5 NPC.SetClass Rogue elseIf NPCClass == 6 NPC.SetClass Priest elseIf NPCClass == 7 NPC.SetClass Nightblade elseIf NPCClass == 8 NPC.SetClass Mage elseIf NPCClass == 9 NPC.SetClass Knight elseIf NPCClass == 10 NPC.SetClass Acrobat elseIf NPCClass == 11 NPC.SetClass Assassin elseIf NPCClass == 12 NPC.SetClass Barbarian elseIf NPCClass == 13 NPC.SetClass Bard elseIf NPCClass == 14 NPC.SetClass Monk elseIf NPCClass == 15 set Dice_Class to 0 endif Call NPCScriptClass ENDIF ;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ IF Time > DoOnceTimeZone * 2 Set DoOnceTimeZone to ((Time + 2) / 2) If (NPC == NPC01ARef) || (NPC == NPC01BRef) || (NPC == NPC01CRef) Call NPC01ScriptPackages elseif (NPC == NPC02ARef) || (NPC == NPC02BRef) || (NPC == NPC02CRef) Call NPC02ScriptPackages elseif (NPC == NPC03ARef) || (NPC == NPC03BRef) || (NPC == NPC03CRef) Call NPC03ScriptPackages elseif (NPC == NPC04ARef) || (NPC == NPC04BRef) || (NPC == NPC04CRef) Call NPC04ScriptPackages elseif (NPC == NPC05ARef) || (NPC == NPC05BRef) || (NPC == NPC05CRef) Call NPC05ScriptPackages elseif (NPC == NPC06ARef) || (NPC == NPC06BRef) || (NPC == NPC06CRef) Call NPC06ScriptPackages elseif (NPC == NPC07ARef) || (NPC == NPC07BRef) || (NPC == NPC07CRef) Call NPC07ScriptPackages elseif (NPC == NPC08ARef) || (NPC == NPC08BRef) || (NPC == NPC08CRef) Call NPC08ScriptPackages elseif (NPC == NPC09ARef) || (NPC == NPC09BRef) || (NPC == NPC09CRef) Call NPC09ScriptPackages elseif (NPC == NPC10ARef) || (NPC == NPC10BRef) || (NPC == NPC10CRef) Call NPC10ScriptPackages elseif (NPC == NPC11ARef) || (NPC == NPC11BRef) || (NPC == NPC11CRef) Call NPC11ScriptPackages elseif (NPC == NPC12ARef) || (NPC == NPC12BRef) || (NPC == NPC12CRef) Call NPC12ScriptPackages elseif (NPC == NPC13ARef) || (NPC == NPC13BRef) || (NPC == NPC13CRef) Call NPC13ScriptPackages elseif (NPC == NPC14ARef) || (NPC == NPC14BRef) || (NPC == NPC14CRef) Call NPC14ScriptPackages elseif (NPC == NPC15ARef) || (NPC == NPC15BRef) || (NPC == NPC15CRef) Call NPC15ScriptPackages elseif (NPC == NPC16ARef) || (NPC == NPC16BRef) || (NPC == NPC16CRef) Call NPC16ScriptPackages elseif (NPC == NPC17ARef) || (NPC == NPC17BRef) || (NPC == NPC17CRef) Call NPC17ScriptPackages elseif (NPC == NPC18ARef) || (NPC == NPC18BRef) || (NPC == NPC18CRef) Call NPC18ScriptPackages elseif (NPC == NPC19ARef) || (NPC == NPC19BRef) || (NPC == NPC19CRef) Call NPC19ScriptPackages elseif (NPC == NPC20ARef) || (NPC == NPC20BRef) || (NPC == NPC20CRef) Call NPC20ScriptPackages endif ENDIF End Here is a specific list of what I've done: - Merged several If blocks using ElseIfs- Replaced the various DoOnceTimeZone flags with one flag. This is evaluated against the time using simple maths.- Removed quotation marks around the variables.- Set the birthsign section to properly clear the inventory of any items that you listed.- Conditionalised the entirety of each section under {If Dice_<section> == 0}- Made "Name" a string variable However, you may still need to add the argument on the Call commands, if they don't already work for you (CSE tells me off about it). I did not do them myself because I haven't seen the User Defined scripts. Edited September 25, 2012 by WarRatsG Link to comment Share on other sites More sharing options...
Oblis Posted September 26, 2012 Author Share Posted September 26, 2012 (edited) Thats why I am an amatur and you a master!Thanks a lot Here is the script I call from the above scriptThis is only for NPC01 Even if I created a seperate script for each npc with its own array, the stuck all the sittable into a common array.(they all npcs load the same chairs and etc)The result is that every npc come to the place the NPC01 is.Maybe because in all scripts the variable CurrentRef has the same name? (I think this is a local variable eh?)This is the script i made for NPC01 and is the same for every npc. (The variable names change only). For example where you see NPC01 it will be NPC02 to the 2nd, NPC03 to the 3rd etc to NPC20. ScriptName NPC01ScriptPackages short DoOnceTrigger5short DoOnceTrigger6short DoOnceTrigger7 Ref NPCRef Name Short Dice_Package Ref CurrentRefArray_var LocationDataArray_var NPC01_ChairsRef NPC01_ChosenChairRef NPC01_ChosenChairshort NPC01_ChairSelectionshort NPC01_ChairsLast short DancingTriggershort LuteTriggershort DistanceFromNPC;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Begin Function { };------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Set NPC to GetSelf Set Name to NPC.GetName If DoOnceTrigger5 == 0If Eval ((ar_Size NPC01_Chairs) == -1)Let NPC01_Chairs := ar_Construct ArrayendifLet CurrentRef := GetFirstRef 32 Label 100 If (CurrentRef) If (CurrentRef.NameIncludes "Chair") || (CurrentRef.NameIncludes "Stool") || (CurrentRef.NameIncludes "Bench") || (CurrentRef.NameIncludes "Cushion")ar_Append NPC01_Chairs CurrentRefPrintToConsole "%z: %n added to array" Name CurrentRefendifLet CurrentRef := GetNextRefGoTo 100 endifLet NPC01_ChairsLast := ar_Last NPC01_Chairsset NPC01_ChairSelection to RAND 0 NPC01_ChairsLastset DoOnceTrigger5 to 1endif;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------;Package Generator;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------If DoOnceTrigger6 == 0set Dice_Package to RAND 1 10set DoOnceTrigger6 to 1 endif;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------If DoOnceTrigger7 == 0 NPC.RemoveItem NPCDrinkingObject 9999NPC.RemoveItem NPCReadingObject 9999NPC.RemoveItem NPCAlchemyObject 9999NPC.RemoveItem NPCDancingObject1 9999NPC.RemoveItem NPCDancingObject2 9999NPC.RemoveItem NPCDancingObject3 9999NPC.RemoveItem NPCDancingObject3 9999NPC.RemoveItem 0miscUdeUluteU01 9999 Let NPC01_ChosenChair := NPC01_Chairs[NPC01_ChairSelection] If Dice_Package == 1Let LocationData := GetPackageLocationData NPCDrinkingNPC01CurrentLocationLet LocationData["Object"] := NPC01_ChosenChairSetPackageLocationData NPCDrinkingNPC01CurrentLocation LocationDataNPC.additem NPCDrinkingObject 1NPC.AddScriptPackage NPCDrinkingNPC01CurrentLocationEndifIf Dice_Package == 2Let LocationData := GetPackageLocationData NPCReadingNPC01CurrentLocationLet LocationData["Object"] := NPC01_ChosenChairSetPackageLocationData NPCReadingNPC01CurrentLocation LocationDataNPC.additem NPCReadingObject 1NPC.AddScriptPackage NPCReadingNPC01CurrentLocationEndifIf Dice_Package == 3Let LocationData := GetPackageLocationData NPCAlchemyNPC01CurrentLocationLet LocationData["Object"] := NPC01_ChosenChairSetPackageLocationData NPCAlchemyNPC01CurrentLocation LocationDataNPC.additem NPCAlchemyObject 1NPC.AddScriptPackage NPCAlchemyNPC01CurrentLocationEndifIf Dice_Package == 7Let LocationData := GetPackageLocationData NPCSmokingNPC01CurrentLocationLet LocationData["Object"] := NPC01_ChosenChairSetPackageLocationData NPCSmokingNPC01CurrentLocation LocationDataNPC.additem 0apparatusUaUspipeU01 1NPC.AddScriptPackage NPCSmokingNPC01CurrentLocationEndif If Dice_Package == 4NPC.additem NPCEatingObject 1NPC.AddScriptPackage NPCEatingCurrentLocationEndif If Dice_Package == 5NPC.AddScriptPackage NPCSleepingCurrentLocationEndif If Dice_Package == 6NPC.AddScriptPackage NPCWanderingCurrentLocationEndif If Dice_Package == 8set LuteTrigger to RAND 1 4if LuteTrigger == 1NPC.AddScriptPackage NPCPlayingLute01PartnerCurrentLocationEndifif LuteTrigger == 2NPC.AddScriptPackage NPCPlayingLute02PartnerCurrentLocationEndifif LuteTrigger == 3NPC.AddScriptPackage NPCPlayingLute03PartnerCurrentLocationEndifEndif If Dice_Package == 9set DancingTrigger to RAND 1 4if DancingTrigger == 1NPC.AddScriptPackage NPCDancing01PartnerCurrentLocationEndifif DancingTrigger == 2NPC.AddScriptPackage NPCDancing02PartnerCurrentLocationEndifif DancingTrigger == 3NPC.AddScriptPackage NPCDancing03PartnerCurrentLocationEndifEndif Let NPC01_Chairs := ar_Nullset DoOnceTrigger7 to 1Endif END Edited September 27, 2012 by Oblis Link to comment Share on other sites More sharing options...
Recommended Posts