Jump to content

How to run script once per session, without GameMode?


FiftyTifty

Recommended Posts

I'm having a wee bit of trouble working my head around this. Don't understand why this wee setup doesn't work, after following this tutorial: https://eddoursul.win/menumode-4/

 

What I am wanting to do, is change the weapon reach of a bunch of weapons, by running a script once every time the game is loaded (i.e, GetGameLoade == 1). Purely as a learning exercise, really, but also a micro-optimization that I can apply to various mods. But for some reason, it just doesn't want to work. Below are my three scripts:

scn AAAFyTyWeapReachQuestScript

begin MenuMode 4

    StopQuest AAAFyTyWeapReachQuest

    if GetGameRestarted == 0
        return
    endif

    SetEventHandler "PostLoadGame" AAAFyTyWeapReachQuestScriptUDF
    SetEventHandler "NewGame" ({} => call AAAFyTyWeapReachQuestScriptUDF 1)

end

 

scn AAAFyTyWeapReachQuestScriptUDF

int iArg

begin function MyPostLoadGameHandler { iArg }

    CallAfterSeconds 0 AAAFyTyWeapReachQuestScriptUDFGameMode

end

 

scn AAAFyTyWeapReachQuestScriptUDFGameMode

Begin Function {}
	
	SetWeaponReach 0.4 WeapSwitchBlade

End

Unfortunately, the function SetWeaponReach never gets called. When using GetWeaponReach WeapSwitchBlade in the console, it returns the default value of 1.0.

 

Any idea why this might be?

Link to comment
Share on other sites

You can't use CallAfterSeconds in a UDF. It only works in a GameMode script.

Figures. The tutorial was faulty then.

 

The real way to do it, is as follows:

scn AAAFyTyWeapReachQuestScript

begin MenuMode 4

    StopQuest AAAFyTyWeapReachQuest

    if GetGameRestarted == 0
        return
    endif

    SetGameMainLoopCallback AAAFyTyWeapReachQuestScriptUDFGameMode 1 1 1

end

 

scn AAAFyTyWeapReachQuestScriptUDFGameMode

Begin Function {}
	
	Print "Test!"
	SetWeaponReach 0.4 WeapSwitchBlade

	SetGameMainLoopCallback AAAFyTyWeapReachQuestScriptUDFGameMode 0

End
Link to comment
Share on other sites

Also you can get ongoing script line readings from ScriptEffectUpdate - The Elder Scrolls Construction Set Wiki

 

just for future reference ,,,, cuz aint no reason to fix what aint broke ...

 

I like your new profile pic ... :wink:

How would that work? That's only for MagicEffect scripts, according to the wiki. Whereas my script is attached to a quest.

 

Yayaya. I've only met a couple people who know who the character is.

Link to comment
Share on other sites

I don't see a way to make it only run once a day, except for setting the script delay to 86,400 seconds. MenuMode 4 will run while the title menu screen is up. Read the bottom paragraph here, for what you can't do before the player has loaded a save.

Edited by GamerRick
Link to comment
Share on other sites

I don't see a way to make it only run once a day, except for setting the script delay to 86,400 seconds. MenuMode 4 will run while the title menu screen is up. Read the bottom paragraph here, for what you can't do before the player has loaded a save.

I already solved it, and it's not once a day. It's running each time a save is loaded or a new game is started.

Link to comment
Share on other sites

 

Also you can get ongoing script line readings from ScriptEffectUpdate - The Elder Scrolls Construction Set Wiki

 

just for future reference ,,,, cuz aint no reason to fix what aint broke ...

 

I like your new profile pic ... :wink:

How would that work? That's only for MagicEffect scripts, according to the wiki. Whereas my script is attached to a quest.

 

Yayaya. I've only met a couple people who know who the character is.

 

I was more just pointing out the other way besides "GameMode" for making a clock run .
When Gamerick said this "You can't use CallAfterSeconds in a UDF. It only works in a GameMode script."
But in your scripts you could cast a spell or give enchanted item ... to then run the
Begin ScriptEffectUpdate
{Clock}
Remove item ... or spell runs out.
But I can't say I really understood your scripting
I don't know either , who your pic is of ... just said I like it ;)
Link to comment
Share on other sites

 

I don't see a way to make it only run once a day, except for setting the script delay to 86,400 seconds. MenuMode 4 will run while the title menu screen is up. Read the bottom paragraph here, for what you can't do before the player has loaded a save.

I already solved it, and it's not once a day. It's running each time a save is loaded or a new game is started.

 

 

What is the solution??? I still cannot imagine anything would be more efficient than just doing a GetGameLoaded check in the GameMode of your quest script.

Edited by GamerRick
Link to comment
Share on other sites

 

 

I don't see a way to make it only run once a day, except for setting the script delay to 86,400 seconds. MenuMode 4 will run while the title menu screen is up. Read the bottom paragraph here, for what you can't do before the player has loaded a save.

I already solved it, and it's not once a day. It's running each time a save is loaded or a new game is started.

 

 

What is the solution??? I still cannot imagine anything would be more efficient than just doing a GetGameLoaded check in the GameMode of your quest script.

 

I posted it. But I can somewhat elaborate.

 

Here is the script attached to the quest, which only runs at the main menu. At no other point is it being processed in any way:

scn AAAFyTyWeapReachQuestScript

begin MenuMode 4 ;The quest script will only run at the main menu

    StopQuest AAAFyTyWeapReachQuest ;No need to have it run repeatedly in the main menu. Quest scripts are re-initialized every time we go to the main menu.

    if GetGameRestarted == 0 ;Safety check, just in case something is f*#@ed
        return
    endif

    SetGameMainLoopCallback AAAFyTyWeapReachQuestScriptUDFGameMode 1 1 1 ; 1 1 1 == Register the callback, run every frame, run only in GameMode

end

SetGameMainLoopCallback With my passed parameters, runs my UDF script in GameMode. And it will do so endlessly, unless my UDF script then unregisters the callback:

scn AAAFyTyWeapReachQuestScriptUDFGameMode

Begin Function {}
	
	Print "Test!"
	SetWeaponReach 0.4 WeapSwitchBlade

	SetGameMainLoopCallback AAAFyTyWeapReachQuestScriptUDFGameMode 0 ;Code that only needs to run once, has been run. So we stop the callback from being run again

End

Does that clear it up for you? Your approach runs your script every frame at all times in GameMode.

 

This approach runs the script once, and once only, during GameMode.

 

Same purpose. But better performance, and better practice.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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