Scripting - The Event system i inventing
Dear Readers!
This blog post about modder stuff and scripting purly for mod makers and others that intrested making scripts.
This episode i going write down one of my uniqe problems i need solve with scripting, my solution that in theory working, and curently in works do devlop.
So be preapre your cop of tea its take some time and brain power to follow trought.
----------------------------------
The Problem:
----------------------------------
SLOS going to be very modular. On the way that i canot predict waht parts are in use and what not.
The mod do lot of functions that need to interact each other even some cases scripts that run on diferent parts of mod not knowing other existence but need to interact each other.
This canot be done easy becuse how papyrus made.
To be exact here is a example: if a captured npc slave dies its need to be removed from slave storage. But need to be removed from the owener to.
Problem is new captured slave script no way to know what type of script going to own the slave so no direct route to tell the script : hey this slave of yours got killed remove it from your table of slaves ASAP!
This just one example and many more possible, like if player clear a slaver base its need have lot of consiquences.
I dont know yet how many event going to exist that need to be proccesed and varius scripts need to take action on the event.
The game in built script event system not cover all the possible cases i need to procces.
Add to this i not wish to use if possible the excelent SKSE functions for a simple reason: Compatiblilty backward and foward.
in general my aproach to modmaking in skyrim is this: if the problem can be solved witout using scripts do that way, if need use scripts use in game base scripts, if not possible that way look for skse and other ways,
----------------------------------
The Solution:
----------------------------------
My solution to this problem invent a event control system of my own.
The idea come from Creation kit wiki. here is a link to revelant article:
Creation kit wiki link: implementing linked lists
This system possible becuse its possible to use a script to reperesent a object in game, and a script can be point another script in the game.
in other words i maje a script that extends a reference alias, i name this script this: "NSReferenceAliasChainScript"
This scripts extends a reference alias so i need a quest and a reference alias and this reference alias need to be contain this script to this script to anything.
call this reference alias: RefA
Let say i make a copy of this and name it: RefB
thrs script "NSReferenceAliasChainScript" contain a property:
QuoteNSReferenceAliasChainScript Property ChainNext Auto
as you can see the property contain the same type of script object that the script it self!
this means if i add a new script to the quest that contain this aliases i can do this thing
QuoteScriptname QuestSampleScript extends Quest
ReferenceAlias Property RefA_Alias auto ;filled with refA
ReferenceAlias Property RefB_Alias auto ;filled with refB
Function LinkupExample()
NSReferenceAliasChainScript linkA = ( refA_Alias as NSReferenceAliasChainScript )
NSReferenceAliasChainScript linkB = ( refB_Alias as NSReferenceAliasChainScript )
LinkA.ChainNext = refB
EndFunction
what this one does makes refA to point RefB trought the property ChainNext.
upon extending this i can make a long chain that contain same elements. i not need to know in the start how many element going to be added to the chain.
this may looks like to you as a Array that changes its size as needed yes can be used for this.
My first problem to make a event handler system i need a body that recives the event.
as i dont know what type of modules going to be used as my mod installed i dont know what type of events going to happen, or how many of them.
For this porpuse i going to use this "chaining linking" techinqe to store the possible type of events.
here comes the extension future to play. i can extend my own script with a new one.
the new script lets call it "EventNameScript" going to extend the "NSReferenceAliasChainScript".
This one solo porpuse to store a string that indentifes the event that this object resposible for!
Script that reports the event need send a event name, so we know what thye of event happened. this string tested aginst the string stored on the "EventNameScript"
Then if matching we know we found the event node that responsible for proccesing this type of event. now we need somehow inform the event proccesing scripts about the event.
first somehow need make them listen the possiblity of event well this done by the event procceser subscribing for the event.
Event proccesing scripts expected to atached to quests, and multiple proccesing script can be waiting same event to happen, i canot predict how many going to wait same event.
For this reason i need make a sub chain for evry event and evry event processer need to be subbscriped/added to this sub chain.
This allow the event proccesing quest to be subbed multiple event node as some may capble proccesing multiple type of event.
Okay let see how is lok my "EventNameScript" this point of time:
Quote
Script EventNameScript extends NSReferenceAliasChainScript
String Property EventTypeName Auto
SLOSEventChainScript Property EventSubChain auto
bool Function EventProcess( String akEventName ) ;called to locate valid event node that going to procces the event
EventNameScript Pointer = Self
while pointer.EventTypeName == akEventName ;we go foward the event chain until we find the valid node
pointer = pointer.ChainNext
if pointer == none ;end of chain stop trap
return(false)
endif
EndWhile
Pointer.EventFired()
Return( True )
EndFunction
bool Function EventFired( ) ;this one called to procces the event
SLOSEventChainScript Pointer = EventSubChain
while Pointer != none
Pointer = Pointer.ChainNext
endif
EndFunction
This one alone not going to work well but for start is okay.
Function EventProcess basicly run trought all the event nodes until the valid one found, then all the sub nodes get tiggered.
this point i needed find a way to inform the subscriber quests, AND its part important give them the event data.
This part is tricky.
Event data need to be stored on a reference alias. This reference alias exist on the event sender quest.
This reference alias added to the call of "EventProcess" Function.
The reference alias used becuse this one can be carry a script that store all the event information we need. Basicly any information can be stored and delivered by this way.
Added bonus i not forced to use same type of reference alias extension script to all type of events. Reason for this is simple the fact the reference alias that cary the script not need to do anything other than exist. the information extraction done by the proccesing script that going to know what type of script added to the reference alias so can extract the required infromation.
Now i owercome the transfer infromation problem final pice of puzzle inform the event proccesing script work to do.
this can be done multiple ways, most easy probably adding another extension to the script named: "EventNameScript"
the 3th layer of the script used to inform the event proccesing script need do somw work.
Reason for this simple: evry event proccesing script added a quest, sad quest and script vary event processors to event proccesors.
simplest way to tigger a part of a script in the quest is to call them directly.
other easy way change the quest stage and assigne a function to stage that tigger the event proccesing function of the quest.
with using 3th leyer i have another problem in hand: need to tigger the 3th leyer script to inform the quest job need done.
Lucky for as the Script Events fowarded from the base item to the last extension of script.
This bead and good, let say calling onupdate in a parent script effect onupdate event fire the scriptthat extend on same script.
Excatly what we looking for here! Changin "EventNameScript" Function "EventFired" While section to call for a single update with very sort peroid of time tigger a extension script that watches on update event.
Problem is we need store the event data in the "SLOSEventChainScript" references. and possible multiple event fires in the same type in sort succesion.
well... this is the same problem before: we dont know how many reference alias coming to our way, what going to contain and how long going to stay.
so why not use agin the chains? (third time of the charm!
)
adding a chain evry event proccesing subscirption point allow evry event procesing unit take their own time to procces the data stored here.after data used up they need remove the used data storage from the chain.
its complicated? yes
its crazy... totaly. XD
its works?
i have no idea in theory yes. I finished the testing of the NSReferenceAliasChainScript and seems works fine.
now i starting make the secund script i named here : "EventNameScript"
after this things work out comming the third one. then i need all of this implemented to SLOS.
plus planning this system or parts of it made avible for modders with open premissions as my commitment the Skyrim Mod maker and LL community.
2 Comments
Recommended Comments