View previous topic :: View next topic |
Author |
Message |
the.gray.fox
Joined: 11 Dec 2009 Posts: 21
|
Posted: Thu Apr 08, 2010 16:10 Post subject: How to hook core functions in nwscript.nss? |
|
|
Hello.
Some time ago there was a page written by G. Zoeller about how to hook the core functions defined in nwscript.nss
I did read it once, but never used that knowledge. So I forgot it.
Recently I seek the page again, and I find it... but the link does not seem to work anymore. Even the google cache is gone.
(here: http://web469.can05.de/doku.php/nwn/how_to_override_core_scripting_functions?DokuWiki=ejpfedgyon)
So I try to do things by what little memory I can salvage from my brain.
But the moment I save nwscript, even without changes over the original, the compiler pops an error at line #11 (where the first #define is met).
Always line #11 -- regardless of what I do. Even if I comment it, the parser still reads it and raises the error!
(too much hardcoding in nwn. it is no work you expect from professionals, might I say)
So my attempts to do stuff with nwscript are ended prematurely.
But I browse again the www, and find this link in which the author explains how the hooking of core functions is done.
(here: http://nwvault.ign.com/fms/Download.php?id=126646)
To my surprise he has no problem to alter nwscript and save it, locally, into his module.
Perhaps I have not read it properly -- English is not my first language.
Or maybe I did... and nwscript was made un-hook-able with the last patch?
But I find no official word to confirm or deny it.
So I am left with the doubt. Can someone clear it for me?
Thanks.
-fox |
|
Back to top |
|
|
ShaDoOoW
Joined: 20 Aug 2005 Posts: 584
|
Posted: Thu Apr 08, 2010 16:52 Post subject: |
|
|
Or maybe author's (me) english is not good hehe.
It works even in patch 1.69. I don't know what you overlooked but try:
- do not use #include "nwscript"
- avoid adding constants to nwscript.nss
- give nwscript.nss into hak or override (but i have it in module too without problems)
- try PRC compiler (that way you have to have it in override, but othewise no problems, but Im able to compile it in bioware compiler as well)
Or maybe you just getting this compile error in nwscript.nss file itself? As include file it won't compile, thats normal. _________________ Community Patch / NWNX Patch / NWNX Files / NWNX Connect |
|
Back to top |
|
|
the.gray.fox
Joined: 11 Dec 2009 Posts: 21
|
Posted: Thu Apr 08, 2010 17:49 Post subject: |
|
|
Ah, perfect!
Thank you for replying me.
I do not know what I am doing wrong.
And there is no room for errors, I think.
I am stopped at the first step: to see if I can have a nwscript.nss local to my module at all.
What I did:
1) open nwscript in script editor (tick the "all resources" filter)
2) save nwscript as-is. Absolutely no change done to it.
And it gives me INVALID DECLARATION TYPE, at line #11.
I am using patch 1.69, english.
But your suggestion is good.
I will take the most recent nwscript from the BIFs and modify it offline.
Then I will place it in override.
Maybe if it does not pass through the script editor the error will go away?
-fox |
|
Back to top |
|
|
ShaDoOoW
Joined: 20 Aug 2005 Posts: 584
|
Posted: Thu Apr 08, 2010 19:29 Post subject: |
|
|
Well that error is normal, your script editor uses "Automatically compile on save" so when you save it you got compile error as nwscript is not only include file but engine file.
Thats OK, try to compile any other script, do you getting this error too? _________________ Community Patch / NWNX Patch / NWNX Files / NWNX Connect |
|
Back to top |
|
|
the.gray.fox
Joined: 11 Dec 2009 Posts: 21
|
Posted: Fri Apr 09, 2010 16:07 Post subject: |
|
|
You are most correct.
The little problem is solved and I can modify nwscript now.
But things do not work as I expected.
I can rename a core function, but then I need to manually add my include to every script in which that core function appeared with her former name.
It kind of defeats the usefulness of renaming the core functions.
In any case -in fact- I will have to manually add an include to all scripts using that core function.
It is still useful to generate syntax errors to seek out all occurrences of that core function in your scripts (a text search would not seek inside includes external to the module. But syntax errors will reach every corner).
I am disappointed.
I tried to append function definitions and implementations to nwscript.
They compile with no problem. But they raise an INVALID COMMAND error at runtime.
Placing a null terminating character (0x00) in front of my appended code (at the end of nwscript) will successfully hide my code to the script editor (stupid editor reads the .nss file as a null terminated string).
But the code still compiles and raises the error at runtime (the parser reads the .nss as a file, bypassing any nullchar).
I was hoping to find a way to "detach" my code from nwscript (as far as the compiler is concerned), yet have my code publicly available by virtue of being physically within nwscript.nss
Failure, of course...
But maybe someone with more insight on these matters can find a work-around?
-fox |
|
Back to top |
|
|
ShaDoOoW
Joined: 20 Aug 2005 Posts: 584
|
Posted: Sat Apr 10, 2010 0:44 Post subject: |
|
|
Yes you need special include, but lets say for spell scripts you dont have to, all of them got x2_inc_spellhook so you add it there and compile (and then remove changed nwscript from module and give compiled spells to override)
I made a one little and simple program which will add #include "yourinclude" into 1line of all *.nss in folder, yo can download it here: http://nwvault.ign.com/View.php?view=Other.Detail&id=1354
Also some advanced text editors (linux mostly) can do that.
Then for all new scripts I add that line manually, no big deal.
So when you need some include, you dont need to append nwscript file, you will give it into that new include.
btw I share with you my OnDelevel event workaround
Code: |
void SetXP(object oCreature, int nXPAmount);
void SetXP(object oCreature, int nXPAmount)
{
if(nXPAmount<1)nXpAmount = 1;//never lower PC xp below 1 - new char check
int nLevel = GetHitDice(oCreature);
int nNew = FloatToInt(0.5+sqrt(0.25+(IntToFloat(nXPAmount)/500)));
CORE_SetXP(oCreature,nXPAmount);
if(nNew < nLevel)
{
ExecuteScript("ev_scr_delevel",oCreature);
}
}
|
_________________ Community Patch / NWNX Patch / NWNX Files / NWNX Connect |
|
Back to top |
|
|
the.gray.fox
Joined: 11 Dec 2009 Posts: 21
|
Posted: Sat Apr 10, 2010 2:52 Post subject: |
|
|
Hello.
I myself have no problem with adding one extra include wherever needed.
But my current project needs to hook nearly every module event.
I also need to detect when a LevelDown occurs (just like you do).
And the use of ForceRest() does not trigger the resting sub-events.
I plan to distribute my package when complete, and I was hoping to find a solution that would not force the users to manually modify all their scripts in which SetXP() and ForceRest() are called.
Not only that is a tedious task, and prone to errors, but it may scare away a neofit scripter.
But looks like I must surrender.
Lot of manual edits may be required, and I can not do a thing to simplify the situation.
-fox |
|
Back to top |
|
|
ShaDoOoW
Joined: 20 Aug 2005 Posts: 584
|
Posted: Sat Apr 10, 2010 9:08 Post subject: |
|
|
Best you can do is to make your own instalation program which will change event scripts and merge the current into new one (PRC had something like that) and which will go through all the scripts in the module and add extra line at the top (if its not there) and possible all of this without need to open module. It would't be so simple but if you want your project to be user friendly this is the only way, otherwise you have to surrender it. I must admit that even with this solution its quite problem for begginers to instal any such script system. _________________ Community Patch / NWNX Patch / NWNX Files / NWNX Connect |
|
Back to top |
|
|
|