Jump to content

Make Actor Sit at random chair and read


Oblis

Recommended Posts

The only time I had any luck getting NPCs to sit and drink (as opposed to their favoured stand and drink) I had a specific chair assigned for the NPC to sit in and then drink (not at my gaming computer so I can't give you the exact specifics). For your purposes this wouldn't help unless your script searched for all available chairs in the NPC's current cell and assigned one of those chairs to the NPC for the drink package (making sure the assigned chair was a persistent reference).

 

WarRatsG will be of much more help than any primitive method I could suggest.

 

For your purposes this wouldn't help unless your script searched for all available chairs in the NPC's current cell and assigned one of those chairs to the NPC for the drink package (making sure the assigned chair was a persistent reference)

 

How this can be done?

Link to comment
Share on other sites

  • Replies 50
  • Created
  • Last Reply

Top Posters In This Topic

For your purposes this wouldn't help unless your script searched for all available chairs in the NPC's current cell and assigned one of those chairs to the NPC for the drink package (making sure the assigned chair was a persistent reference)

 

How this can be done?

 

OBSE would be needed here. You would need to do some Ref-Walking, but it's not too hard to do. I'll write up a script fragment for you if that is the idea that you want.

 

My first idea may still work though. The Reading animation may only involve the upper body, in which case I guess a second animation for sitting NPCs would not be needed. You could try to use the same method I described before, but use the normal Reading animation instead.

Link to comment
Share on other sites

OBSE would be needed here. You would need to do some Ref-Walking, but it's not too hard to do. I'll write up a script fragment for you if that is the idea that you want.

 

My first idea may still work though. The Reading animation may only involve the upper body, in which case I guess a second animation for sitting NPCs would not be needed. You could try to use the same method I described before, but use the normal Reading animation instead.

 

I always use OSBE since most of the mods need this.

Right now I'm using OBSE .20

 

+1

Yeee! I look foward for your script example. I like to get new ideas.

 

I entered the animation menu. Found sitting table and added a child called SitRead. There I added the read animation there and selected upper body. Then I made a test and the animation was the same. Standing and reading. I also searched for sit & read animation but there is not anything there. My knowledge in idle is not very good and I may not do this the right way. Dunno

Edited by Oblis
Link to comment
Share on other sites

There is actually no function that returns whether or not the object is a chair. The only solution I can think of is to check the object's name for keywords, like "chair" and "stool".

 

The following script is just a fragment - incorporate it into your own script however you see fit. Replace anything written inside the arrows (< >) with whatever is requested.

 

 

 

Ref CurrentRef
Ref ChosenChair

Array_var Chairs
Array_var LocationData

Begin GameMode


If eval (ar_Size Chairs == -1)
	Let Chairs := ar_Construct Array
endif


Let CurrentRef := GetFirstRef 32

Label 100

If CurrentRef
	
	If CurrentRef.IsPersistent
		If (CurrentRef.NameIncludes "Chair") || (CurrentRef.NameIncludes "Stool")
			ar_Insert Chairs 0 CurrentRef
		endif
	endif

	Let CurrentRef := GetNextRef
	GoTo 100

endif


;Let ChosenChair := <the chair the NPC will sit in>

Let LocationData := GetPackageLocationData <Package>
Let LocationData["Object"] := ChosenChair
SetPackageLocationData <Package> LocationData

Let Chairs := ar_Null

End

 

 

 

This saves all of the furniture that includes the words "Chair" or "Stool" in the cell to the array "Chairs". I'm not sure how you will select which chair to use, but if you tell me then I will happily code the selection process in. Once a chair is selected, it is substituted into the package.

 

Hopefully this will work for you.

Edited by WarRatsG
Link to comment
Share on other sites

Omg! This script is too advanced for my knowledge!

I m trying to understand it :)

 

Edit:

 

It checks Name or Editor ID?

 

Edit:

Crush. Crush. Cruch.

Normal...

This code is too advanced for me :(

 

Anyway..

 

This is the part of my script that manages the packages

Can you place me your script into mine?

 

;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
;Package Generator
;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
If DoOnceTrigger6 == 0
set Dice_Package to RAND 1 11
set DoOnceTrigger6 to 1
endif

set NPCSitting to NPC.GetSitting

If DoOnceTrigger7 == 0

If Dice_Package == 1
NPC.AddScriptPackage NPCDrinkingCurrentLocation
PrintToConsole "%z is Drinking" name
set DoOnceTrigger7 to 1
endif

If Dice_Package == 2
if SittingTrigger == 0
NPC.AddScriptPackage NPCSittingCurrentLocation
set SittingTrigger to 1
endif
if NPCSitting == 3
NPC.RemoveScriptPackage NPCSittingCurrentLocation
NPC.AddScriptPackage NPCReadingCurrentLocation
PrintToConsole "%z is Reading" name
set SittingTrigger to 0
set DoOnceTrigger7 to 1
endif
endif

If Dice_Package == 3
NPC.AddScriptPackage NPCEatingCurrentLocation
PrintToConsole "%z is Eating" name
set DoOnceTrigger7 to 1
endif

If Dice_Package == 4
NPC.AddScriptPackage NPCSleepingCurrentLocation
PrintToConsole "%z is Sleeping" name
set DoOnceTrigger7 to 1
endif

If Dice_Package == 5
NPC.AddScriptPackage NPCWanderingCurrentLocation
PrintToConsole "%z is Wandering" name
set DoOnceTrigger7 to 1
endif

If Dice_Package == 6
NPC.AddScriptPackage NPCAlchemyCurrentLocation
PrintToConsole "%z is doing potions" name
set DoOnceTrigger7 to 1
endif

If Dice_Package == 7
NPC.AddScriptPackage NPCSmokingCurrentLocation
PrintToConsole "%z is smoking" name
set DoOnceTrigger7 to 1
endif

If Dice_Package == 8
NPC.AddScriptPackage NPCPreachingCurrentLocation
PrintToConsole "%z is preaching" name
set DoOnceTrigger7 to 1
endif

If Dice_Package == 9
NPC.AddScriptPackage NPCSittingCurrentLocation
PrintToConsole "%z is sitting" name
set DoOnceTrigger7 to 1
endif

If Dice_Package == 10
NPC.AddScriptPackage NPCPlayingLuteCurrentLocation
PrintToConsole "%z is playing lute" name
set DoOnceTrigger7 to 1
endif

If Dice_Package == 11
NPC.AddScriptPackage NPCMagePonderCurrentLocation
PrintToConsole "%z is pondering" name
set DoOnceTrigger7 to 1
endif

endif

Edited by Oblis
Link to comment
Share on other sites

I also noticed that in the test area the objects have no ref, Only Odject ID. Maybe this is the reason the script crushes?

It is inpossible to add ref to every object in game.

So I think better it has to check for ID not REF to get the "chair" or "stool" thing...

Eh?

Link to comment
Share on other sites

Omg! This script is too advanced for my knowledge!

I m trying to understand it :)

 

The first three lines (starting with "If eval (ar_Size Chairs == -1)" ) initialize an array, which is a kind of database. It allows me to store as many variables as I want.

 

The next 11 lines (starting with "Let CurrentRef := GetFirstRef 32") do something called Ref-Walking. This is where all references in a cell are scanned one at a time, then I can do whatever I like with the reference until the next one is scanned. In this case, I check if it is persistent and if it contains the keywords - which if it does, I add to the array.

 

The Part I have commented out (;Let ChosenChair := <insert algorithm>") is possibly the part causing the crash. Essentially, I have summed up the result of some kind of algorithm that determines which chair in the cell will be used. Because I don't know what kind of process you want to use, I did not create any process, so in the script itself there is no "Chosen Chair", so the UseItemAt package has a location of 0.

 

The next three lines (Starting with "Let LocationData := GetPackageLocationData <Package>") replace the Package's target chair with the "Chosen Chair".

 

The final line ("Let Chairs := ar_Null") clears the temporary array out so that doesn't become part of the savegame and clog it up.

 

 

Edit:

 

It checks Name or Editor ID?

 

Name

 

Edit:

Crush. Crush. Cruch.

 

The way I see it, that's one of two things. I made a typo with initializing the array for a start, but that has been fixed. Also, it could be because there is no Location for the package, for the reason mentioned above. For now, I will just assign it to the first element of the array.

 

This is the part of my script that manages the packages

Can you place me your script into mine?

 

 

 

;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
;Package Generator
;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
If DoOnceTrigger6 == 0
       set Dice_Package to RAND 1 11
       set DoOnceTrigger6 to 1
endif

set NPCSitting to NPC.GetSitting

If DoOnceTrigger7 == 0

       If Dice_Package == 1
               NPC.AddScriptPackage NPCDrinkingCurrentLocation
               PrintToConsole "%z is Drinking" name
               set DoOnceTrigger7 to 1
       endif

       If Dice_Package == 2

               If eval (ar_Size Chairs == -1)
                       Let Chairs := ar_Construct Array
               endif
        
               Let CurrentRef := GetFirstRef 32        
               Label 100        
               If (CurrentRef)                
                       If CurrentRef.IsPersistent
                               If (CurrentRef.NameIncludes "Chair") || (CurrentRef.NameIncludes "Stool")
                                       ar_Insert Chairs 0 CurrentRef
                               endif
                       endif
                       Let CurrentRef := GetNextRef
                       GoTo 100        
               endif

               Let ChosenChair := Chairs[0]
               Let Chairs := ar_Null

               Let LocationData := GetPackageLocationData NPCReadingCurrentLocation
               Let LocationData["Object"] := ChosenChair
               SetPackageLocationData NPCReadingCurrentLocation LocationData

               NPC.AddScriptPackage NPCReadingCurrentLocation
               PrintToConsole "%z is Reading" name
               set DoOnceTrigger7 to 1
       endif

       If Dice_Package == 3
               NPC.AddScriptPackage NPCEatingCurrentLocation
               PrintToConsole "%z is Eating" name
               set DoOnceTrigger7 to 1
       endif

       If Dice_Package == 4
               NPC.AddScriptPackage NPCSleepingCurrentLocation
               PrintToConsole "%z is Sleeping" name
               set DoOnceTrigger7 to 1
       endif

       If Dice_Package == 5
               NPC.AddScriptPackage NPCWanderingCurrentLocation
               PrintToConsole "%z is Wandering" name
               set DoOnceTrigger7 to 1
       endif

       If Dice_Package == 6
               NPC.AddScriptPackage NPCAlchemyCurrentLocation
               PrintToConsole "%z is doing potions" name
               set DoOnceTrigger7 to 1
       endif

       If Dice_Package == 7
               NPC.AddScriptPackage NPCSmokingCurrentLocation
               PrintToConsole "%z is smoking" name
               set DoOnceTrigger7 to 1
       endif

       If Dice_Package == 8
               NPC.AddScriptPackage NPCPreachingCurrentLocation
               PrintToConsole "%z is preaching" name
               set DoOnceTrigger7 to 1
       endif

       If Dice_Package == 9
               NPC.AddScriptPackage NPCSittingCurrentLocation
               PrintToConsole "%z is sitting" name
               set DoOnceTrigger7 to 1
       endif

       If Dice_Package == 10
               NPC.AddScriptPackage NPCPlayingLuteCurrentLocation
               PrintToConsole "%z is playing lute" name
               set DoOnceTrigger7 to 1
       endif

       If Dice_Package == 11
               NPC.AddScriptPackage NPCMagePonderCurrentLocation
               PrintToConsole "%z is pondering" name
               set DoOnceTrigger7 to 1
       endif

endif

 

 

 

That should work a little better. In future, please indent your scripts so that they are easier to work with :P

Also, I can guarantee that your NPC will almost never Ponder, because when saving the Rand function as an integer it is always rounded down. Since 11 is the maximum value of Rand, you have something like a 1/1000000 chance of ever seeing it.

 

I also noticed that in the test area the objects have no ref, Only Odject ID. Maybe this is the reason the script crushes?

It is inpossible to add ref to every object in game.

So I think better it has to check for ID not REF to get the "chair" or "stool" thing...

Eh?

 

Everything that you can see in game is a reference. Think of it this way - if you see it in the object window of the CS, it is an Object; if you see it in the render window of the CS, it is a reference.

 

Not only that, the script checks if it is a persistent reference.

Edited by WarRatsG
Link to comment
Share on other sites

No every chair in that room is persistent.

MAybe this is causeing problems too?

 

The script gives:

 

http://i208.photobucket.com/albums/bb180/Aramis1979/bb7a341f.png

 

for the line:

 

If eval (ar_Size Chairs == -1)

 

Edit:

 

Just for testing purposes I removed the if that creates problem and the script saved normally.

I run the game and the npc did the reading without sitting on a chair (standing).

So I think this may be nessessary eh?

Edited by Oblis
Link to comment
Share on other sites

Sorry...

It still doesnt work. :(

I mean the script is not giving any problem but the npc still is standing and reading. He doesnt even care to move anywhere (trying to find a chair or something).

I never imagined that it could be so difficult. :(

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...