generalmx Posted October 16, 2016 Share Posted October 16, 2016 (edited) I'm new to Papyrus scripting, though not new to TES modding and certainly not to coding, and the way Event Handlers are used are a bit confusing to me. It seems all scripts are meant to be attached to objects, quests, or effects, so I'm not sure how one makes use of the NVSE Event Handlers, which are by nature detached. All the tutorials I've been looking at either show it from the point of view of attaching to something or show the event handling code in snippets that leave out key stuff. My first question is: how would I go about doing something on game load? I'll start with firing off a debug message and work up to registering a functioning event handler. I know how to make a script attached to an existing form but I'm not sure what, if anything, an "on game load" would be attached to. Edited October 16, 2016 by generalmx Link to comment Share on other sites More sharing options...
PushTheWinButton Posted October 16, 2016 Share Posted October 16, 2016 (edited) It seems you're getting confused between papyrus, an event based language, and NVSE's event handlers, which aren't papyrus and still use NV's native language. Event handlers in NVSE are written as UDF scripts which accept the correct arguments for the event, then you assign the detached script to the event in a separate script using the SetEventHandler function. HOWEVER, to do something on load you don't need an event handler. Instead you use a quest script that runs in GameMode fairly frequently, and the condition GetGameLoaded (which returns true every time a save game is loaded) or GetGameRestarted (which returns true only once per game session). Edited October 16, 2016 by PushTheWinButton Link to comment Share on other sites More sharing options...
RoyBatterian Posted October 16, 2016 Share Posted October 16, 2016 GetGameLoaded should be avoided, use GetGameRestarted. Link to comment Share on other sites More sharing options...
generalmx Posted October 19, 2016 Author Share Posted October 19, 2016 Alright so that's done but the next thing I'm having trouble with is using SetEventHandler. Here's example code: ScriptName 123InitScript BEGIN GameMode if ( GetGameRestarted() ) SetEventHandler "OnDeath" 123DeathScript PrintToConsole "123InitScript complete" endif END ScriptName 123DeathScript ref rKilled ref rKiller Begin Function {rKilled, rKiller} PrintToConsole "Something died" End This compiles alright but I can't seem to get my function called when something dies. I also can't seem to find a good example to play with looking at plugins that use NVSE. Link to comment Share on other sites More sharing options...
PushTheWinButton Posted October 19, 2016 Share Posted October 19, 2016 Is the function script definitely an "Object" type script? Making that mistake has screwed me over a couple of times. So does the Print line definitely run in the GameMode script? There's plenty of mods that use NVSE; I use it pretty extensively. I used to use event more often too, but not so much now. There's usually a better way to do things and running a script every time something happens can be performance intensive so you need to be careful what's in your event function. On that note, it might also be worth filtering using the "first" and "second" parameters so that your event function doesn't run when its not needed. So if you're only interested in actors that are killed by the player you'd use: SetEventHandler "OnDeath" EvOnDeathFunction "second"::PlayerREF Link to comment Share on other sites More sharing options...
Mktavish Posted October 22, 2016 Share Posted October 22, 2016 (edited) "123DeathScript" This is a form ID ? Don't use numbers to begin any Form-ID ! Ref or Base ... nothing While it may work sometimes and for a little while ... The engine can go screwy lewy and flat out end up refusing to find items that start with numbers. I just recently found this out myself ... had been using "00" for awhile and then things just up and quit working. But swapping back to starting with letters fixed it.And to clarify ... numbers inside or ending the form ID is fine. Edited October 22, 2016 by Mktavish Link to comment Share on other sites More sharing options...
RoyBatterian Posted October 22, 2016 Share Posted October 22, 2016 Don't start any editor ids with numbers, ever. Use aa or zz or something for your sorting needs. Starting scripts in particular with numbers will make them not work. Link to comment Share on other sites More sharing options...
Recommended Posts