Script Help Request

Post » Wed May 25, 2016 12:27 am

Hi, I working on making a mod where in a couple rooms I want the player to have to wear protection in then so the he/she is not losing health. One room is supposed to be really cold and without this protection (probably an amulet or an ring) they'll freeze slowing freeze to death. The other room is supposed to be insanely hot, and the player wouldn't be able to last long in there at all.



The thing is I really have no idea how to go about making these scripts myself, and I would like some help with making them. Any help at all will be most welcome!

User avatar
Shiarra Curtis
 
Posts: 3393
Joined: Thu Jan 04, 2007 3:22 pm

Post » Tue May 24, 2016 8:38 pm

There are a few ways this might be handled, depending on how you want the effect to appear. It is not clear if you expect players with resistance to fire or frost due to race, spell or potion effects to still be vulnerable to this damage.



I tested one approach requiring three scripts (for the cold room).


I used Arrille's Tradehouse for my test cell.


I created an amulet and gave it a custom frost resistance enchantment of 0%. (This displays the frost protection icon, but it will not offer any real frost protection except for the room's effects. You can make it a proper frost resistance enchantment if you wish.)


A script on the amulet checks to see if it is equipped, and writes that value to a global variable.


In my test, the global variable is cyr_amuletEquipped, but you rename it as appropriate.


I placed an invisible activator in the cold room (Arrille's Tradehouse).


A script on the activator starts a global script that applies the frost damage. (In this solution, the global script is necessary to remove the damage effect after the player leaves the cell. It could be handled differently if you don't care about the player experiencing the frost damage effect.)


The global script reads the value of the global variable and add/removes a custom frost damage curse. (This needs to be a curse, since a spell is merely added to the player's spell list, and an ability damages both the current health and the base health.)


Using spells rather than scripted damage may make it vulnerable to cures and dispels - another tradeoff for enjoying the actual spell effect.


My custom frost curse does 1 point of damage, but you can make it greater if you wish.



The amulet's script:




Spoiler

Begin cyr_AmuletProtectionScript



; Attached to amulet cyr_exquisite_amulet.


; Checks to see if amulet is equipped, and if it is prevents the


; player from suffering frost damage while in Arrille's Tradehouse.



; short cyr_amuletEquipped ; global variable



short OnPCEquip



if ( menumode == 1 )


return


endif



if ( cyr_amuletEquipped == 0 )


if ( OnPCEquip == 1 )


set cyr_amuletEquipped to 1


endif


elseif ( cyr_amuletEquipped == 1 )


if ( OnPCEquip == 0 )


set cyr_amuletEquipped to 0


endif


endif



End





The invisible activator's script:




Spoiler

Begin cyr_ArrillesTradehouseScript



; Attached to hidden activator cyr_hAct_ArrillesTradehouse.


; Starts global script that determines if the player suffers frost damage.



if ( ( ScriptRunning "cyr_GlobalFrostDamageScript" ) == 0 )


StartScript "cyr_GlobalFrostDamageScript"


endif



End





The global script:




Spoiler

Begin cyr_GlobalFrostDamageScript



; Global script started by script cyr_ArrillesTradehouseScript.


; Checks to see if amulet is equipped, and causes the player to suffer frost damage


; if not wearing amulet while in Arrille's Tradehouse.



; short cyr_amuletEquipped ; global variable



short spellAdded



if ( ( GetPCCell "Seyda Neen, Arrille's Tradehouse" ) == 0 )


if ( spellAdded == 1 )


set spellAdded to 0


player->RemoveSpell "cyr_FrostDamage"


endif


StopScript "cyr_GlobalFrostDamageScript"


return


endif



if ( cyr_amuletEquipped == 0 )


if ( spellAdded == 0 )


set spellAdded to 1


player->AddSpell "cyr_FrostDamage"


endif


elseif ( cyr_amuletEquipped == 1 )


if ( spellAdded == 1 )


set spellAdded to 0


player->RemoveSpell "cyr_FrostDamage"


endif


endif



End





Obviously you will tailor these scripts for your circumstances, and create a similar set of scripts for the hot room. You may be able to use them as a guide if you want to use a different approach than the one I tested. Or simply clarify your needs and I or someone else will help you make the necessary adjustments.

User avatar
Phoenix Draven
 
Posts: 3443
Joined: Thu Jun 29, 2006 3:50 am

Post » Wed May 25, 2016 1:05 am


Thank you, I'll look into setting them up for my mod. I think that this will be good but I'll need to test it out to see if is what I'm going for. Just a quick question where should I put the invisible activator? Would right in front of the door that you enter the cell work? Oh, would the invisible activator used for sound effects work for this? Or is there something else I should use?



Edit, oh about the protection, I think that I'm going to stick limiting to using the amulet to stop the effects, that way the only way to safely travel the area is if you found the ring/amulets in the previous section. So natural resistances/potions/etc will be of no help.

User avatar
Robyn Lena
 
Posts: 3338
Joined: Mon Jan 01, 2007 6:17 am

Post » Wed May 25, 2016 3:07 am

You can place the invisible activator anywhere in the cell (even below the floor or behind a wall). I typically edit one of Bethesda's sound activators since you can see them clearly in the editor, but they are not rendered in-game.



If you do not what the player to benefit from any conventional elemental protection (racial, spells or potions) you will need to script the damage. This can be more efficient (the global script is not necessary, or the global variable for that matter although another adjustment is required). However it means there will be no spell effect to accompany the damage. It means that until the player notices the loss of health he/she may not realize there is a problem, but it will work.



I did a quick check, and it is possible to create a spell that will not do any damage, but the spell effects are still observed - this I tested in-game. I modified the activator script to inflict 1 point of health damage per seconds. You can adjust that to be whatever you require by changing the amount of damage (I do not know if it has to be an integer) or the timer (e.g. 1 point every 2 seconds) - or both.



If you like the idea of the spell effect being visible, just edit the custom spell (curse) to do zero damage (minimum and maximum).



This is the new activator script:




Spoiler

Begin cyr_ArrillesTradehouseScript



; Attached to hidden activator cyr_hAct_ArrillesTradehouse.


; Starts global script that determines if the player suffers frost damage.



; short cyr_amuletEquipped ; global variable



float timer



if ( menumode == 1 ) ; necessary for proper timer operation


return


endif



if ( ( ScriptRunning "cyr_GlobalFrostDamageScript" ) == 0 )


StartScript "cyr_GlobalFrostDamageScript"


endif



if ( cyr_amuletEquipped == 0 )


set timer to ( timer + GetSecondsPassed )


if ( timer < 1 )


return


endif


set timer to 0


player->ModCurrentHealth -1


endif



End





I forgot to mention in my previous post that the enchantment on the amulet is constant effect resist frost with a magnitude of zero (it is just for show).



If you don't care about the appearances, but just want the damage and protection, you don't need to create the spell (curse) the amulet does not require an enchantment, you do not need the global script (but we will keep the global variable for now) and the activator script will look like this:




Spoiler

Begin cyr_ArrillesTradehouseScript



; Attached to hidden activator cyr_hAct_ArrillesTradehouse.


; Starts global script that determines if the player suffers frost damage.



; short cyr_amuletEquipped ; global variable



float timer



if ( menumode == 1 ) ; necessary for proper timer operation


return


endif



if ( cyr_amuletEquipped == 0 )


set timer to ( timer + GetSecondsPassed )


if ( timer < 1 )


return


endif


set timer to 0


player->ModCurrentHealth -1


endif



End





One thing I noticed during testing is the scripted health damage seemed faster than it should be (almost 1 point per half-second). I cannot see why that would be the case. If you experience something like that you can tweak the damage and duration give the results you want, if not the results you would expect.

User avatar
An Lor
 
Posts: 3439
Joined: Sun Feb 18, 2007 8:46 pm


Return to III - Morrowind