[Papyrus]How to get several instances of the same script run

Post » Wed Jun 20, 2012 12:21 am

Hi there,

another tricky question: Is there any way to get several instances of the same script running without attaching the script to an item and spawning it?

The reason I am asking is: I am still laying out plans on creating an extension for the AI I'd describe as a "more sophisticated simulation of social interaction". Part of it consists of breaking up relationships from being a bidirectional link into two unidirectional links, making them more dynamic (possible to add at runtime as player meets NPCs or two NPCs meet each other) and add more funcionality to than just determine a state of attitude two persons have towards each other.

Since I neither can add relationships on runtime nor add scripts to them I'd like to use a relationship script that does all the work. Relationships then would be stored in an array inside a script attached to actors. Obvioulsy each relationship would need to be an instance of it's own of the script.
User avatar
Rhysa Hughes
 
Posts: 3438
Joined: Thu Nov 23, 2006 3:00 pm

Post » Wed Jun 20, 2012 1:35 am

No? Scripts are separate Files. Without attaching it to a FORM, the Engine would not load it.
User avatar
Sarah Edmunds
 
Posts: 3461
Joined: Sat Jul 08, 2006 8:03 pm

Post » Wed Jun 20, 2012 7:24 am

Ok I tested several things.

Using a magic effect that has the script attached to it does not work as you cannot have the same effect running multiple times at the same time on the same actor.

So the last resort is to use a token-item. Since I don't want to flood the inventory of an actor with those RelationshipTokens I thought it would be nice to have a cell to place those tokens in that is never accessed by the player and place the RelationshipTokens there.

So I created an empty cell in the CK and placed a XMarker into it. I gave that marker as a property to a testing script attached to a spell. Upon casting the spell (OnEffectStart) five RelationshipTokens are placed at the marker, their refernce is saved in an array and a Initialize function is called that gives a unique ID to the relationship (realized via a simple global counter each new relationship gets an integer as ID). After 20 seconds (using singleUpdate) an echo function on the RelationshipTokens is called that echoes their ID.

This works pretty well so far. I have to test if placing a huge amount of tokens in that empty cell has any impact on performance.
User avatar
Kahli St Dennis
 
Posts: 3517
Joined: Tue Jun 13, 2006 1:57 am

Post » Wed Jun 20, 2012 3:53 pm

Ok I tested several things.

Using a magic effect that has the script attached to it does not work as you cannot have the same effect running multiple times at the same time.

So the last resort is to use a token-item. Since I don't want to flood the inventory of an actor with those RelationshipTokens I thought it would be nice to have a cell to place those tokens in that is never accessed by the player and place the RelationshipTokens there.

So I created an empty cell in the CK and placed a XMarker into it. I gave that marker as a property to a testing script attached to a spell. Upon casting the spell (OnEffectStart) five RelationshipTokens are placed at the marker, their refernce is saved in an array and a Initialize function is called that gives a unique ID to the relationship (realized via a simple global counter each new relationship gets an integer as ID). After 20 seconds (using singleUpdate) an echo function on the RelationshipTokens is called that echoes their ID.

This works pretty well so far. I have to test if placing a huge amount of tokens in that empty cell has any impact on performance.

It shouldn't, so long as the player never goes there.
User avatar
Nicole Coucopoulos
 
Posts: 3484
Joined: Fri Feb 23, 2007 4:09 am

Post » Wed Jun 20, 2012 2:31 pm

It shouldn't, so long as the player never goes there.

And so long i don't loop through all of them doing stuff :P. Still I better should go test it before diving into it deeper.
Anyhow I am somewhat happy this actually works. I would have thought scripts on items/actors would be accessible only so long they are spawned in the world and in the same cell as the player. I also wonder: would I still be able to acces the script if i placed the items inside a container (that thought just crossed my mind)?
User avatar
Anthony Diaz
 
Posts: 3474
Joined: Thu Aug 09, 2007 11:24 pm

Post » Wed Jun 20, 2012 1:30 pm

Got another somewhat related question (related to my problem of making custom relationships):

From http://www.creationkit.com/SetRelationshipRank_-_Actor reference:
Relationship data is NOT stored for Templated Actors, and any scripts that would set relationship data on a Templated Actor will get wiped once your game session is over (which obviously has bad implications for Save/Load).

What does "Templated Actors" refer to?? And also what are non-templated Actors then (for which a change in factionrank would be saved). Also does SetRelationshipRank work on a pair of actors for which no predefined (created in CK) relationship exists?
User avatar
Sunnii Bebiieh
 
Posts: 3454
Joined: Wed Apr 11, 2007 7:57 pm

Post » Wed Jun 20, 2012 2:23 pm

Using a magic effect that has the script attached to it does not work as you cannot have the same effect running multiple times at the same time.

Oww... that mean I need my second rethink in as many days.

So how does the "on fire" thing work, I wonder. Can only one actor can be aflame at any given time? I'm assuming that "on fire" is a magic effect. Diseases too... although maybe only the player actually catches them.

Of course, what I want is to stick a distinct script instance onto several difference NPCs, so I don't have the problem of not having a form to put them on. Maybe that's the difference.
User avatar
naomi
 
Posts: 3400
Joined: Tue Jul 11, 2006 2:58 pm

Post » Wed Jun 20, 2012 3:49 pm

Of course you can have several instances of the same magic effect on different Actors. But if I apply the same magic effect twice (by using the same spell) to the same actor what happens is that the first Magic effect is endet automatically and then the second one get's applied.
User avatar
sally coker
 
Posts: 3349
Joined: Wed Jul 26, 2006 7:51 pm

Post » Wed Jun 20, 2012 2:32 am

well you could make a global array of references to actors to keep track of who has how many stacking effects, but that would limit you to 128 total "victims" at any one time, since arrays are capped at 128.
User avatar
CYCO JO-NATE
 
Posts: 3431
Joined: Fri Sep 21, 2007 12:41 pm


Return to V - Skyrim