Aller au contenu

Photo

Include Scripts


  • Veuillez vous connecter pour répondre
10 réponses à ce sujet

#1
Lucan Silverhand

Lucan Silverhand
  • Members
  • 27 messages
I am looking to create an include script to add new parameters for new skills to the game.
I have tried just adding them to nwscript.nss, but it will not compile correctly. I did a bit of searching and read that it was better to just create an include file, but I've never made one before and don't know how they work.
I want to be able to create checks for my new skills. So far I've created a new ginc_param_const script with them added to it, which compiled successfully.

I'd added the line to the nwscript:
int SKILL_BALANCE =30;

for a skill example.

Any help is appreciated.

#2
Shallina

Shallina
  • Members
  • 1 011 messages
No main in include, only function.

#3
Morbane

Morbane
  • Members
  • 1 883 messages
an include file can be anything you want to remain static (even dynamic alogrithms) to be referencable with just a # "include".

I have one for my Feat constants to match the 2da row, and another with 30 helper functions.

#4
Lucan Silverhand

Lucan Silverhand
  • Members
  • 27 messages
I found out you don't have to edit nwscript or even create an include, but now I've got the skills showing as they should I have another problem which relates to it. I added the new skills to the ginc_param_const script and now have found that ga_local_int (which sets an integer value) which includes ginc_param_const fails to work as long as the param_const script is in use. I have no idea why this is as the only thing I changed from the script was to add the skill parameters.

#5
Morbane

Morbane
  • Members
  • 1 883 messages
You really shouldnt edit the game scripts unless you really know what you are doing. The ginc_** etceteras need to work with many other scripts, you may never notice until it is too late - but you did notice and you know what happens now.

#6
_Knightmare_

_Knightmare_
  • Members
  • 643 messages
Once you edit an include script and compile it, you need to recompile ALL other scripts that call on that include file (or more specifically all the ones that call on the edited function in the include file). So, given the choice, you may want to make your own. Check out my tutorial linked in sig below. There is a section in there on making your own include script files. You can also declare stuff before the void main() of a regular script and skip making a seperate include.

#7
Lucan Silverhand

Lucan Silverhand
  • Members
  • 27 messages
Thanks Knightmare, your tutorial has been helpful. However I am still having issues with gc_skill_rank. Where am I going wrong? Whenever I try to add my new include (which compiles successfully, taken directly out of param_const with additions) to skill_rank it will not compile including the new include claiming it has a function definition missing a name (on an unused line).

my inc_skills file

///////////////////////////////////////////////////////////
// Function Definitions
///////////////////////////////////////////////////////////


// Return constant value for skill n
// Used in gc_skill_dc, gc_skill_rank
int GetSkillConstant(int nSkill)
{
int nSkillVal;

switch (nSkill) 
{
case 0: // APPRAISE
nSkillVal = SKILL_APPRAISE;
break;
case 1: // BLUFF
nSkillVal = SKILL_BLUFF;
break;
case 2: // CONCENTRATION
nSkillVal = SKILL_CONCENTRATION;
break;
case 3: // CRAFT ALCHEMY
nSkillVal = SKILL_CRAFT_ALCHEMY;
break;
case 4: // CRAFT ARMOR
nSkillVal = SKILL_CRAFT_ARMOR;
break;
case 5: // CRAFT WEAPON
nSkillVal = SKILL_CRAFT_WEAPON;
break;
case 6: // DIPLOMACY
nSkillVal = SKILL_DIPLOMACY;
break;
case 7: // DISABLE DEVICE
nSkillVal = SKILL_DISABLE_TRAP;
break;
case 8: // DISCIPLINE
nSkillVal = SKILL_DISCIPLINE;
break;
case 9: // HEAL
nSkillVal = SKILL_HEAL;
break;
case 10: // HIDE
nSkillVal = SKILL_HIDE;
break;
case 11: // INTIMIDATE
nSkillVal = SKILL_INTIMIDATE;
break;
case 12: // LISTEN
nSkillVal = SKILL_LISTEN;
break;
case 13: // LORE
nSkillVal = SKILL_LORE;
break;
case 14: // MOVE SILENTLY
nSkillVal = SKILL_MOVE_SILENTLY;
break;
case 15: // OPEN LOCK
nSkillVal = SKILL_OPEN_LOCK;
break;
case 16: // PARRY
nSkillVal = SKILL_PARRY;
break;
case 17: // PERFORM
nSkillVal = SKILL_PERFORM;
break;
case 18: // RIDE
nSkillVal = SKILL_RIDE;
break;
case 19: // SEARCH
nSkillVal = SKILL_SEARCH;
break;
case 20: // SET TRAP
nSkillVal = SKILL_CRAFT_TRAP;
break;
case 21: // SLEIGHT OF HAND
nSkillVal = SKILL_SLEIGHT_OF_HAND;
break;
case 22: // SPELLCRAFT
nSkillVal = SKILL_SPELLCRAFT;
break;
case 23: // SPOT
nSkillVal = SKILL_SPOT;
break;
case 24: // SURVIVAL
nSkillVal = SKILL_SURVIVAL;
break;
case 25: // TAUNT
nSkillVal = SKILL_TAUNT;
break;
case 26: // TUMBLE
nSkillVal = SKILL_TUMBLE;
break;
case 27: // USE MAGIC DEVICE
nSkillVal = SKILL_USE_MAGIC_DEVICE;
break;
case 28: // BALANCE
nSkillVal = SKILL_BALANCE;
break;

}

return (nSkillVal);
}






gc_skill_rank (untouched except the problem #inc script)


// gc_skill_rank(int nSkill, int nRank)
/*
 Determine if PC Speaker has sufficient rank in a particular skill.
 Parameters:
  int nSkill  = skill int to check
  int nRank = minimum rank to return TRUE
 Remarks:
  skill ints
  0 APPRAISE
  1 BLUFF
  2 CONCENTRATION
  3 CRAFT ALCHEMY
  4 CRAFT ARMOR
  5 CRAFT WEAPON
  6 DIPLOMACY
  7 DISABLE DEVICE
  8 DISCIPLINE
  9 HEAL
  10 HIDE
  11 INTIMIDATE
  12 LISTEN
  13 LORE
  14 MOVE SILENTLY
  15 OPEN LOCK
  16 PARRY
  17 PERFORM
  18 RIDE
  19 SEARCH
  20 CRAFT TRAP
  21 SLEIGHT OF HAND
  22 SPELL CRAFT
  23 SPOT
  24 SURVIVAL
  25 TAUNT
  26 TUMBLE
  27 USE MAGIC DEVICE
*/ 
// BMA-OEI 9/02/05
#include "ginc_param_const"
#include "inc_skill"

int StartingConditional(int nSkill, int nRank)
{
 object oPC = GetPCSpeaker();
 int nSkillVal = GetSkillConstant(nSkill);
 
 if (GetSkillRank(nSkillVal, oPC) >= nRank)
 {
  return TRUE;
 }
 else
 {
  return FALSE;
 }
}

Modifié par Lucan Silverhand, 03 mai 2011 - 12:39 .


#8
The Fred

The Fred
  • Members
  • 2 516 messages
OK, a quick primer on includes (you probably already know all this by now):
You can add constants or even functions to any script you write, like so:
const int MY_NEW_CONSTANT = 12;
void main()
{
    //Your code here
}

An include file is a way of making a "library" of functions and/or constants that you want to use lots, so you can do this:
//This is an include file, save as "my_include"
const int MY_NEW_CONSTANT = 12;

//This is the script
#include "MY_INCLUDE"

void main()
{
    //Your code here
}


I think your probably is actually that you are including both the original include, and your own one. This will probably confuse the compiler, because it now has two functions with the same name.


However, "gc_skill_dc" and "gc_skill_rank" are, imo, really stupid scripts. They take a number, which refers to a skill, and then, in a function contained in an include file, look up another number corresponding to that number to make a skill check with a skill refered to by said number. Perhaps everyone else knows something I don't, but why anyone would even think to do that is completely beyond me. Since you're changing the script yourself anyway, I would actually suggest forgetting the include file, and just writing a proper version of the script, something like this:
int StartingConditional(int nSkill, int nRank)
{
    object oPC = GetPCSpeaker();
    return (GetSkillRank(nSkill, oPC) >= nRank);
}
Basically, you are eliminating the
int nSkillVal = GetSkillConstant(nSkill);
line. What this means is that you can just use the number which corresponds directly to each skill. This is simply the number in the 2da file "skills.2da". Note that these are different numbers - for example, Appraise is now 20, not 0.

Modifié par The Fred, 03 mai 2011 - 02:49 .


#9
Lucan Silverhand

Lucan Silverhand
  • Members
  • 27 messages
You were right, The Fred. The reason the gc_skill_rank wasn't allowing me to add my include was because it contained double functions. I'm still not quite getting it though. I removed them and it compiled fine. However, when working with gc_skill_rank it will not work with both "ginc_param_const" and my include because it again has duplicates (makes sense considering I copied it straight out of it). I'm still not certain what exactly I should put in my code to just include the new constants.
 
eg.

const int BALANCE = 28;

void main()
{
    //Your code here (What goes in here?)
}



Your second workaround proved much more helpful. The simple script checks for the skill fine, once one remembers that it's using the corresponding number from the skills.2da.

For the moment, I believe I'll use this, although if anyone can help with the code of the inc it would be appreciated. 

Modifié par Lucan Silverhand, 04 mai 2011 - 08:29 .


#10
Morbane

Morbane
  • Members
  • 1 883 messages
AT least you are trying Lucan - I had 3 semesters of IT and I still had problems with getting scripting the way I wanted it. Lots of trial and error - the best way to learn - if you have the time that is.


Have you heard of the NWN2 lexicon 1.69 ?? It is a must have for learning scripting in NWN2.

Modifié par Morbane, 04 mai 2011 - 08:27 .


#11
The Fred

The Fred
  • Members
  • 2 516 messages
Sorry, that was just an example of how to add a constant to a script and how an include file can do it for you.

To change the ginc_skill_ scripts the way you want to, you need both to add a constant AND to change the function which looks up the real constants from those constants (if that makes sense). You can just modify the standard include file, and then recompile the ginc_skill_ scripts. Alternatively, put the modified versions in your include file as you were doing, and then replace the standard include with your own.

However, I would argue that doing all of this is a workaround to a silly system which makes it hard to add new skills. The alternative method I suggested is just doing away with all of that and using a much simpler idea (i.e. taking away the pointless intermediate steps which make everything annoying) which doesn't need you to add new constants or change old functions when you add new skills. I can't speak for others, but to me, this seems like a much more intuitive way of doing things.