Jump to content

How to make a script run on all moving Actors?


GrandsonOfSam

Recommended Posts

I am trying to make a script, that would run on every actor that are active around the player, including the player itself. I have read thru the list on GECK wiki, but haven't found a way. Or am I trying something too fancy here? The script itself is a combat script getting values from the actors in realtime and modifying them.

 

Just a small pointer into the right direction would be nice, as I'm completely stuck on this one...

Link to comment
Share on other sites

This will require something a bit fancy. The approach I'd use would be to use a quest script that loops through nearby actors via FOSE's looping and reference walking functions (Label, Goto, GetFirstRef and GetNextRef) and adds a scripted token (an unplayable, therefore invisible, piece of armour) to all actors that don't already have one.

 

This token would use GetContainer to effectively run a script on the actor that it has been added to.

 

Cipscis

Link to comment
Share on other sites

Thank you Cipscis :) I keep forgetting the FOSE functions... I know the thing I'm trying to accomplish is hard to do, otherwise it would have been done already numerous times ;)

 

Just feels weird that there isn't a simple command to rotate a script on all actor references in the area in a loop, as there really should be. Atleast if I was the quest designer :P

 

I'm going to finish the script tomorrow, as I'm a bit too full of GECK at the moment... :D

Link to comment
Share on other sites

Most vanilla scripts are really very simple and refer to specific things because if they needed to do anything more complicated or general, they'd just implement it in the engine. Of course, we don't have that luxury, but because Bethesda didn't need to use the same methods as us they didn't implement many functions that we'd need to implement more complicated features. That's basically why FOSE is so awesome - it lets us do stuff with scripts that Bethesda would have had to hard-code into the engine.

 

Something like this should allow you to iterate through all actors near the player:

ref rCurrentRef

Begin GameMode

set rCurrentRef to GetFirstRef 200 1 0 ; Actors
Label 10
if rCurrentRef
	; Do stuff

	set rCurrentRef to Pencil01 ; Prevent "apple" bug with GetNextRef
	set rCurrentRef to GetNextRef
	Goto 10
endif

End

Cipscis

Link to comment
Share on other sites

I played around with the Label, GoTo, GetFirstRef and GetNextRef last night, but I have to say, your example is much more simple way to implement it :) I like to keep my code and scripts as simple and short as possible, so I need to rewrite some of my script :)

 

A big thank you again :)

 

One more question: I need to keep the script that is implemented with the Token running at the background all the time. Alas, I think this will bring some problems though, as the amount of Actors can be as high as 30 in the worst case... So is it safe to run so many instances of a script, or should I instead use another main script that all the Token scripts call, or check the existence of the token from the main script? Is it even possible to transfer ref variables between scripts?

 

I need the main script to be realtime and run on all actors, as I am using it to change ActorValues dynamically during combat.

Link to comment
Share on other sites

When testing the efficiency of various functions, I commonly find that I have to call a function thousands or tens of thousands of times per frame in order to get any effect on performance, so running 30 instances of a script that manipulates actor values is unlikely to have any effect on performance. While it's always a good idea to make your scripts as efficient as possible, this shouldn't be at the expense of functionality.

 

Surrounding the majority of the code in conditional statements that should keep it from executing when it's not needed should be enough to ensure that the scripts are very efficient, but if you want to go the extra mile you might want to add in an early "return" statement or two, which will prevent the code from being processed at all (if a conditional statement returns false the code it contains will be processed but not executed, with a very very tiny - unnoticeable - effect on performance).

 

Cipscis

Link to comment
Share on other sites

ok, good to know :) I'm currently in process of testing one bigger and 9 small mods I have made, so I script when I find time, but it's almost ready for first tests too though :)

 

The pointers you gave me and your tutorials on FO3 scripts have helped a lot on adapting from other games :)

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...