hi all!
i'm (still) little confused about module processing in module core..
does anyone knows how priority is determined, or what logic is applied when game process module scripts?
i have following situation:
- my add-on module have custom_module_core script which intercepts "module presave" event and "module load" event for creating "story so far" on loading screen (some way similar to sp_module_start):
void main(){ event ev = GetCurrentEvent(); int nEventType = GetEventType(ev); string sDebug;
int nEventHandled = FALSE;
switch(nEventType) { case EVENT_TYPE_MODULE_LOAD: //when we load form save in our module { yad_HandleStorySoFar(); //sets some story plot flags andd calls WR_SetStoryPlot(MY_STORY_PLOT) PrintToLog("-----> MODULE LOAD STORY SO FAR!"); break; } case EVENT_TYPE_MODULE_PRESAVE: //when we prepare to save in our module {
yad_HandleStorySoFar(); //sets some story plot flags and calls WR_SetStoryPlot(MY_STORY_PLOT)
PrintToLog("-----> MODULE PRESAVE STORY SO FAR!"); break; }
} //it seems that we dont need this if we want to avoid strange //behaviors in SP, but be careful! i leave it here cause currently //upper code works.. if (!nEventHandled) { HandleEvent(ev, RESOURCE_SCRIPT_MODULE_CORE); //calls module_core script }}
and this works, BUT ONLY BEFORE "post-coronation" event (if you finished main campaign and play my mod as dlc, it just shows origin story), AND if i am in my mod areas..
now i placed floaty message on every call to this function (for debug), and floaty is showed always when i save game, irrelevant of area where i currently am..
what confuses me is why this works? it should not.. only explanation is that module scripts are both run in same time (sp_module_start and custom_module_core), and depending of module ownership of area where i save game, that module_core script have precedence in order of executing.. anyone have some explanation or better insight of this?
tnx in advance..
Module processing
Débuté par
dr.drummie
, nov. 04 2013 01:55
#1
Posté 04 novembre 2013 - 01:55
#2
Posté 05 novembre 2013 - 07:47
I've played with some logging and local copies of SP..
well, it seems that events are sent to modules by priority, first goes to SP cause we extending SP.. even if event is handled in SP, event is also sent to our module.. i'm not sure if same applies if event handled is set to TRUE in module_core, i guess it's same behavior.. when we extend SP, it's best to avoid passing events to module_core to avoid duplicate processing..
I've changed some scripts to mimic SP behavior and now it works..
some log file output:
Load from save game:
Party camp:
General Loading - Start
General Loading - End
Script -----> SP MODULE LOAD! handle event - pass to sp module start.
Script -----> SP MODULE START LOAD - STORY SO FAR! dont handle event pass it to module core
Script -----> MODULE CORE LOAD! event is defined in module_core, but not handled!
Script -----> SP MODULE LOAD - AFTER HANDLE EVENT! return to sp module and event handled = TRUE
Script -----> YADAM MODULE LOAD - STORY SO FAR! event sent to my module
Script -----> YADAM PRCSCR SCRIPT! area load (any)
Enter Random encounter, interrupted when travelling:
General Area List Swap - Start
General Area List Swap - End
Script -----> YADAM PRCSCR SCRIPT! area load (any)
Enter Lothering:
General Area List Swap - Start
General Area List Swap - End
Script -----> YADAM PRCSCR SCRIPT! area load (any)
Saving Lothering:
Script -----> SP MODULE PRESAVE! handle event - pass to sp module start
Script -----> SP MODULE START PRESAVE - STORY SO FAR! - dont handle event pass it to module core
-------------> module core does not have PRESAVE EVENT!!
Script -----> SP MODULE PRESAVE - AFTER HANDLE EVENT! return to sp module and event handled = TRUE
Script -----> YADAM MODULE PRESAVE - STORY SO FAR! event sent to my module
-------------> does not set story cause were not in my mod areas..
General Saving - Start
General Saving - End
Enter Lake Brtonigla:
General Area List Swap - Start
General Area List Swap - End
Script -----> YADAM PRCSCR SCRIPT! area load (any)
Saving Lake Brtonigla:
Script -----> SP MODULE PRESAVE! handle event - pass to sp module start
Script -----> SP MODULE START PRESAVE - STORY SO FAR! - dont handle event pass it to module core
-------------> module core does not have PRESAVE EVENT!!
Script -----> SP MODULE PRESAVE - AFTER HANDLE EVENT! return to sp module and event handled = TRUE
Script -----> YADAM MODULE PRESAVE - STORY SO FAR! event sent to my module
Script -----> yad_SetStorySoFar - SETTING STORY SO FAR! sets story based on prefix of my mod areas (yad)
General Saving - Start
General Saving - End
Load Lothering (from Lake Brtonigla):
General Loading - Start
General Loading - End
Script -----> SP MODULE LOAD! handle event - pass to sp module start.
Script -----> SP MODULE START LOAD - STORY SO FAR! dont handle event pass it to module core
Script -----> MODULE CORE LOAD! event is defined in module_core, but not handled!
Script -----> SP MODULE LOAD - AFTER HANDLE EVENT! return to sp module and event handled = TRUE
Script -----> YADAM MODULE LOAD - STORY SO FAR! event sent to my module
Script -----> YADAM PRCSCR SCRIPT! area load (any)
Load Lake Brtonigla (from Lothering):
General Loading - Start
General Loading - End
Script -----> SP MODULE LOAD! handle event - pass to sp module start.
Script -----> SP MODULE START LOAD - STORY SO FAR! dont handle event pass it to module core
Script -----> MODULE CORE LOAD! event is defined in module_core, but not handled!
Script -----> SP MODULE LOAD - AFTER HANDLE EVENT! return to sp module and event handled = TRUE
Script -----> YADAM MODULE LOAD - STORY SO FAR! event sent to my module
Script -----> yad_SetStorySoFar - SETTING STORY SO FAR! sets story based on prefix of my mod areas (yad)
Script -----> YADAM PRCSCR SCRIPT! area load (any)
module script:
#include "log_h"
#include "utility_h"
#include "wrappers_h"
#include "events_h"
#include "yad_utility_h"
#include "yad_constants_h"
void main()
{
event ev = GetCurrentEvent();
int nEventType = GetEventType(ev);
switch(nEventType)
{
case EVENT_TYPE_MODULE_LOAD: //when we load from save in our module
{
PrintToLog("-----> YADAM MODULE LOAD - STORY SO FAR!");
//story plot to be displayed..
yad_SetStorySoFar();
break;
}
case EVENT_TYPE_MODULE_PRESAVE: //when we prepare to save in our module
{
PrintToLog("-----> YADAM MODULE PRESAVE - STORY SO FAR!");
//story plot to be displayed..
yad_SetStorySoFar();
//handles our custom "story so far" and sets plot flags which
//text will be displayed on loading screen..
yad_HandleStorySoFar();
break;
}
}
}
functions:
void yad_HandleStorySoFar()
{
//player enters from camp
int bPlainCamp = WR_GetPlotFlag(PLT_YAD000PT_MAIN, ADDED_TO_PLAIN_CAMP);
//Player enters from Village of Haven.
int bHaven = WR_GetPlotFlag(PLT_YAD000PT_MAIN, ADDED_TO_HAVEN_VILLAGE);
//Player enters from Orzammar.
int bOrzammar = WR_GetPlotFlag(PLT_YAD000PT_MAIN, ADDED_TO_OZRAMMAR);
if (bPlainCamp){
WR_SetPlotFlag(PLT_YAD000PT_SSF_YADAM, SSF_YAD_CAMP_TO_LAKE_BRTONIGLA, TRUE, TRUE);
}
else if (bHaven){
WR_SetPlotFlag(PLT_YAD000PT_SSF_YADAM, SSF_YAD_HAVEN_TO_LAKE_BRTONIGLA, TRUE, TRUE);
}
else if (bOrzammar){
WR_SetPlotFlag(PLT_YAD000PT_SSF_YADAM, SSF_YAD_ORZAMMAR_TO_CAVES_OF_VIZINADA, TRUE, TRUE);
}
else {
WR_SetPlotFlag(PLT_YAD000PT_SSF_YADAM, SSF_YAD_MOVING_AROUND, TRUE, TRUE);
}
}
void yad_SetStorySoFar()
{
object oArea = GetArea(GetHero());
string sAreaCode = StringLeft(GetTag(oArea), 3);
if(sAreaCode == "yad"){
//set "story so far" to be displayed upon loading
WR_SetStoryPlot(PLT_YAD000PT_SSF_YADAM);
if (yad_Debug()) DisplayFloatyMessage(GetMainControlled(), PLT_YAD000PT_SSF_YADAM, FLOATY_MESSAGE, 16777215, 20.0);
PrintToLog("-----> yad_SetStorySoFar - SETTING STORY SO FAR!");
}
}
dont ask me why i write in plural..
well, it seems that events are sent to modules by priority, first goes to SP cause we extending SP.. even if event is handled in SP, event is also sent to our module.. i'm not sure if same applies if event handled is set to TRUE in module_core, i guess it's same behavior.. when we extend SP, it's best to avoid passing events to module_core to avoid duplicate processing..
I've changed some scripts to mimic SP behavior and now it works..
some log file output:
Load from save game:
Party camp:
General Loading - Start
General Loading - End
Script -----> SP MODULE LOAD! handle event - pass to sp module start.
Script -----> SP MODULE START LOAD - STORY SO FAR! dont handle event pass it to module core
Script -----> MODULE CORE LOAD! event is defined in module_core, but not handled!
Script -----> SP MODULE LOAD - AFTER HANDLE EVENT! return to sp module and event handled = TRUE
Script -----> YADAM MODULE LOAD - STORY SO FAR! event sent to my module
Script -----> YADAM PRCSCR SCRIPT! area load (any)
Enter Random encounter, interrupted when travelling:
General Area List Swap - Start
General Area List Swap - End
Script -----> YADAM PRCSCR SCRIPT! area load (any)
Enter Lothering:
General Area List Swap - Start
General Area List Swap - End
Script -----> YADAM PRCSCR SCRIPT! area load (any)
Saving Lothering:
Script -----> SP MODULE PRESAVE! handle event - pass to sp module start
Script -----> SP MODULE START PRESAVE - STORY SO FAR! - dont handle event pass it to module core
-------------> module core does not have PRESAVE EVENT!!
Script -----> SP MODULE PRESAVE - AFTER HANDLE EVENT! return to sp module and event handled = TRUE
Script -----> YADAM MODULE PRESAVE - STORY SO FAR! event sent to my module
-------------> does not set story cause were not in my mod areas..
General Saving - Start
General Saving - End
Enter Lake Brtonigla:
General Area List Swap - Start
General Area List Swap - End
Script -----> YADAM PRCSCR SCRIPT! area load (any)
Saving Lake Brtonigla:
Script -----> SP MODULE PRESAVE! handle event - pass to sp module start
Script -----> SP MODULE START PRESAVE - STORY SO FAR! - dont handle event pass it to module core
-------------> module core does not have PRESAVE EVENT!!
Script -----> SP MODULE PRESAVE - AFTER HANDLE EVENT! return to sp module and event handled = TRUE
Script -----> YADAM MODULE PRESAVE - STORY SO FAR! event sent to my module
Script -----> yad_SetStorySoFar - SETTING STORY SO FAR! sets story based on prefix of my mod areas (yad)
General Saving - Start
General Saving - End
Load Lothering (from Lake Brtonigla):
General Loading - Start
General Loading - End
Script -----> SP MODULE LOAD! handle event - pass to sp module start.
Script -----> SP MODULE START LOAD - STORY SO FAR! dont handle event pass it to module core
Script -----> MODULE CORE LOAD! event is defined in module_core, but not handled!
Script -----> SP MODULE LOAD - AFTER HANDLE EVENT! return to sp module and event handled = TRUE
Script -----> YADAM MODULE LOAD - STORY SO FAR! event sent to my module
Script -----> YADAM PRCSCR SCRIPT! area load (any)
Load Lake Brtonigla (from Lothering):
General Loading - Start
General Loading - End
Script -----> SP MODULE LOAD! handle event - pass to sp module start.
Script -----> SP MODULE START LOAD - STORY SO FAR! dont handle event pass it to module core
Script -----> MODULE CORE LOAD! event is defined in module_core, but not handled!
Script -----> SP MODULE LOAD - AFTER HANDLE EVENT! return to sp module and event handled = TRUE
Script -----> YADAM MODULE LOAD - STORY SO FAR! event sent to my module
Script -----> yad_SetStorySoFar - SETTING STORY SO FAR! sets story based on prefix of my mod areas (yad)
Script -----> YADAM PRCSCR SCRIPT! area load (any)
module script:
#include "log_h"
#include "utility_h"
#include "wrappers_h"
#include "events_h"
#include "yad_utility_h"
#include "yad_constants_h"
void main()
{
event ev = GetCurrentEvent();
int nEventType = GetEventType(ev);
switch(nEventType)
{
case EVENT_TYPE_MODULE_LOAD: //when we load from save in our module
{
PrintToLog("-----> YADAM MODULE LOAD - STORY SO FAR!");
//story plot to be displayed..
yad_SetStorySoFar();
break;
}
case EVENT_TYPE_MODULE_PRESAVE: //when we prepare to save in our module
{
PrintToLog("-----> YADAM MODULE PRESAVE - STORY SO FAR!");
//story plot to be displayed..
yad_SetStorySoFar();
//handles our custom "story so far" and sets plot flags which
//text will be displayed on loading screen..
yad_HandleStorySoFar();
break;
}
}
}
functions:
void yad_HandleStorySoFar()
{
//player enters from camp
int bPlainCamp = WR_GetPlotFlag(PLT_YAD000PT_MAIN, ADDED_TO_PLAIN_CAMP);
//Player enters from Village of Haven.
int bHaven = WR_GetPlotFlag(PLT_YAD000PT_MAIN, ADDED_TO_HAVEN_VILLAGE);
//Player enters from Orzammar.
int bOrzammar = WR_GetPlotFlag(PLT_YAD000PT_MAIN, ADDED_TO_OZRAMMAR);
if (bPlainCamp){
WR_SetPlotFlag(PLT_YAD000PT_SSF_YADAM, SSF_YAD_CAMP_TO_LAKE_BRTONIGLA, TRUE, TRUE);
}
else if (bHaven){
WR_SetPlotFlag(PLT_YAD000PT_SSF_YADAM, SSF_YAD_HAVEN_TO_LAKE_BRTONIGLA, TRUE, TRUE);
}
else if (bOrzammar){
WR_SetPlotFlag(PLT_YAD000PT_SSF_YADAM, SSF_YAD_ORZAMMAR_TO_CAVES_OF_VIZINADA, TRUE, TRUE);
}
else {
WR_SetPlotFlag(PLT_YAD000PT_SSF_YADAM, SSF_YAD_MOVING_AROUND, TRUE, TRUE);
}
}
void yad_SetStorySoFar()
{
object oArea = GetArea(GetHero());
string sAreaCode = StringLeft(GetTag(oArea), 3);
if(sAreaCode == "yad"){
//set "story so far" to be displayed upon loading
WR_SetStoryPlot(PLT_YAD000PT_SSF_YADAM);
if (yad_Debug()) DisplayFloatyMessage(GetMainControlled(), PLT_YAD000PT_SSF_YADAM, FLOATY_MESSAGE, 16777215, 20.0);
PrintToLog("-----> yad_SetStorySoFar - SETTING STORY SO FAR!");
}
}
dont ask me why i write in plural..
#3
Posté 05 novembre 2013 - 08:37
Events are multicast by the engine to the main module and all of its add-ons. Consequently your script isn't intercepting the events so much as being notified that the events have been raised and allowing you to react to them. Therefore if, for example, your module is an add-on to the Single Player (SP) module then the SP is being notified, your module is being notified and all other add-ons are being notified.
You cannot prevent the events going to the other modules even if the way BioWare uses the
Incidentally when posting code it can be helpful to use the [code] and [/code] tags.
You cannot prevent the events going to the other modules even if the way BioWare uses the
nEventHandledvariable might make it appear that way. Consequently you module is an add-on (to the SP or any other module) you must not use
module_coreor route unahandled events from your script to
module_core.
Incidentally when posting code it can be helpful to use the [code] and [/code] tags.
Modifié par Sunjammer, 05 novembre 2013 - 08:38 .
#4
Posté 05 novembre 2013 - 08:59
thanks Sunjammer, that helps a lot..
from SP scripts i can see what's happening, but don't know when it's happening.. how events are chained together (in relation to my module) cause sometimes things would work, and sometimes didn't.. also i 'm confused why some events get to my module, and some don't (i believe it was unique power or item acquired), for some i must use engineevents.gda, and some i can catch in my "module core" script.. and debugging scripts is.. well, just is...
from SP scripts i can see what's happening, but don't know when it's happening.. how events are chained together (in relation to my module) cause sometimes things would work, and sometimes didn't.. also i 'm confused why some events get to my module, and some don't (i believe it was unique power or item acquired), for some i must use engineevents.gda, and some i can catch in my "module core" script.. and debugging scripts is.. well, just is...
Modifié par dr.drummie, 05 novembre 2013 - 09:01 .





Retour en haut






