tomfrankly Posted November 6, 2012 Share Posted November 6, 2012 I'm trying to make magicka regenerate while the player is casting spells. I'm not sure how to go about this, but I assume it has to do with creating an invisible quest which has a script attached. I'm pretty clueless about how to do scripting in the Creation Kit, but I do have programming background in Java and C, so understanding the code itself shouldn't be a problem. Here is the script I started (it doesn't compile). Once the script is working, how do I get it running during the game?Scriptname tomfranklyRegenWhileCasting extends Actor Event OnInit() ; This event will run once, when the script is initialized RegisterForUpdate(1) GotoState ("polling") EndEvent State polling Debug.Trace("Polling!") While (player.iscasting > 0) Debug.Trace("CASTING!") endWhile EndState State active ; Do nothing in here EndState Link to comment Share on other sites More sharing options...
MGoods Posted November 7, 2012 Share Posted November 7, 2012 I must admit I haven't done much with states, but I'm pretty sure that they are used to encapsulate events and functions, not contain code. To elaborate you use states to say "when the script is in this state, do this when this event fires, or when this function is called, and do that when the script is in that state", the code you have in those state blocks is never called by anything, ever. Link to comment Share on other sites More sharing options...
Eckss Posted November 7, 2012 Share Posted November 7, 2012 I’ll first point out that I’m not an authority on scripting, I’m self-taught and I’ve had to find a lot of things out the hard way. However I do think I can help. For what you want, you’ll need to:1. Set up an empty quest, selecting the ‘Start Game Enabled’ and ‘Allow Repeated Stages’ checkboxes.2. Set up a Quest Alias for the Player and attach your Script to that Alias.That’s it. As for the script, Papyrus doesn’t seem to like certain things that would seem logical given your background, so be careful.For example, you can’t just use ‘Player’ and expect it to work even though logically you should be able to. You have to do something like this:Actor ak = Game.GetPlayer()You can then use ak to refer to the player as an actor. You have to do this even though you’re attaching the script to a Quest Alias that IS the Player. Otherwise you have to get the Alias to do things and that still requires that you set up a property for the Alias even though your script is attached to it. To get something to happen whenever a spell is cast, you need to have your script activated by an Event. Something like,Event OnSpellCast (Form akSpell) ; Do whatever EndEventOnSpellCast is an Object Reference Event and therefore should work on an Actor script as Actor is an extension of Object Reference.Unless a script is activated every time it’s expected to run and stops when it’s not needed, you might end up with a script that never stops which will eventually break the game. Good luck.Eck. :thumbsup: Link to comment Share on other sites More sharing options...
IsharaMeradin Posted November 7, 2012 Share Posted November 7, 2012 I think Eckss idea would work, however OnSpellCast requires you to define the spells with which you want the regen ablity to take place. That would be a lot of repetitive code. I think a simpler route would be: on the player alias attach a script which registers for update say every 5-30 seconds the OnUpdate event would check for the player's actual magicka to be lower than their base magickaif it is then your magicka regen kicks in. because the script is attached to an alias, when the mod is uninstalled the script shouldn't be continuing to run. tho to be safe you could make the update dependent upon a defined global variable and have users set that global variable to something else which will cause the update to be unregistered. Link to comment Share on other sites More sharing options...
rickerhk Posted November 7, 2012 Share Posted November 7, 2012 Whenever possible, use RegisterForSingleUpdate() instead of RegisterForUpdate() and register for the next update within your code block. http://forums.bethsoft.com/topic/1409991-best-practices-papyrus/page__hl__practices Link to comment Share on other sites More sharing options...
Eckss Posted November 7, 2012 Share Posted November 7, 2012 OnSpellCast requires you to define the spells with which you want the regen ablity to take place. That would be a lot of repetitive code.Really? :confused:If so, then the Wiki entry example must be very misleading because that’s not how it reads to me.If you need to specify the spell, how could the Event in the Wiki example ever be called except in the instance that the spell cast was a fireball? Unless the Wiki is wrong, the OnSpellCast Event parameter akSpell contains the spell that was cast to trigger the event, so I don’t see how there would be any repetitive code in the situation outlined by the OP. It doesn’t matter what the value of akSpell is, you just have to code it like that because Papyrus requires it for correct syntax. Eck. Link to comment Share on other sites More sharing options...
IsharaMeradin Posted November 7, 2012 Share Posted November 7, 2012 Perhaps they need to word it better then.Or provide full working scripts. It looked to me that a property needed to be defined for it to function, a property which corresponded to whatever spell was being cast. Link to comment Share on other sites More sharing options...
Eckss Posted November 8, 2012 Share Posted November 8, 2012 @IsharaMeradin, that’s a basic difference between a Function and an Event. The definition of an Event’s parameters is:The parameters are identical to the function parameter list, but should match the data that the game will send to the event.and can be seen here on the relevant Wiki page. In case that isn’t clear enough, a Function requires parameters to be INPUT to it for it to function (the clue’s in the name) while an Event will OUTPUT the parameters that triggered the Event notification (the clue’s in the name here also).If you think that the Wiki could be better worded, you can edit it yourself as:This Wiki is a community-run site that is a living help file where you'll find everything you need to use the Creation Kit and make mods for The Elder Scrolls V: Skyrim. This Wiki is publicly editable... all you need to do is create an account to start contributing.I hope that clears everything up.Eck. :) Link to comment Share on other sites More sharing options...
demidekidasu Posted November 16, 2012 Share Posted November 16, 2012 (edited) The way I get a script to run itself is by attaching it to an X marker somewhere in the Tamriel worldspace (I put all mine outside whiterun so I can find them in the future :P), with "full lod" checked. Works flawlessly in my experience. Can't be bothered writing all that quest stuff... lol Have your opening event as "OnInit" and you are good to go. Example - here is the script for my mod Passtime, using SKSE functions, that I simply attached to an X marker outside Whiterun. actor property PlayerREF auto idle property IdleStop_Loose auto ;================================ ;===============INIT============== ;================================ Event OnInit() GotoState("WAITforINPUT") EndEvent ;================================ State WAITforINPUT Event OnBeginState() RegisterForKey(210) RegisterForKey(199) RegisterForKey(201) RegisterForKey(211) RegisterForKey(207) RegisterForKey(209) Utility.Wait(0.5) EndEvent EndState ;================================ Event OnKeyDown(Int KeyCode) If KeyCode == 210 Debug.Notification("You start to warm your hands by the fire...") UnregisterForAllKeys() Utility.Wait(0.5) Game.DisablePlayerControls(True, True, True, False, True, True, True, True) Game.ForceThirdPerson() debug.SetGodMode(true) Utility.wait(2.0) Debug.SendAnimationEvent(PlayerREF, "IdleWarmHands") RegisterForKey(210) GotoState("KEYONEEND") ElseIf KeyCode == 199 Debug.Notification("You start reading a book...") UnregisterForAllKeys() Utility.Wait(0.5) Game.DisablePlayerControls(True, True, True, False, True, True, True, True) Game.ForceThirdPerson() debug.SetGodMode(true) Utility.wait(2.0) Debug.SendAnimationEvent(PlayerREF, "IdleBook_Read") RegisterForKey(199) GotoState("KEYTWOEND") ElseIf KeyCode == 201 Debug.Notification("You do a dance...") UnregisterForAllKeys() Utility.Wait(0.5) Game.DisablePlayerControls(True, True, True, False, True, True, True, True) Game.ForceThirdPerson() debug.SetGodMode(true) Utility.wait(2.0) Debug.SendAnimationEvent(PlayerREF, "IdleCiceroDance2") Utility.wait(6.0) GotoState("KEYTHREEEND") ElseIf KeyCode == 211 Debug.Notification("You sit down looking sad...") UnregisterForAllKeys() Utility.Wait(0.5) Game.DisablePlayerControls(True, True, True, False, True, True, True, True) Game.ForceThirdPerson() debug.SetGodMode(true) Utility.wait(2.0) Debug.SendAnimationEvent(PlayerREF, "IdleWounded_01") RegisterForKey(211) GotoState("KEYFOUREND") ElseIf KeyCode == 207 Debug.Notification("You lie down...") UnregisterForAllKeys() Utility.Wait(0.5) Game.DisablePlayerControls(True, True, True, False, True, True, True, True) Game.ForceThirdPerson() debug.SetGodMode(true) Utility.wait(2.0) Debug.SendAnimationEvent(PlayerREF, "IdleWounded_02") RegisterForKey(207) GotoState("KEYFIVEEND") ElseIf KeyCode == 209 Debug.Notification("You sit down feeling unwell...") UnregisterForAllKeys() Utility.Wait(0.5) Game.DisablePlayerControls(True, True, True, False, True, True, True, True) Game.ForceThirdPerson() debug.SetGodMode(true) Utility.wait(2.0) Debug.SendAnimationEvent(PlayerREF, "IdleWounded_03") RegisterForKey(209) GotoState("KEYSIXEND") EndIf EndEvent ;================================ ;================================ ;==============KEY 1============== ;================================ State KEYONEEND Event OnKeyDown(Int KeyCode) If KeyCode == 210 Debug.Notification("You stop warming your hands...") UnregisterForAllKeys() Utility.wait(2.0) Debug.SendAnimationEvent(PlayerREF, "IdleForceDefaultState") Utility.Wait(0.5) Game.EnablePlayerControls() debug.SetGodMode(False) PlayerREF.playidle(IdleStop_Loose) Utility.Wait(0.2) GotoState("WAITforINPUT") EndIf EndEvent EndState ;================================ ;================================ ;==============KEY 2============== ;================================ State KEYTWOEND Event OnKeyDown(Int KeyCode) If KeyCode == 199 Debug.Notification("You stop reading...") UnregisterForAllKeys() Utility.wait(2.0) Debug.SendAnimationEvent(PlayerREF, "IdleForceDefaultState") Utility.Wait(0.5) Game.EnablePlayerControls() debug.SetGodMode(False) PlayerREF.playidle(IdleStop_Loose) Utility.Wait(0.2) GotoState("WAITforINPUT") EndIf EndEvent EndState ;================================ ;================================ ;==============KEY 3============== ;================================ State KEYTHREEEND Event OnBeginState() Utility.wait(0.2) Debug.SendAnimationEvent(PlayerREF, "IdleForceDefaultState") Utility.Wait(0.5) Game.EnablePlayerControls() debug.SetGodMode(False) PlayerREF.playidle(IdleStop_Loose) Utility.Wait(0.2) GotoState("WAITforINPUT") EndEvent EndState ;================================ ;================================ ;==============KEY 4============== ;================================ State KEYFOUREND Event OnKeyDown(Int KeyCode) If KeyCode == 211 Debug.Notification("You stand up...") UnregisterForAllKeys() Utility.wait(2.0) Debug.SendAnimationEvent(PlayerREF, "IdleForceDefaultState") Utility.Wait(0.5) Game.EnablePlayerControls() debug.SetGodMode(False) PlayerREF.playidle(IdleStop_Loose) Utility.Wait(0.2) GotoState("WAITforINPUT") EndIf EndEvent EndState ;================================ ;================================ ;==============KEY 5============== ;================================ State KEYFIVEEND Event OnKeyDown(Int KeyCode) If KeyCode == 207 Debug.Notification("You stand up...") UnregisterForAllKeys() Utility.wait(2.0) Debug.SendAnimationEvent(PlayerREF, "IdleForceDefaultState") Utility.Wait(0.5) Game.EnablePlayerControls() debug.SetGodMode(False) PlayerREF.playidle(IdleStop_Loose) Utility.Wait(0.2) GotoState("WAITforINPUT") EndIf EndEvent EndState ;================================ ;================================ ;==============KEY 6============== ;================================ State KEYSIXEND Event OnKeyDown(Int KeyCode) If KeyCode == 209 Debug.Notification("You stand up...") UnregisterForAllKeys() Utility.wait(2.0) Debug.SendAnimationEvent(PlayerREF, "IdleForceDefaultState") Utility.Wait(0.5) Game.EnablePlayerControls() debug.SetGodMode(False) PlayerREF.playidle(IdleStop_Loose) Utility.Wait(0.2) GotoState("WAITforINPUT") EndIf EndEvent EndState ;================================ Edited November 16, 2012 by demidekidasu Link to comment Share on other sites More sharing options...
Recommended Posts