Author Topic: Spell Hook or script replacement?  (Read 394 times)

Legacy_Tassie Wombat

  • Jr. Member
  • **
  • Posts: 78
  • Karma: +0/-0
Spell Hook or script replacement?
« on: February 02, 2011, 05:53:24 am »


               I have a new script to change the TimeStop spell.   It's quite a complicated script and I am unsure of the best place to put it.   I'm sure one of you can tell me where to stick it  :innocent:


Should I simply save it as "nw_s0_timestop" thereby replacing the default script (I think) ... or should I add the script contents to my spell hook script?

Cheers,
Wombat
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Spell Hook or script replacement?
« Reply #1 on: February 02, 2011, 06:11:01 am »


               replace it. then compile it.
               
               

               
            

Legacy_Tassie Wombat

  • Jr. Member
  • **
  • Posts: 78
  • Karma: +0/-0
Spell Hook or script replacement?
« Reply #2 on: February 02, 2011, 06:31:08 am »


               Thanks for the quick response Lightfoot8 '<img'>
               
               

               
            

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
Spell Hook or script replacement?
« Reply #3 on: February 02, 2011, 10:00:42 am »


               Its 6 of one, half a dozen of the other.



Spell-Hooks - contains all your spell scripts in a single script - the code in the hook script, gets executed before the default spell code. (Unless you call the SpellScriptOveride function - in which case this exits the spell early) This is potentially useful, because it means you dont need to replicate the whole spell script if you are just trying to do something like assigning a local var to the spell target.



Spell-Scripts - These allow you a bit more customization, at the cost of having the code for each spell, contained in the script for that spell. Not always a good idea, because if you are editing 30+ spells, thats 30 scripts all over your module that you have to keep track off.





I would go with Spell-Hooking, over script changes, purely just because its easier to manage.

Granted, scripts do have a size restriction, but there are ways to get around that if you use ExecuteScript



Eg -

Some people index their spellhook script alphabetically, or perhaps by Spell Index Number

if the Spell number is between 1-50  - ExecuteScript()  on 'spell_hook1'  

if the spell number is 51-100 - ExecuteScript on 'Spell_hook2'





Its purely up to the coder, but alot of these principles are useful, and mirror concepts used in some professional coding standards.



Funky even uses a sort of Index system/Look-Up table for Sim-Tools for the very large case/if statement he uses for parsing the commands.

He uses the FindSubstring function, to find out where the first letter of the command, comes in the string

'abcdefghijklmnopqrstuvwxyz' etc,

and this then produces a number,

Allowing him to have all the 'A' functions, beside eachother, all the 'B's together etc.
               
               

               
            

Legacy_The Fred

  • Newbie
  • *
  • Posts: 46
  • Karma: +0/-0
Spell Hook or script replacement?
« Reply #4 on: February 02, 2011, 04:06:39 pm »


               In this case, where it seems you are modifying only a single script in a way very specific to that spell, simply overriding the script is probably best. Spellhooking is awesome and very powerful, but it's more for sweeping changes to spells (e.g. whenever *any* spell is cast, do this, etc).
               
               

               
            

Legacy_Tassie Wombat

  • Jr. Member
  • **
  • Posts: 78
  • Karma: +0/-0
Spell Hook or script replacement?
« Reply #5 on: February 03, 2011, 02:45:12 am »


               Thanks for the further info.  



At this stage my spell hook is only making a small change to my Raise Dead and Resurrection spells to remove my death variable.  I only figured out how to do this a couple of days ago ... but felt comfortable with that.



The TimeStop spell on the other hand is a whole lot more complex and confusing.   I think at this stage I will replace the whole script for the TimeStop.   Maybe later when my scripting experience increases and I feel comfortable with altering that script I might move it to the spell hook.



Thanks again,

Wombat
               
               

               
            

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
Spell Hook or script replacement?
« Reply #6 on: February 03, 2011, 10:40:55 am »


               

The Fred wrote...

In this case, where it seems you are modifying only a single script in a way very specific to that spell, simply overriding the script is probably best. Spellhooking is awesome and very powerful, but it's more for sweeping changes to spells (e.g. whenever *any* spell is cast, do this, etc).

True, it does 'allow' this, but in my opinion, it is easier to edit 1 script, to modify dozens of spells, rather to open dozens of scripts to edit dozens of spells.

The only limitation to spell hook scripts, is the size of the script file, and this can by bypassed via execute script.
               
               

               
            

Legacy_The Fred

  • Newbie
  • *
  • Posts: 46
  • Karma: +0/-0
Spell Hook or script replacement?
« Reply #7 on: February 03, 2011, 08:12:16 pm »


               Yes but it's also messier to have one script do dozens of completely different things when each spell already has its own spell script. I love spellhooking, but when you're just changing a single spell, it seems kind of pointless. If you wanted to change a group of spells (say, all the Summon Creature spells) etc, or to funnel multiple spells through the same logic, this would by far be the best way to do it. For a single spell, though, there's no downside to using the spellscript, but there is the upside (however trivial) of order and readability.
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Spell Hook or script replacement?
« Reply #8 on: February 03, 2011, 08:33:07 pm »


               

The Fred wrote...

...to change a group of spells (say, all the Summon Creature spells) etc, or to funnel multiple spells through the same logic...

There is another technique and I think that still better than spellhook. Changing (server-side only needed) spellscripts of multiple spell to one same, where this will be solved.

Spellhook seems to me good only for conditions where spells cannot be cast, for "wild" magic zones or other ideas where you don't want run the original spellscript.

I can't imagine (well I can, but I don't see any logic or advantage of it, only downsides) how would anyone changed lets say damage in spell using spellhook...
               
               

               


                     Modifié par ShaDoOoW, 03 février 2011 - 08:34 .
                     
                  


            

Legacy_The Fred

  • Newbie
  • *
  • Posts: 46
  • Karma: +0/-0
Spell Hook or script replacement?
« Reply #9 on: February 04, 2011, 07:35:11 pm »


               Changing the spellscripts to a single one works just fine, but requires 2da editing. From a purely scripting, hak-less sense, spellhooking is probably the way to go. As you say, tweaking an existing script makes more sense in the spellscript, though. Spellhooking is great when you want conditional things to happen, e.g. Wild Magic, as you mentioned, or perhaps guards attacking somewhere magic is outlawed, making goblins run away because they're scared etc. - anything which happens for multiple spells, or which happens for some condition which does not depend on the spell cast.
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Spell Hook or script replacement?
« Reply #10 on: February 04, 2011, 07:52:54 pm »


               Yeah, one more thing that would be possible via spellhook came into my mind - spell turning '<img'>
               
               

               
            

Legacy_The Fred

  • Newbie
  • *
  • Posts: 46
  • Karma: +0/-0
Spell Hook or script replacement?
« Reply #11 on: February 05, 2011, 10:30:36 am »


               I might actually, though there are certain limitations. You'd have to flag all areas as "wild magic" areas so that spellhooking affects NPCs (BioWare didn't think that people might actually want to use the awesome potential of the system they built, it seems) and there might be issues with casting spells back. Also the spellhooking would only happen when a spell is cast on a specific person, not when it strikes them via Area-of-Effect, though I guess that makes a certain sort of sense.
               
               

               
            

Legacy_spool32

  • Jr. Member
  • **
  • Posts: 57
  • Karma: +0/-0
Spell Hook or script replacement?
« Reply #12 on: February 11, 2011, 04:16:29 pm »


               There are entire Spellhooking systems available for use... you might consider using a pre-built system rather than trying to roll your own.