Jump to content

Home

a_adjust scripts


T7nowhere

Recommended Posts

I would like to know how to alter the generic a_adjust"nameattribute" and a_givefeat scripts so that instead of giving the PC the feats they can be given to an npc through dialog.

 

Here are the scripts in question:

//adjusts WISDOM by the value of GetSCriptParameter( 1 )
void main()
{
   int tValue = GetScriptParameter( 1 );
   AdjustCreatureAttributes(GetFirstPC(), ABILITY_WISDOM, tValue);
}

 

// a_givefeat
// Parameter Count: 1
// Param1 - The Feat Id from Feat.2DA for the desired feat.
// This script grants the requested feat to the player's character
// without regard to prerequisites.
void main()
{
   int nFeatId = GetScriptParameter( 1 );
   GrantFeat( nFeatId, GetFirstPC() );
}

 

What I would like to do is make it possible to use these in dialogs with party npc's to adjust their attributes skills and feats. The assumption is that the pc is currently in conversation with the npc that is to recieve the bonus. So if its possible to make a generic script that can be used to adjust any npc that would be great. But if I have to specify the npc(by tag) that is to recieve the bonus then that'll work to. I'm just not sure how it should be writen.

 

I was thinking of combinning scripts like "a_makejedi" with "a_givefeat". So that I can make it check for the npc that I list in the if statements. which is controled by Parameter 1 and then parameter 2 would be for the Givefeat script. It should be possible to do, But I'm not sure how to make it work. I think it would be something like this. But the script below obviously does not work. I'm better at cannibalizing scripts than writing them. Scripting is my only real modding bottle neck. Any assistance would be helpfull.

 /*NPC numbers, as specified in NPC.2da

0       Atton
1       BaoDur

*/

void main()
{    
int nScriptNumber = GetScriptParameter( 1 );
int nFeatId = GetScriptParameter( 2 );   


if ( nScriptNumber == 0 ) {
GrantFeat( nFeatId, Getobjectbytag("Atton") );
}
if ( nScriptNumber == 1 ) {
GrantFeat( nFeatId, Getobjectbytag("BaoDur") );
//ECT.
}
} 

Link to comment
Share on other sites

I believe something like this should work...

 

// ST: st_adjuststat

#include "k_inc_glob_party"

void main() {
   int nNPC    	= GetScriptParameter(1); // NPC_*
   int nAttribute 	= GetScriptParameter(2); // ABILITY_*
   int nAmount 	= GetScriptParameter(3);

   object oNPC;

   if (nNPC == NPC_PLAYER)
   	oNPC = GetFirstPC();
   else
    	oNPC = GetObjectByTag(GetNPCTag(nNPC));

   if (GetIsObjectValid(oNPC) 
   	&& (nAttribute >= ABILITY_STRENGTH)
   	&& (nAttribute <= ABILITY_CHARISMA)) 
   {
	AdjustCreatureAttributes(oNPC, nAttribute, nAmount);
   }
}

 

...and...

 

// ST: st_givefeat

#include "k_inc_glob_party"

void main() {
   int nNPC  = GetScriptParameter(1); // NPC_*
   int nFeat = GetScriptParameter(2);

   object oNPC;

   if (nNPC == NPC_PLAYER)
   	oNPC = GetFirstPC();
   else
    	oNPC = GetObjectByTag(GetNPCTag(nNPC));

   if (GetIsObjectValid(oNPC) && !GetHasFeat(nFeat, oNPC)) {
	GrantFeat(nFeat, oNPC);
   }
}

 

The NPC parameter should be set to the value equal to the NPC_* constant of the party member to receive the feat or stat change.

 

The relevant constant values are (snipped from nwscript.nss):

 

NPC_PLAYER =-1

NPC_ATTON = 0

NPC_BAO_DUR = 1

NPC_CANDEROUS = 2

NPC_G0T0 = 3

NPC_HANDMAIDEN = 4

NPC_HK_47 = 5

NPC_KREIA = 6

NPC_MIRA = 7

NPC_T3_M4 = 8

NPC_VISAS = 9

NPC_HANHARR = 10

NPC_DISCIPLE = 11

 

ABILITY_STRENGTH = 0

ABILITY_DEXTERITY = 1

ABILITY_CONSTITUTION = 2

ABILITY_INTELLIGENCE = 3

ABILITY_WISDOM = 4

ABILITY_CHARISMA = 5

Link to comment
Share on other sites

Ok great I'll try this out right away.

 

Edit: Thanks alot stoffe, You just saved me coutless hours of frustration.

 

Both scripts work perfectly If there used on separate dialog nodes, but if both script nodes are used only the first fires. But thats fine by me, I am going to have alot of fun with this :D

Link to comment
Share on other sites

The assumption is that the pc is currently in conversation with the npc that is to recieve the bonus.

If this is the case, it can be achieved much easier. You don't need to provide NPC constant because NPC object will be OBJECT_SELF in the scripts (coz he is the caller).

 

I believe you can also make one script to do both tasks if you wish. Eg:

// affects NPC SPEAKER
void main()
{

int iAction = GetScriptParameter(1);
int iAbility = GetScriptParameter(2);
int iValue = GetScriptParameter(3);
int iFeat = GetScriptParameter(4);

/*
	ActionParam1 iAction values
	--------------
	1 = adjust ability
	2 = give feat
	3 = do both

*/

switch (iAction)
{
	case 1:
	{
		// adjust attr
		AdjustCreatureAttributes(OBJECT_SELF, iAbility, iValue);
	} break;
	case 2:
	{
		// give feat
		if (!GetFeatAcquired(iFeat, OBJECT_SELF)) { GrantFeat(iFeat,OBJECT_SELF); }

	} break;
	case 3:
	{
		// do both
		AdjustCreatureAttributes(OBJECT_SELF, iAbility, iValue);
		if (!GetFeatAcquired(iFeat, OBJECT_SELF)) { GrantFeat(iFeat,OBJECT_SELF); }

	} break;
	default:
}
}

Link to comment
Share on other sites

Originally posted by Xcom

If this is the case, it can be achieved much easier. You don't need to provide NPC constant because NPC object will be OBJECT_SELF in the scripts (coz he is the caller).

 

Unless I am mistaken OBJECT_SELF in a script fired from a dialog always refer to the object that started the conversation, not necessarily the one who speaks.

 

This would work fine for normal conversations with only two people involved. But for conversations between several people, or conversations which are started by another object than the NPC in question, using OBJECT_SELF would be unreliable.

 

I suppose it depends on how specialized for a particular task, or how adaptable/reusable you want your scripts to be. A matter of the situation and personal taste I guess. :)

Link to comment
Share on other sites

Originally posted by stoffe -mkb-

Unless I am mistaken OBJECT_SELF in a script fired from a dialog always refer to the object that started the conversation, not necessarily the one who speaks.

 

No, I believe you are correct, but from what I understood, the dialog between the two is what T7 had in mind. :giveup:

Link to comment
Share on other sites

  • 2 weeks later...
Originally posted by stoffe -mkb-

I believe something like this should work...

 

// ST: st_givefeat

#include "k_inc_glob_party"

void main() {
   int nNPC  = GetScriptParameter(1); // NPC_*
   int nFeat = GetScriptParameter(2);

   object oNPC;

   if (nNPC == NPC_PLAYER)
   	oNPC = GetFirstPC();
   else
    	oNPC = GetObjectByTag(GetNPCTag(nNPC));

   if (GetIsObjectValid(oNPC) && !GetHasFeat(nFeat, oNPC)) {
	GrantFeat(nFeat, oNPC);
   }
}

 

I like this script, but I would like to add abit more flexability to it.

 

What I would like to do is add some if else statements so that if the npc already has the feat in Param2 it will ignore it and move onto the feat in Param 3 and if the npc has the feat in Param3 then it moves onto Param4 and if the npc has the feat in Param4 then it moves on to Param5 and if the npc has all the feats then nothing happends.

 

I have tried it but I'm not sure how the syntax would be written.

Link to comment
Share on other sites

Originally posted by T7nowhere

I like this script, but I would like to add abit more flexability to it.

 

What I would like to do is add some if else statements so that if the npc already has the feat in Param2 it will ignore it and move onto the feat in Param 3 and if the npc has the feat in Param3 then it moves onto Param4 and if the npc has the feat in Param4 then it moves on to Param5 and if the npc has all the feats then nothing happends.

 

I have tried it but I'm not sure how the syntax would be written.

 

How about this? I believe it would do what you ask for:

 

#include "k_inc_glob_party"

void main() {
   int nNPC  = GetScriptParameter(1); // NPC_*
   int nFeat;
   int i;
   object oNPC;  

   oNPC = (nNPC == NPC_PLAYER ? GetFirstPC() : GetObjectByTag(GetNPCTag(nNPC)));

   if (GetIsObjectValid(oNPC)) {       
       for (i = 2; i <= 5; i++) {
           nFeat = GetScriptParameter(i);
           if ((nFeat > 0) && !GetFeatAcquired(nFeat, oNPC)) {
               GrantFeat(nFeat, oNPC);
               break;
           }
       }
   }
}

 

EDIT: Fixed a bug in the code...

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...