Jump to content

A ring that adds a spell...


Huglarh

Recommended Posts

Good day folks, ive been tinkering around and i cant find a way to make a script that adds the spells when i equip a ring, but when removing it, it would remove the spell.

 

I know how to add them but i do not know a Script set i can use?

 

Can anyone provide a Script i can use? I learn faster if i were to see a example~

Link to comment
Share on other sites

Create an object script with this code:

scn SCRIPTNAME

Begin onEquip
  Player.addspell SPELL1
  Player.addspell SPELL2
  ...
End

Begin onUnequip
  Player.removespell SPELL1
  Player.removespell SPELL2
  ...
End

Replace SCRIPTNAME with a name of your choice

Replace SPELL1, SPELL2, etc... with the Name/ID of the spells

Attach this script to the ring

Edited by forli
Link to comment
Share on other sites

Create an object script with this code:

scn SCRIPTNAME

Begin onEquip
  Player.addspell SPELL1
  Player.addspell SPELL2
  ...
End

Begin onUnequip
  Player.removespell SPELL1
  Player.removespell SPELL2
  ...
End

Replace SCRIPTNAME with a name of your choice

Replace SPELL1, SPELL2, etc... with the Name/ID of the spells

Attach this script to the ring

 

Thanks so much, can you help me with a Delimma in one of my topics, for exp Tokens? ^_^;

Link to comment
Share on other sites

Questions:

 

scn ringscript

 

array_var spells1

array_var spells2

 

ref spellref

 

short index

 

Begin OnEquip

 

let spells1 := Player.GetSpells

RunScriptLine "PlayerSpellBook"

let spells2 := Player.GetSpells

let index := 0

while (index < ar_Size spells2)

let spellref := spells2[index]

if eval (ar_Find spellref spells1)

ar_Erase spells2 index

Continue

endif

let index += 1

loop

 

End

 

Begin OnUnequip

 

while (0 < ar_Size spells2)

let spellref := spells2[0]

Player.RemoveSpell spellref

ar_Erase spells2 0

loop

 

End

 

Will this work in making the ring have all spells, then removing them takes them?

Link to comment
Share on other sites

The post was edited to reflect actual testing, the previous comment about the "continue" instruction becomes invalid since not performing the increment is indeed what is expected, was in the condition the mistake.

 

BUT

 

you should not do that PlayerSpellBook. Depending on the mods the list can be above 2000 spells (mine has 2590) and many of them aren't meant to be on players inventory. This securely will freeze the game as soon you try to open the spells menu.

 

In time: use the "code" and "/code" encased in brackets to post codes, like in the post above your last.

 

There is an error in the test, to work with the array as you intend it should be:

scn ringscript

array_var spells1
array_var spells2

ref spellref

short index

Begin OnEquip
  let spells1 := Player.GetSpells
  RunScriptLine "PlayerSpellBook"
  let spells2 := Player.GetSpells
  let index := 0
  while (index < ar_Size spells2)
     let spellref := spells2[index]
     if eval (ar_Find spellref spells1) != -99999.0
        ar_Erase spells2 index
        Continue
     endif
    let index += 1
  loop
End

Begin OnUnequip
  let index := ar_size spells2
  printC "array size %.2f", index, 1
  while (0 < ar_Size spells2)
     let spellref := spells2[0]
     Player.RemoveSpell spellref
     ar_Erase spells2 0
  loop
  let index := ar_size spells2
End

 

I must insist that trying to access the spells menu while the ring is equipped will freeze the game. But now the unequip works and keeps the player's original spells intact.

 

You can verify it placing some PrintToConsole commands to follow what is happening. This one allow you see the name of the spell being deleted:

...
let spellref := spells2[0]
Player.RemoveSpell spellref
printc "deleted %n", spellref, 1
...

The console command TDT can be used while debugging, everything printed to console is immediately seen.

Edited by nosisab
Link to comment
Share on other sites

I agree with nosisab. You shouldn't use PlayerSpellBook. It would add all the spells in the game to the player. I doubt it would actually freeze the game when you check your spell menu, but it will be very very laggy.

 

And the original code was missing something like

 

if eval (ar_Find spellref spells1) >= 0

 

but nosisab fixed it. :thumbsup:

Link to comment
Share on other sites

fg109, I'm telling from "experience" ... :)

 

I made a simple mod creating the ring and placed the script on it... and it freezes (or at least takes a huge amount of time which is the same from the player stand point) when trying to "playerSpellBook" ... both using the ring or just using the console command... and it returns 2590 spells were added to my book (no kidding).

 

using PrintC commands I was able to follow the script worked (after correcting the test) and I got the expected value... and the unequip removed all the previously given spells and kept those I already had. Notice I tested it in a early save where the character was green and had few spells in its book.

 

In non heavily modded games it may work, for sure it works in vanilla game, but I have OOO, COBL and Midas Magic among others and I have reasons to believe most mod's users will have similar or worst scenery... like the entire FCOM etc...

 

Actually I posted in this thread because I find the original script very creative and this thread can be good tutorial for scripting beginners. All the credits for it go to the OP.

 

PS: Occurred me just Now

 

There is an inherent danger in this approach... I'm not sure the array will be saved on savegame and so will fail when reloading from a save with the ring already equipped. If so it could be solved keeping the array in a VariablesQuestScript, but I can't state it surely without testing (besides there are some dangers with dynamic changing variables in quest scripts).

 

(Edit: this will fail)..."Another possible solution would be testing if the game is fresh loaded or restarted and if the ring is already equipped, force the unequip and reequip to refresh the array. This is done once by game reload/restart and is quick enough to pass unperceived by the player even with big arrays."

 

PPS: the above approach fails... the player's book will be seen as having the full specter since there is no spells2 to work with... well, I let the real solution to reader's imagination :) (hint: saving the original player's book in a "safe place" and hopping she doesn't change it in the meanwhile).

 

This kind of thing must be carefully weighted before making public release. People can get angry if some their beloved and hardly achieved spells just vanish or get stuck with all that dump in the book.

Edited by nosisab
Link to comment
Share on other sites

fg109, I'm telling from "experience" ... :)

 

I made a simple mod creating the ring and placed the script on it... and it freezes (or at least takes a huge amount of time which is the same from the player stand point) when trying to "playerSpellBook" ... both using the ring or just using the console command... and it returns 2590 spells were added to my book (no kidding).

 

using PrintC commands I was able to follow the script worked (after correcting the test) and I got the expected value... and the unequip removed all the previously given spells and kept those I already had. Notice I tested it in a early save where the character was green and had few spells in its book.

 

In non heavily modded games it may work, for sure it works in vanilla game, but I have OOO, COBL and Midas Magic among others and I have reasons to believe most mod's users will have similar or worst scenery... like the entire FCOM etc...

 

Actually I posted in this thread because I find the original script very creative and this thread can be good tutorial for scripting beginners. All the credits for it go to the OP.

 

PS: Occurred me just Now

 

There is an inherent danger in this approach... I'm not sure the array will be saved on savegame and so will fail when reloading from a save with the ring already equipped. If so it could be solved keeping the array in a VariablesQuestScript, but I can't state it surely without testing (besides there are some dangers with dynamic changing variables in quest scripts).

 

(Edit: this will fail)..."Another possible solution would be testing if the game is fresh loaded or restarted and if the ring is already equipped, force the unequip and reequip to refresh the array. This is done once by game reload/restart and is quick enough to pass unperceived by the player even with big arrays."

 

PPS: the above approach fails... the player's book will be seen as having the full specter since there is no spells2 to work with... well, I let the real solution to reader's imagination :) (hint: saving the original player's book in a "safe place" and hopping she doesn't change it in the meanwhile).

 

This kind of thing must be carefully weighted before making public release. People can get angry if some their beloved and hardly achieved spells just vanish or get stuck with all that dump in the book.

 

Hehe. Thanks.

 

And it wont be publically released if it'll cause this problem xD

 

To be honest i wondered if it were possible. and its for a friend :)

 

Thanks so much for your help ^_^

Link to comment
Share on other sites

  • Recently Browsing   0 members

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