Jump to content

DOWNLOAD MODS

Are you looking for something shiny for your load order? We have many exclusive mods and resources you won't find anywhere else. Start your search now...

LEARN MODDING

Ready to try your hand at making your own mod creations? Visit the Enclave, the original ES/FO modding school, and learn the tricks of the trade from veteran modders...

JOIN THE ALLIANCE

Membership is free and registering unlocks image galleries, project hosting, live chat, unlimited downloads, & more...

General Script Questions #2


WillieSea
 Share

Recommended Posts

Huh, that's weird. Is it possible that the creature's fire resistance negates the damage? I wouldn't think fire resistance would come into play here though...

Maybe you should try turning it around and see what gets returned for the effect if you hit something with a fire spell. As a debugging exercise - make sure the spell you're using does indeed have a magic effect code of FIDG.

Link to comment
Share on other sites

Huh, that's weird. Is it possible that the creature's fire resistance negates the damage?

What's even weirder is that he doesn't have fire resistance. That's how I knew the script wasn't working. I hit him with a fireball and his health went down.

One thing I'm going to try is combining your idea with mine, like this:

Begin OnMagicEffectHit FIDG

  AddSpell CreatureHealSpell02

End


Begin GameMode

  If  IsSpellTarget CreatureHealSpell02 == 1 && HasMagicEffect FIDG == 0

    RemoveSpell CreatureHealSpell02

  Endif

End

Hopefully, that will resolve the issue.

Edit: Nope. That script adds the healing spell correctly, but doesn't remove it. It's starting to look like I just need to remove the fire creatures entirely.

Edited by The Vyper
Link to comment
Share on other sites

That's what I was starting to wonder. That's why I suggested you turn it around to see what effect that spell casts (as a test) because the code looked fine.

Now if only I could figure out why my DayCount variable won't persist on file save...

We've got:

set DBCMQ07UnholyAlliance.DayCount to GameDaysPassed + 3

in the stage result script for one of the stages. DBCMQ07UnholyAlliance is the name of the quest. At first DayCount was declared as a short and I thought that that was the problem, but it still loses it's value after game reload when I switched it to a float.

It gets set properly at first. But if you save the game, exit and then reload the save, DayCount will be zero. I tried moving this to the quest script, but that doesn't help.

Any ideas?

Link to comment
Share on other sites

That's what I was starting to wonder. That's why I suggested you turn it around to see what effect that spell casts (as a test) because the code looked fine.

And things get even weirder. When I did finally add fire resistance to Flamey, the OnMagicEffectHit block never ran. Apparently, when 100% Resist (effect) is applied, the game won't even register a hit from (effect).

Now if only I could figure out why my DayCount variable won't persist on file save...

We've got:

set DBCMQ07UnholyAlliance.DayCount to GameDaysPassed + 3

in the stage result script for one of the stages. DBCMQ07UnholyAlliance is the name of the quest. At first DayCount was declared as a short and I thought that that was the problem, but it still loses it's value after game reload when I switched it to a float.

It gets set properly at first. But if you save the game, exit and then reload the save, DayCount will be zero. I tried moving this to the quest script, but that doesn't help.

Any ideas?

From what I can tell, changes to Global Variables persist after a save/reload. Have you tried getting DBCMQ07UnholyAlliance to advance and reference a Global Variable instead of an in-script variable?

Link to comment
Share on other sites

And things get even weirder. When I did finally add fire resistance to Flamey, the OnMagicEffectHit block never ran. Apparently, when 100% Resist (effect) is applied, the game won't even register a hit from (effect).

Really? Wow, that's good to know.

From what I can tell, changes to Global Variables persist after a save/reload. Have you tried getting DBCMQ07UnholyAlliance to advance and reference a Global Variable instead of an in-script variable?

*sigh* No I'm afraid it was a saved game issue. Apparently DarkRider and I have something in common: we both got the "you have to test the mod as if you never had it installed" lecture from Arthmoor. I hate it when the lizard is right. *frown* Once I did a clean save, it was fine.

I'm sure both of our responses back to Arthmoor were the same too: No! That's too much work. :lol:

Edited by AndalayBay
Link to comment
Share on other sites

  • 1 month later...

Short is for integer values from -32768 to 32767. Float is for decimal values. If you can use a short for something, you should. Floats are estimates and you will find the values off very slightly, so when you are evaluating the value of a float, you should avoid exact matches (==) if you can.

You do need to be careful, because many functions or game settings are actually floats even though they look like shorts. Gamehour is a prime example of this.

Here's the wiki page on variables - they list the different types at the bottom.

Link to comment
Share on other sites

  • 1 month later...

Q1. You would need to keep track of the date and time. There are many variables that can be used for this purpose, check here:

http://cs.elderscrolls.com/index.php/Category:Time_Functions

You would probably want to use a quest script so the script is running all the time, or you could have a menu option in the bank calculate it when the player checks the balance. Either way will work, and based on how you want to do it will determine what you need to do in the script to figure out the time passed, and how much interest the make on their gold.

Q2. You can use quest script variables to store the account balance or you can use global variables. Depending on how you want to setup the script will determine which is best to use.

Both amounts can be accessed from any script at any branch location.

I am pretty sure there are bank mods made for Oblivion if you are interested in looking at how they did it.

  • Upvote 1
Link to comment
Share on other sites

  • 3 weeks later...

I'm trying to script something and I want to make sure I have this right before I go too far. What I want to happen is this:

1. The player puts some items in a container.

2. A spell hits the container, removes the placed items and replaces them with welkynd and/or varla stones.


The script I have for the spell is:


scn RechargeVarlaWelkyndScript


Short VCount

Short WCount


BeginScriptEffectStart


Set VCount to RCRef.GetItemCount VarlaStoneDepleted

Set WCount to RCRef.GetItemCount WelkyndStoneDepleted


RCRef.RemoveItem VarlaStoneDepleted VCount

RCRef.RemoveItem WelkyndStoneDepleted WCount


RCRef.AddItem VarlaStone VCount

RCRef.AddItem WelkyndStone WCount


End

Do I need to add anything more to this?

Link to comment
Share on other sites

I'm trying to script something and I want to make sure I have this right before I go too far. What I want to happen is this:

1. The player puts some items in a container.

2. A spell hits the container, removes the placed items and replaces them with welkynd and/or varla stones.

The script I have for the spell is:

scn RechargeVarlaWelkyndScript


Short VCount

Short WCount


BeginScriptEffectStart


Set VCount to RCRef.GetItemCount VarlaStoneDepleted

Set WCount to RCRef.GetItemCount WelkyndStoneDepleted


RCRef.RemoveItem VarlaStoneDepleted VCount

RCRef.RemoveItem WelkyndStoneDepleted WCount


RCRef.AddItem VarlaStone VCount

RCRef.AddItem WelkyndStone WCount


End

Do I need to add anything more to this?

Looks solid to me. Is that for the mod you were telling me about yesterday?

Link to comment
Share on other sites

Okay, got a problem. I've attached scripts to the varla and welkynd stones that should add "depleted" versions of the stones to the player's inventory when they're used. For some reason, the scripts aren't working right. If I have an enchanted weapon that isn't fully charged, selecting a varla stone re barges it but doesn't add the depleted stone. If I don't have anything that needs to be recharged, selecting a varla stone does add the depleted stone. That's definitely not what I want to happen. The script is:


Scn RVWSVarlaStoneScript


Begin OnEquip Player


Player.AddItem VarlaStoneDepleted 1


End

From what I understand, this should run whenever I select a varla stone in inventory, but in only runs if the stone is not used to recharge something. I get a similar problem with the welkynd stones. How can I fix this?

Link to comment
Share on other sites

You 'could' make a replacement varla stone, that is just an activativalte object within your inventory. But that has problems of its own.

I thought there were mods out there that dealt with varla stones, you might do a search and see if they did anything that is close to what you want. You coudl then look at how they got it to work.

Link to comment
Share on other sites

  • 2 weeks later...

I have a slight problem with my new WIP mod. I've placed a red welkynd stone in the center of a room. I've set up a trigger zone to make it fire at 8 targets in sequence, then all at once. I've got that part working. The problem is that it won't stop firing when the player is no longer in the trigger zone. I cobbled together the script from some I've seen around here:


scn DavavindaMultiFireTurretTrigZoneScript


float timer

short stoneState

short Triggered


begin onTrigger


     if  stoneState == 0

               set stoneState to 1

               set timer to 0

               set Triggered to 1

          endif

     endif


end


Begin Gamemode


   if stoneState > 0 && Triggered == 1

     set timer to timer + getsecondspassed

      if timer > 1.125 && stoneState == 1

         D03MultiFireStoneRef.cast StandardShockDamageTarget4Expert D03Targ01

         set stoneState to 2

      elseif timer > 1.25 && stoneState == 2

         D03MultiFireStoneRef.cast StandardShockDamageTarget4Expert D03Targ02

         set stoneState to 3

      elseif timer > 1.375 && stoneState == 3

         D03MultiFireStoneRef.cast StandardShockDamageTarget4Expert D03Targ03

         set stoneState to 4

      elseif timer > 1.5 && stoneState == 4

         D03MultiFireStoneRef.cast StandardShockDamageTarget4Expert D03Targ04

         set stoneState to 5

      elseif timer > 1.625 && stoneState == 5

         D03MultiFireStoneRef.cast StandardShockDamageTarget4Expert D03Targ05

         set stoneState to 6

      elseif timer > 1.75 && stoneState == 6

         D03MultiFireStoneRef.cast StandardShockDamageTarget4Expert D03Targ06

         set stoneState to 7

      elseif timer > 1.875 && stoneState == 7

         D03MultiFireStoneRef.cast StandardShockDamageTarget4Expert D03Targ07

         set stoneState to 8

      elseif timer > 2 && stoneState == 8

         D03MultiFireStoneRef.cast StandardShockDamageTarget4Expert D03Targ08

         set stoneState to 9     

      elseif timer > 2.125 && stoneState == 9

         D03MultiFireStoneRef.cast StandardFireDamageTarget4Expert D03Targ01

         D03MultiFireStoneRef.cast StandardFireDamageTarget4Expert D03Targ02

         D03MultiFireStoneRef.cast StandardFireDamageTarget4Expert D03Targ03

         D03MultiFireStoneRef.cast StandardFireDamageTarget4Expert D03Targ04

         D03MultiFireStoneRef.cast StandardFireDamageTarget4Expert D03Targ05

         D03MultiFireStoneRef.cast StandardFireDamageTarget4Expert D03Targ06

         D03MultiFireStoneRef.cast StandardFireDamageTarget4Expert D03Targ07

         D03MultiFireStoneRef.cast StandardFireDamageTarget4Expert D03Targ08

         set stoneState to 0

         set Triggered to 0

      endif

    endif

End


begin onReset


     reset3DState


end

From what I understand of scripting, that should make the stone stop firing after leaving the trigger zone but it doesn't. What do I need to change to make this work?

Link to comment
Share on other sites

  • 4 weeks later...

As my first foray into Oblivion modding, I'm trying to keep it simple by cloning a functional script from another mod (author expressly permitted this) and add it to a clothing mod. The basic functionality is simple: add the spell when the Player is Sneaking while wearing the scripted item of clothing, and remove it when not Sneaking.

I've made a copy of the clothing mod, renamed it to a unique filename but retained the internal EditorIDs because once I've worked out the HOW, I plan add it to the original clothing mod (not for redistribution) so it will keep being sorted by BOSS.

So far I have created a new "Chameleon" Ability Spell (75 magnitude, 0 duration, 0 cost: which I believe makes it "constant effect") to duplicate the one called in the script but with a new name (to avoid dependency on a second mod). I've adapted the original script to be a little more generic and added it to a couple of clothing items. The script compiles, and I got it to put out a simple message, but the spell never shows up in the list of active effects when Sneaking.

Here's the original functioning code:


Scn THShadowShield


Begin Gamemode

  if player.isSneaking == 1 && player.getEquipped THShadowCuirass == 1

    player.addspell THKameleontti

  elseif player.isSneaking == 0 || player.getEquipped THShadowCuirass == 0

    player.removespell THKameleontti

  Endif

End

And here is my adaptation:

Scn KCShadowNinjutsu


ref   refThisGear   ; Object Reference Variable: When uninitialized, references scripted object


Begin Gamemode

; Processes every frame

  set refThisGear to getSelf

  If refThisGear != 0

  ; reference has been set

    If ( player.isSneaking == 1 && player.getEquipped refThisGear == 1 )

      player.addspell KCFadeNinjutsu

      ; KCFadeNinjutsu is an Ability Spell added by the parent mod

    ElseIf ( player.isSneaking == 0 || player.getEquipped refThisGear == 0 )

      player.removespell KCFadeNinjutsu

    ; Else Do Nothing

    Endif

  Else

    Message "No gear reference", 1  ; Debug message

  EndIf

End

So, where have I gone wrong? It looks like I'm failing to get a valid reference for the scripted object. If this "mod object" is considered a 'dynamic object', what am I supposed to use to get the reference?

-Dubious-

Link to comment
Share on other sites

Hmm, my guess is you can't get the reference of an object inside a container. Since the object is in the players inventory (player is a container) the reference would not be valid.

That would be one reason why the original script has it hard coded to the object reference.

But, have you put a message where your adding and removing the spell, to make sure its hitting that code?

If its hitting that code, then there is something wrong with your spell. You might try simply adding the spell to the player and see if it works.

Link to comment
Share on other sites

Hmm, my guess is you can't get the reference of an object inside a container

...

But, have you put a message where your adding and removing the spell, to make sure its hitting that code?

Good point. Added messages to each conditional section of code that adds or removes the spell. Tested by equipping a scripted item of clothing, and I get the "No Gear reference" message immediately. Toggle on Sneak mode, but the message never changes despite waiting about a minute in case there is a stacked buffer of messages. Remove the clothing and the "no gear ref" message disappears.

So despite the clothing object being equipped, it seems pretty conclusive that I am failing to get the reference. (And the intent is that it should not take effect until BOTH worn AND sneaking, so not having a valid reference when it is in inventory is expected of the design.)

I suppose I could make the "worn" conditional into a OR for the EditorID of each scripted object, but that doesn't teach me the reference lesson. So I would like to pursue that angle.

Thanks for the response.

Edit: After doing some more digging, I wonder if this wouldn't work better as an OnEquip and OnUnequip block pair? Complete rewrite of course, and I still need to learn why this doesn't work. But a better approach, I think. Ack, no! OnEquip only runs once. Might be used to kick this off, but chaining scripts is more advanced than I'm comfortable with at this point. (Can you have more than one block in a script? Edit: Answer: yes you can. This is actually the approach that eventually worked. See next post.)

Edit2: Now I'm wondering if the problem lies with the clothing mod I'm using. After reading some more about persistent objects, I thought the way I was testing might be causing my problems. I had been using "player.additem" to put it directly into my inventory, so I wondered if I needed to drop out of inventory and pick it up again to give it persistence. But when I did that, it appeared in mid-air in "crucifix" layout and could not be activated or grabbed. So I fast travelled to the container location and got it from there, but when I dropped it out of inventory, again with the unaccessible crucifix.

Edit3: Answer to the "crucifix" is that the original mod is missing the "*_gnd.nif" files in the "World" NIF file slot. With that, the mod items can be dropped and grabbed, apparently unrelated to "persistence".

-Dubious-

Edited by dubious
Link to comment
Share on other sites

Well, I got my script working. But only after I worked out a different approach alluded to in my first edit which did not require me to determine an ID for the object. It appears despite the container being marked Persistent, the items from it are still considered dynamic. At least, I was never able to get an ID other than zero. Does anyone have a method to get that? I see several functions in OBSE that initially seem to be aimed to that end, but they all seem to require you to know the EditorID ahead of time. I couldn't find anything that would get me either the Editor or Base ID for a dynamic object without knowing one or the other beforehand, so that is still a mystery to unravel. Anyway, here is what worked for me:


Scn KCShadowNinjutsu


short sDBug           ; Flag for DeBug messages

short sIsEquipped     ; Flag for GameMode section processing


Begin OnEquip player

; Doesn't activate if item is broken.

  set sIsEquipped to 1

  If sDBug == 1

    Message "KCShadowNinjutsu item equip detected.", 1

  EndIf

End


Begin Gamemode

; Processes every frame

  If sIsEquipped == 1

    If player.isSneaking == 1

      player.addspell KCFadeNinjutsu

      ; KCFadeNinjutsu is an Ability Spell added by the parent mod

    Else

      player.removespell KCFadeNinjutsu

    Endif

  ; Else Do Nothing

  EndIf

End


Begin OnUnequip player

; Doesn't activate if item is broken.

  set sIsEquipped to 0

  If sDBug == 1

    Message "KCShadowNinjutsu item unequip detected.", 1

  EndIf

End

Edit: Removed erroneous reference that OBSE was required, left over from earlier attempts.

It meets my design goals of being 'generic' enough to work without modification when attached to any suitable item. It doesn't deal with the issues if the item gets broken, but since I am only planning on attaching it to non-armor for the moment, I'm going to leave that as an exercise for the future. Hopefully this will help someone else through the learning curve in the future.

-Dubious-

Edited by dubious
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...