Author Topic: How to add custom scripts to a hak pak?  (Read 664 times)

Legacy__Guile

  • Hero Member
  • *****
  • Posts: 1308
  • Karma: +0/-0
How to add custom scripts to a hak pak?
« on: April 27, 2012, 05:28:34 pm »


               I need to take base nwn spells, which I've modified, and add them to a custom hak pak which I will create...

Also I need a suggestion on what to name this hak pak, as it will include JUST edited base spells...
The actual includes that control ALL spells will be in the module for adjusting...


So how would I go about adding the spell scripts to the hak pak?
               
               

               
            

Legacy_Alex Warren

  • Sr. Member
  • ****
  • Posts: 326
  • Karma: +0/-0
How to add custom scripts to a hak pak?
« Reply #1 on: April 27, 2012, 06:48:19 pm »


               This will not work, because resources in haks can't be edited in toolset. So even though this will allow to modify includes it won't be possible to recompile the spell scripts (the module will always use files from hak first)

You'll have to put all your scripts in an erf file. Or you could make your scripts read settings form 2da or variables set on module.
               
               

               


                     Modifié par Alex Warren, 27 avril 2012 - 05:54 .
                     
                  


            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
How to add custom scripts to a hak pak?
« Reply #2 on: April 27, 2012, 07:57:39 pm »


               As Alex said, giving scripts to hak is possible but very poor choice. (Of course you can tell user that if he wants to change those scripts he have to delete them from this hak. If its so important.)

Changing 2das neither spellhook wont help you however, since you still need these scripts to import somehow to the module afterall. ERF is the best choice for this purpose.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
How to add custom scripts to a hak pak?
« Reply #3 on: April 28, 2012, 12:26:05 am »


               

_Guile wrote...

So how would I go about adding the spell scripts to the hak pak?



It seems like everyone wants to play _Gile and give advice instead of answering the question.   LoL.

So l try and not give advice and just answer the question.   Well at least one answer to the question, For there are many ways you could go about adding you spells to a Hak Pack.   If you have all of your spells  compiled in one module, you could just export them into an ERF and then change the extention of the .erf to .hak. 

A Hak Pack is really nothing more then a ERF file with a .hak extention. 

For that matter the module itself is nothing more then an ERF file with a .mod extention.   So you could rename the extention on module from .mod to .hak. Then open it with the hak utility that shiped with the game ad delete everything except your spell scripts from the Hak.  

Or  when you open a module with the toolset, all of the files in the .mod ERF file are unpacked into a folder called temp0 located in the modules folder.  You could just get all of you spell scripts out of that folder and pack them into a hak with the utility that shipped with the game. 

Oh well, I guess I gave three way.  
               
               

               


                     Modifié par Lightfoot8, 27 avril 2012 - 11:27 .
                     
                  


            

Legacy__Guile

  • Hero Member
  • *****
  • Posts: 1308
  • Karma: +0/-0
How to add custom scripts to a hak pak?
« Reply #4 on: April 28, 2012, 04:51:34 pm »


               Thanks Lightfoot8...

So if I put the spells in the hakpak, and left the actual configuration scripts in the module / erf (for importing), the spells would stay the same, but the user could still modify the configuration scripts..

Therefore the hak pak would contain only the spells & the module would have the actual configuration scripts for editing...

This would work correct?

I wanted to put the spells in a Hak Pak for 1 reasons, and that is to reduce the # of scripts in the module, so that builders could simply add the spell system without cluttering their scripts with a bunch of nw_s0 / x2_s0 scripts...

If that's not feasible, then no big deal, as I don't mind the script count personally, I have modules with over 2000+ scripts.. (as long as you use naming conventions it's not a problem)...  
               
               

               


                     Modifié par _Guile, 28 avril 2012 - 03:54 .
                     
                  


            

Legacy_The Amethyst Dragon

  • Hero Member
  • *****
  • Posts: 2981
  • Karma: +0/-0
How to add custom scripts to a hak pak?
« Reply #5 on: April 28, 2012, 07:14:14 pm »


               Brief overview of how scripts & includes work, with relations to haks, at least as I understand it...

spell script - covers all of the functions of a spell, may link to one or more "include" scripts for additional functions and/or constants
include - holds functions and/or constants for easier coding of multiple scripts

Normal process:

1. enable use of an "include" in a spell script by adding it to the top
#include "myincludefile"
2. write spell script, probably referencing one or more functions/constants from the include
3. save and compile spell script
- encodes entire spell script and used portions of include to the compiled script file (.ncs)
- saves script source file for future editing (.nss)

Any changes to an include file are not automatically applied to a compiled script!  The script has already been compiled, using the previous version of the include functions/constants.

If changes are made to an included function/constant, each spell script that uses that must be re-compiled for the changes to take effect.

When a script is placed in a hak, that script basically becomes unchangeable while it's in the hak.  If an included function/constant used by the hak-stored script is changed, the script files need to be extracted from the hak and added back to the module resources (so they can be changed/updated), recompiled with the updated include (so the changes will be included in the compiled scripts), then the compiled scripts get added back to the hak.

Hak-stored scripts are great...as long as you don't plan on changing anything about those scripts (including the "include" functions/constants).
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
How to add custom scripts to a hak pak?
« Reply #6 on: April 28, 2012, 07:19:49 pm »


               

_Guile wrote...

Thanks Lightfoot8...

So if I put the spells in the hakpak, and left the actual configuration scripts in the module / erf (for importing), the spells would stay the same, but the user could still modify the configuration scripts..

Therefore the hak pak would contain only the spells & the module would have the actual configuration scripts for editing...

This would work correct?


 Nope,  AD above did a good job of explaining why It will not work.  
               
               

               
            

Legacy_ShadowM

  • Hero Member
  • *****
  • Posts: 1373
  • Karma: +0/-0
How to add custom scripts to a hak pak?
« Reply #7 on: April 28, 2012, 07:46:11 pm »


               You can just take erf file of your scripts and drop it into nwhak remove ExportInfo file and save it, then you good to go. If you keep a base module that you making changes too script and includes then compile them you pop open the hak file overwrite files with the new compiled files, remove ExportInfo file and save, Like everyone has said though putting scripts into hakpaks is good for scripts that your not going to change. If the script is referring to numbers in configuration script then it should still work.  If the hakpak script is looking for a specific number like a module int and you change that module int it will apply the change. As for example of putting spell scripts in hakpaks here a link to one.
Link
               
               

               


                     Modifié par ShadowM, 28 avril 2012 - 06:46 .
                     
                  


            

Legacy__Guile

  • Hero Member
  • *****
  • Posts: 1308
  • Karma: +0/-0
How to add custom scripts to a hak pak?
« Reply #8 on: April 28, 2012, 08:10:20 pm »


               Great help guys, thanks....

I'll just leave the spell scripts in the module, wouldn't be much of a problem to ignore those prefixes anyway (nw_s0 / x2_s0 / etc), just means more scripts to rummage through...

I ran into some major problems, but I'll post that in the scripting forums, thanks again everyone.