Jump to content

Make Actor Sit at random chair and read


Oblis

Recommended Posts

Take a look at Uurwen's AI package, where she *sits* reading -- she has a specific chair, but you could make various packages for different chairs, choosing randomly. She is one of the mages in Cheydinhal Mages Guild.

 

Don't overlook the 'Must Complete' flag, either.

Link to comment
Share on other sites

  • Replies 50
  • Created
  • Last Reply

Top Posters In This Topic

Take a look at Uurwen's AI package, where she *sits* reading -- she has a specific chair, but you could make various packages for different chairs, choosing randomly. She is one of the mages in Cheydinhal Mages Guild.

 

Don't overlook the 'Must Complete' flag, either.

 

Thanks for reply. Yes i could do 100 packages for 100 chairs to cover all the world but still this is not what it must be done.

Because if for example you lead the follower into Bravil house and the chair is on Imperial City, he will start a travel there and may die in the process or lost.

Even if the chair is in the same city, the actor shall travel there and aciidendly disappear.

 

My packages have current location flag which means that the follower will stay and live wherever the player will choose.

For example the player may choose to live in a cave. So the npc shall concider the cave to be his home.

 

The basic idea of the script that manages the packages is almost ready. Unfortunatelly my experience with scripting is low, and i cannot help more with this.

I hope WarRatsG will have the courage to help me finish it.

Link to comment
Share on other sites

I've taken a look at the script over and over, but I can't see any logical error. I can only assume it must be a technical error of some kind.

 

I believe it is one of 2 functions causing the problem.

 

The first, and slightly more likely I think, is the SetLocationData function. The function changes only the location of the AI package- no other settings are changed. Because of this, you may need to set the AI package location to a random chair in the CS, just so that all of the other settings of the package are configured for sitting in a chair. The script will change the exact choice of chair in-game.

I got the feeling that I am supplying the wrong type of arguement to the function, but if that is the case I'm not sure what other kind of arguement it would accept. We'll cross that bridge when we come to it ;)

 

The second is more of a syntax error: Eval is a strange function to me, it only seems to ever be useful when dealing with arrays. It's real use has never actually been explained to me, so I have done a little more research on the function and I think I know a little more about how it works. I've altered that line in the script; if it still doesn't work after trying the 2 things mentioned, then remove the "If Eval ((ar_Size Chairs) == -1)" line entirely, and just make a Do-Once loop around "Let Chairs := ar_Construct Array" instead.

 

Here is the re-edited script:

 

 

 

If Dice_Package == 2

               If Eval ((ar_Size Chairs) == -1)
                       Let Chairs := ar_Construct Array
                       PrintToConsole "Oblis:: Array Intialised"
               endif
        
               Let CurrentRef := GetFirstRef 32        
               Label 100        
               If (CurrentRef)                
                       If CurrentRef.IsPersistent
                               If (CurrentRef.NameIncludes "Chair") || (CurrentRef.NameIncludes "Stool")
                                       ar_Append Chairs CurrentRef
					PrintToConsole "Oblis:: %n added to array" CurrentRef
                               endif
                       endif
                       Let CurrentRef := GetNextRef
                       GoTo 100        
               endif

               Let ChosenChair := Chairs[0]
	  PrintToConsole "Oblis:: ChosenChair == %n" ChosenChair
               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

 

 

 

I have included some console output messages too - all starting with "Oblis:: ". When you test this out, please tell me anything that appears. You can use PageUp and PageDown keys to help you look through the console if you need to.

Edited by WarRatsG
Link to comment
Share on other sites

You are awsome!

This finally worked with some bugs.

 

I used your script at start but they didnt respond.

Then I set a specific chair to the location, and this cause them to sit on a chair and read.

(not at the chair i had set)

 

I have noticed that they always choose the same chair. It is like add and save that chair to be used for ever.

 

Now when a second npc using the same script is at the same room, he gets this specific chair too, while if he is in different place he will choose an other chair.

The result is that the first is sitting while the second is standing and read (probably because the chair is occupied).

 

Edit:

 

I run some tests

I created different scripts for the npcs but they still had the same problem (with both scripts the new and the old).

The 1 of the 2 was stitting and the other was standing.

And sometimes the actor was heading outside (possibly to find the specific chair) dunno

 

Edit

Maybe the problem is that every chair in room has the same name but different ref?

Because in the report I get this:

 

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

 

Maybe it has to define ref name (at least presistent items may have although many of them dont have)

 

Also I want to ask you what it may happen if i remove If CurrentRef.IsPersistent

because many of the furniture are not presistent. It may add non presistent item too?

Edited by Oblis
Link to comment
Share on other sites

Hello again,

As I said above I made too many tests (about 2 hours on this) and I finally managed to make it work for 2 npcs with common script.

With my little knowledge of scripting I made the following additions:

 

First of all created a seperate reading package for each npc.

Now the NPC1 has NPCReadingCurrentLocation while the NPC2 has NPCReading02CurrentLocation

I made that because I thought there in a conflict between the package and the script.

Then I added the following things at script:

 

Let ChosenChair00 := Chairs[0]

Let ChosenChair01 := Chairs[1]

Let ChosenChair02 := Chairs[2]

Let ChosenChair03 := Chairs[3]

 

and created a seperate locationdata for each npc adding his own chair.

If an other npc sits there my npc will read standing.

 

If (NPC.NameIncludes "Njada")

Let LocationData := GetPackageLocationData NPCReadingCurrentLocation

Let LocationData["Object"] := ChosenChair01

SetPackageLocationData NPCReadingCurrentLocation LocationData

 

NPC.AddScriptPackage NPCReadingCurrentLocation

PrintToConsole "1 = %n" ChosenChair01

PrintToConsole "%z is Reading" name

set DoOnceTrigger7 to 1

Endif

 

If (NPC.NameIncludes "Prevylia")

Let LocationData := GetPackageLocationData NPCReading02CurrentLocation

Let LocationData["Object"] := ChosenChair02

SetPackageLocationData NPCReading02CurrentLocation LocationData

 

NPC.AddScriptPackage NPCReading02CurrentLocation

PrintToConsole "2 = %n" ChosenChair02

PrintToConsole "%z is Reading" name

set DoOnceTrigger7 to 1

Endif

 

I want to notice some things:

 

1. Even with the script you created, there is no randomness in the chair an npc will choose. The npc will act if like he had a specific chair in his package. With your script this chair changes acording to the interior he is incide which is cool by my opinion. Maybe you have to think of some random choice on the element the script selects from the array or something like this... dunno.

 

2. This is working only for persistant furniture, which means that if an npc is in a place with no persistant furniture the script will fail. I was thinking if I remove the line you have added about it, if he will select other furniture too? What do you think?

 

3. I noticed that when i load a game, the script is not running (because of the triggers) until the time will pass to activate them. I tried to push the chair selection script outside the package selection lines (to the gamemode) and they keep doing what they supposed to do when i loaded. But i think there will be some problem with Let CurrentRef := GetFirstRef 32 because it will loop all the time. Am I right?

 

Thanks for you patience on my matter.

I hope you will help me more to make it perfect.

Link to comment
Share on other sites

I had already told you I had not created a selection process for the chair because I didnt know if you wanted it to be random or have some kind of specific algorithm. Woth the current script, the package will always point to the first chair that the script scans in the cell, therefore it will be the same one every time.

 

I did create everything you would need for the selection process, be it random or algorithmic. All you need to do is specify what kind of system you want, if any.

 

I dont know how the game would react to having a non persistent reference as the location. Im guessing that so long as the chair remains in memory it should be okay, but if you leave a cell for too long the reference may become invalid. It may cause them to stand and read or may crash the game - I cant say for certain.

 

You should be able to put it in a GameMode block. It will not loop indefinitely, but ref-walking is not something you want to do.every frame. You should either conditionalize the loop or create a timer.

Link to comment
Share on other sites

Well the only thing I can think for make them random is the following:

 

If DoOnceTrigger8 == 0

set ChairSelection00 to RAND 1 20

set ChairSelection01 to RAND 1 20

set ChairSelection02 to RAND 1 20

set ChairSelection03 to RAND 1 20

set DoOnceTrigger8 to 1

endif

 

Let ChosenChair00 := Chairs[ChairSelection00]

Let ChosenChair01 := Chairs[ChairSelection01]

Let ChosenChair02 := Chairs[ChairSelection02]

Let ChosenChair03 := Chairs[ChairSelection03]

 

Sorry my knowledge to arrays had birthday yesterday. It is so little.

 

And what if there are not 20 chairs in the interior? The game may crush.

Maybe I will put something that will give me the last element of the array in number at the place where is 20.

Maybe ar_Last ?!?

Link to comment
Share on other sites

Arrays start at 0, but other than that yes - the range would be "rand 0 (ar_last)".

You may need to be more specific in your chair selection though. It could result in an NPC travelling the entire way through a dungeon to find a chair at the end. Finding the closest chair may be better.

 

And I think trying to access a ref in an array that doesnt exist would crash the game. It would simply return an invalid reference, which would probably result in the NPC standing up to read. At least, hypothetically ;)

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...