Jump to content

Make Actor Sit at random chair and read


Oblis

Recommended Posts

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

  • Replies 50
  • Created
  • Last Reply

Top Posters In This Topic

  • 2 weeks later...

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 advance

Oblis

Edited by Oblis
Link to comment
Share on other sites

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 by Oblis
Link to comment
Share on other sites

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 by Oblis
Link to comment
Share on other sites

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 by WarRatsG
Link to comment
Share on other sites

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 by WarRatsG
Link to comment
Share on other sites

Thats why I am an amatur and you a master!

Thanks a lot

 

Here is the script I call from the above script

This 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 DoOnceTrigger5

short DoOnceTrigger6

short DoOnceTrigger7

 

Ref NPC

Ref Name

 

Short Dice_Package

 

Ref CurrentRef

Array_var LocationData

Array_var NPC01_Chairs

Ref NPC01_ChosenChair

Ref NPC01_ChosenChair

short NPC01_ChairSelection

short NPC01_ChairsLast

 

short DancingTrigger

short LuteTrigger

short DistanceFromNPC

;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Begin Function { }

;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Set NPC to GetSelf

Set Name to NPC.GetName

 

If DoOnceTrigger5 == 0

If Eval ((ar_Size NPC01_Chairs) == -1)

Let NPC01_Chairs := ar_Construct Array

endif

Let CurrentRef := GetFirstRef 32

Label 100

If (CurrentRef)

If (CurrentRef.NameIncludes "Chair") || (CurrentRef.NameIncludes "Stool") || (CurrentRef.NameIncludes "Bench") || (CurrentRef.NameIncludes "Cushion")

ar_Append NPC01_Chairs CurrentRef

PrintToConsole "%z: %n added to array" Name CurrentRef

endif

Let CurrentRef := GetNextRef

GoTo 100

endif

Let NPC01_ChairsLast := ar_Last NPC01_Chairs

set NPC01_ChairSelection to RAND 0 NPC01_ChairsLast

set DoOnceTrigger5 to 1

endif

;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

;Package Generator

;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

If DoOnceTrigger6 == 0

set Dice_Package to RAND 1 10

set DoOnceTrigger6 to 1

endif

;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

If DoOnceTrigger7 == 0

 

NPC.RemoveItem NPCDrinkingObject 9999

NPC.RemoveItem NPCReadingObject 9999

NPC.RemoveItem NPCAlchemyObject 9999

NPC.RemoveItem NPCDancingObject1 9999

NPC.RemoveItem NPCDancingObject2 9999

NPC.RemoveItem NPCDancingObject3 9999

NPC.RemoveItem NPCDancingObject3 9999

NPC.RemoveItem 0miscUdeUluteU01 9999

 

Let NPC01_ChosenChair := NPC01_Chairs[NPC01_ChairSelection]

 

If Dice_Package == 1

Let LocationData := GetPackageLocationData NPCDrinkingNPC01CurrentLocation

Let LocationData["Object"] := NPC01_ChosenChair

SetPackageLocationData NPCDrinkingNPC01CurrentLocation LocationData

NPC.additem NPCDrinkingObject 1

NPC.AddScriptPackage NPCDrinkingNPC01CurrentLocation

Endif

If Dice_Package == 2

Let LocationData := GetPackageLocationData NPCReadingNPC01CurrentLocation

Let LocationData["Object"] := NPC01_ChosenChair

SetPackageLocationData NPCReadingNPC01CurrentLocation LocationData

NPC.additem NPCReadingObject 1

NPC.AddScriptPackage NPCReadingNPC01CurrentLocation

Endif

If Dice_Package == 3

Let LocationData := GetPackageLocationData NPCAlchemyNPC01CurrentLocation

Let LocationData["Object"] := NPC01_ChosenChair

SetPackageLocationData NPCAlchemyNPC01CurrentLocation LocationData

NPC.additem NPCAlchemyObject 1

NPC.AddScriptPackage NPCAlchemyNPC01CurrentLocation

Endif

If Dice_Package == 7

Let LocationData := GetPackageLocationData NPCSmokingNPC01CurrentLocation

Let LocationData["Object"] := NPC01_ChosenChair

SetPackageLocationData NPCSmokingNPC01CurrentLocation LocationData

NPC.additem 0apparatusUaUspipeU01 1

NPC.AddScriptPackage NPCSmokingNPC01CurrentLocation

Endif

 

If Dice_Package == 4

NPC.additem NPCEatingObject 1

NPC.AddScriptPackage NPCEatingCurrentLocation

Endif

 

If Dice_Package == 5

NPC.AddScriptPackage NPCSleepingCurrentLocation

Endif

 

If Dice_Package == 6

NPC.AddScriptPackage NPCWanderingCurrentLocation

Endif

 

If Dice_Package == 8

set LuteTrigger to RAND 1 4

if LuteTrigger == 1

NPC.AddScriptPackage NPCPlayingLute01PartnerCurrentLocation

Endif

if LuteTrigger == 2

NPC.AddScriptPackage NPCPlayingLute02PartnerCurrentLocation

Endif

if LuteTrigger == 3

NPC.AddScriptPackage NPCPlayingLute03PartnerCurrentLocation

Endif

Endif

 

If Dice_Package == 9

set DancingTrigger to RAND 1 4

if DancingTrigger == 1

NPC.AddScriptPackage NPCDancing01PartnerCurrentLocation

Endif

if DancingTrigger == 2

NPC.AddScriptPackage NPCDancing02PartnerCurrentLocation

Endif

if DancingTrigger == 3

NPC.AddScriptPackage NPCDancing03PartnerCurrentLocation

Endif

Endif

 

Let NPC01_Chairs := ar_Null

set DoOnceTrigger7 to 1

Endif

 

END

 

Edited by Oblis
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...