Outsource functions to another script

Post » Mon Oct 27, 2014 2:35 am

Hi,
i try to outsource my functions to another script. Lets say there are 2 Actors who have all a different scripts on them, but they are all using the same functions.
So i thought i outsource the functions to another script, but i don't know how to access them. I tried it like this:

Actor 1 - Team "bandits"

Spoiler
Scriptname MS_SpawnTeamBandits extends Actor  MS_SpawnActorsFUNCTIONS    Property    myFunctions    autoActorBase         Property     EncSkeever       autoActor             Property     ThisActor        auto     Hiddenstring            Property     team = "bandits" autoEvent onInit()     myFunctions.spawn(team, ThisActor, EncSkeever, 10)     Debug.Notification ("10 Skeevers spawned at the actor")EndEvent

Actor 2 - Team "falmer"

Spoiler
Scriptname MS_SpawnTeamFalmers extends Actor  MS_SpawnActorsFUNCTIONS    Property    myFunctions    autoActorBase         Property     EncWolf          autoActor             Property     ThisActor        auto     Hiddenstring            Property     team = "falmer"  autoEvent onInit()     myFunctions.spawn(team, ThisActor, EncWolf, 10)     Debug.Notification ("10 Wolfs spawned at the actor")EndEvent


Script which holds the function - the script is attached nowhere, because i don't know where i should put it, i tried to attach it to the player alias, but i can't fill the property of the script as you can see http://www.pasteall.org/pic/show.php?id=78976

Spoiler

Scriptname MS_SpawnActorsFUNCTIONS extends Actor

;========================================
; Functions
;========================================

function spawn (string team, Actor ThisActor_p, ActorBase BASE_p, int amount_p )

bool loop = true
int counter = 1

while loop && BASE_p != None && amount_p > 0

ThisActor_p = self.PlaceActorAtMe (BASE_p, 1)
ChangeTeam (ThisActor_p, team )


if counter == amount_p
loop = false
endif

counter += 1
endwhile
endfunction


Faction Property BanditFaction auto
Faction Property MS_FalmerFaction auto

function ChangeTeam(Actor myActor_p, string team_p)

myActor_p.RemoveFromAllFactions()

if team_p == "falmer"
myActor_p.AddToFaction( MS_FalmerFaction )

elseif team_p == "bandits"
myActor_p.AddToFaction( BanditFaction )

else
Debug.Notification ("Error 1")
endif

myActor_p.setAV("Aggression", self.getAV("Aggression") as int)

endfunction

If i try to fill the script property then i only can pick a cell (http://www.pasteall.org/pic/show.php?id=78976)

I try it now for hours without success. Can someone help me please ?
Thanks in advance for any help!!

User avatar
mishionary
 
Posts: 3414
Joined: Tue Feb 20, 2007 6:19 am

Post » Sun Oct 26, 2014 11:15 pm

Am I right that you instead want the two actors to pull the same functions from another script, besides the scripts attached to them?

If so, that is the beauty of quest scripts because they make doing so really simple.

Create a dummy quest with the sole purpose of holding the quest script and place your functions in there.

To call these functions from the quest script to another script, add the quest property to the script on the actors and cast the quest to the script, and point it to your function.

Scriptname Example extends Actor  Quest property myFunctionHoldingQuest auto Some Event()(myFunctionHoldingQuest as myFunctionHoldingQuestScript).myFunctions()EndEvent
User avatar
Andrew Perry
 
Posts: 3505
Joined: Sat Jul 07, 2007 5:40 am

Post » Mon Oct 27, 2014 10:05 am

Thank you for your answer !
Yes, each actor has one script, and this script has the only purpose to call the function "spawn" from my other script (MS_SpawnActorsFUNCTIONS)

I created a quest and added my script which contains the functions there. Then i filled the properties of that script of course.

I modified the scripts on my actors like this - (Properties are filled)

Spoiler
Scriptname MS_SpawnTeamBandits extends Actor  ActorBase         Property     EncWolf          autoActor             Property     ThisActor        auto     HiddenQuest             Property     myQuest          auto  string     Property     team = "bandits" autoEvent onInit()    (myQuest  as MS_SpawnActorsFUNCTIONS).spawn(team, ThisActor, EncWolf, 10)     Debug.Notification ("10 Wolfs spawned at the actor")EndEvent


But unfortunattely i get the error: cannot cast a quest to a ms_functionsoutsourcetestfunctions, types are incompatible, if i try to compile above script

Do you know what i did wrong?

Edit: I noticed that there is still the property "myfunctions" altough i deleted the propertie already as you can see in the script above. But i can't fill that property.
http://www.pasteall.org/pic/show.php?id=78982
Edit 2: Ok that probably was a bug of the creation kit, i created a new script with the same code and now this propertie dissapeared. but the error is still the same.
It looks like it is not possible to outsource my functions at this way. I think it works only if i extend "Quest" , but i need to extend actor, otherwise i cant call the functions that i need like "placeactoratme".

User avatar
Chris Ellis
 
Posts: 3447
Joined: Thu Jul 26, 2007 10:00 am

Post » Sun Oct 26, 2014 10:34 pm

It will throw an error if the name of the script is not correct. It is one of many ways to pull functions from a quest script.

Lets try the other way.

ms_functionsoutsourcetestfunctions property myQuestScript auto

After doing that you'll have to save the actor script, and close, and open it back up so that you are able to fill the script property.

So I THINK all you have to do is:

myQuestScript.myFunctions()

I've never used that method before. Always the one I suggested above.

User avatar
Smokey
 
Posts: 3378
Joined: Mon May 07, 2007 11:35 pm

Post » Mon Oct 27, 2014 8:20 am

I tried it:

Spoiler
Scriptname MS_OutsourceFunctionsCALL extends Actor  ms_functionsoutsourcetestfunctions property myQuestScript autoActorBase         Property     EncWolf          autoActor                 Property     ThisActor        auto     Hiddenstring     Property     team = "bandits" autoEvent onInit()   myQuestScript.spawn(team, ThisActor, EncWolf, 10)     Debug.Notification ("10 Wolfs spawned at the actor")EndEvent


It compiles, but i can't fill that property as you can see http://www.pasteall.org/pic/show.php?id=78982.
And the functions are not working anymore, no one is spawning at my actor. :/

User avatar
Mistress trades Melissa
 
Posts: 3464
Joined: Mon Jun 19, 2006 9:28 pm


Return to V - Skyrim