logo logo

 Back to main page

The NWNX Community Forum

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
funcs plugin, demo module or examples

 
Post new topic   Reply to topic    nwnx.org Forum Index -> Scripts and Modules
View previous topic :: View next topic  
Author Message
Epitaffio



Joined: 13 Jul 2010
Posts: 29
Location: Italy

PostPosted: Fri Jul 16, 2010 11:23    Post subject: funcs plugin, demo module or examples Reply with quote

I'm on linux.

Is there any demo module for this plugin or some example of how to use the functions in that?


I would to create a script to do something similar to this:

1) Remove all the feats and the ability from a pc.
2) Add feats and ability from my choice.
3) Set the pc HP.

I'm not skilled at nwn script and i'm having some issues to use the funcs functions : (
Back to top
View user's profile Send private message
ShaDoOoW



Joined: 20 Aug 2005
Posts: 584

PostPosted: Fri Jul 16, 2010 13:02    Post subject: Re: funcs plugin, demo module or examples Reply with quote

Epitaffio wrote:
I'm not skilled at nwn script and i'm having some issues to use the funcs functions : (

NWNX is primary designed for those skilled in nwscript...

If you would on win I could paste you some examples, but I fear those functions on win are not the same as linux ones...
_________________
Community Patch / NWNX Patch / NWNX Files / NWNX Connect
Back to top
View user's profile Send private message
Epitaffio



Joined: 13 Jul 2010
Posts: 29
Location: Italy

PostPosted: Fri Jul 16, 2010 14:16    Post subject: Re: funcs plugin, demo module or examples Reply with quote

ShaDoOoW wrote:
Epitaffio wrote:
I'm not skilled at nwn script and i'm having some issues to use the funcs functions : (

NWNX is primary designed for those skilled in nwscript...

If you would on win I could paste you some examples, but I fear those functions on win are not the same as linux ones...


I know : ( , but rome wasn't built in a day Razz


If you could post these example, you do me a big favor.

As soon as i can (i'm not at home right now) i will post what i have done and where i have issues (i did certainly stupid mistakes).


Grazie.
Back to top
View user's profile Send private message
ShaDoOoW



Joined: 20 Aug 2005
Posts: 584

PostPosted: Fri Jul 16, 2010 20:55    Post subject: Reply with quote

feat removal, this example will remove monk speed feat
Code:
 if(GetHasFeat(FEAT_MONK_ENDURANCE,oPC)
 {
 RemoveKnownFeat(oPC,FEAT_MONK_ENDURANCE);
 }

to remove all feats, there would be more way to do that, I guess GetKnownFeatByLevel would be the best way, but since I dont work at linux anymore, I don't know whats the result so I will use in my example another way:
Code:

ForceRest(oPC);//this will replenish any feats with uses per day
int nFeat = 0;
 while(nFeat < 1116) //1115 is the last feat without any custom content
 {
  if(GetHasFeat(nFeat,oPC))
  {
  RemoveKnownFeat(oPC,nFeat);
  }
 }

I don't have example for Hitpoints at all, but I know PC can have only 255 hitpoints each level, so you must loop all levels, get how many hitpoint is there, distract from 255 then from total you want to add and add that number and check next levels until total hitpoints to add reach 0...
_________________
Community Patch / NWNX Patch / NWNX Files / NWNX Connect
Back to top
View user's profile Send private message
Epitaffio



Joined: 13 Jul 2010
Posts: 29
Location: Italy

PostPosted: Fri Jul 16, 2010 23:35    Post subject: Reply with quote

Hum to remove all the feat i was convinced that the parameter to pass at the RemoveKnownFeat function was only the constant of the feat..


This is what i've done at this time (i have cleaned the code from all the try : ) )

Code:


//Gets the total number of feats known by oCreature.
int GetTotalKnownFeats (object oCreature) {
    SetLocalString(oCreature, "NWNX!FUNCS!GETTOTALKNOWNFEATS", "        ");
    return StringToInt(GetLocalString(oCreature, "NWNX!FUNCS!GETTOTALKNOWNFEATS"));
}

//Gets the feat at nIndex in oCreature's feat list.
int GetKnownFeat(object oCreature, int nIndex) {
    SetLocalString(oCreature, "NWNX!FUNCS!GETKNOWNFEAT", "        ");
    return StringToInt(GetLocalString(oCreature, "NWNX!FUNCS!GETKNOWNFEAT"));
}

//Returns TRUE if the target inherently knows a feat (as opposed to by any equipment they may possess)
int GetKnowsFeat(int nFeatId, object oCreature) {
    SetLocalString(oCreature, "NWNX!FUNCS!GETKNOWSFEAT", IntToString(nFeatId) + "        ");
    return StringToInt(GetLocalString(oCreature, "NWNX!FUNCS!GETKNOWSFEAT"));
}

//Removes nFeat from oCreature if it knows the feat inherently.
int RemoveKnownFeat(object oCreature, int nFeat) {
    SetLocalString(oCreature, "NWNX!FUNCS!REMOVEKNOWNFEAT", IntToString(nFeat) + "          ");
    return StringToInt(GetLocalString(oCreature, "NWNX!FUNCS!REMOVEKNOWNFEAT"));
}



void main(){

    //Preparo le variabili
    object oPC = GetLastUsedBy();
    int iPClevel = GetHitDice(oPC);

    SendMessageToPC(oPC, "Livello: "+IntToString(iPClevel) );

    if(iPClevel == 1){

        int iPCnTalenti = GetTotalKnownFeats(oPC);
        int iCounting;

        SendMessageToPC(oPC, "Talenti: "+IntToString(iPCnTalenti) );

        for (iCounting = 0; iCounting < iPCnTalenti; iCounting++){

            int iPCtalento = GetKnownFeat(oPC, iCounting);
            SendMessageToPC(oPC, "iCounting: "+IntToString(iCounting)+". Talento: "+IntToString(iPCtalento) );


        }

    } // FINE if livello 1
}





The code in the cycle was just a try, the GetKnownFeat result 3 to all feat but I did't know how to find the constant of the feat..


So to remove all the feat i must cycle through all the feat instead of all the pc's feat?

Thanks for all of the hints!




-----------------------------




Edit:

Cycle edited with the ShaDoOoW hint for the remove feat function.

Code:


        for (iCounting = 0; iCounting < iPCnTalenti; iCounting++){

            int iPCtalento = GetKnownFeat(oPC, iCounting);

                SendMessageToPC(oPC, "iCounting: "+IntToString(iCounting)+". Talento: "+IntToString(iPCtalento) );
                RemoveKnownFeat(oPC, iPCtalento);

        }




But i'm having an issue with this. Let's explain..

Pc with 13 feats, start the cycle:

Code:

iCounting 0, feat id 3
iCounting 1, feat id 170
iCounting 2, feat id 233
iCounting 3, feat id 241
iCounting 4, feat id 243
iCounting 5, feat id 375
iCounting 6, feat id 10
iCounting 7, feat id -1
iCounting 8, feat id -1
iCounting 9, feat id -1
iCounting 10, feat id -1
iCounting 11, feat id -1
iCounting 12, feat id -1


The first 7 feats have been deleted but not the last 6..

Rerunning the cycle, 6 feats:

Code:

iCounting 0, feat id 46
iCounting 1, feat id 237
iCounting 2, feat id 354
iCounting 3, feat id -1
iCounting 4, feat id -1
iCounting 5, feat id -1


As above, only the half of the total feats have been deleted. And so on until there are 0 feats.

What can be O.o?
Back to top
View user's profile Send private message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Sat Jul 17, 2010 2:33    Post subject: Reply with quote

Its just a shot in the dark...
Code:

for (iCounting = 0; iCounting < iPCnTalenti; iCounting++){

            int iPCtalento = GetKnownFeat(oPC, iCounting);

                SendMessageToPC(oPC, "iCounting: "+IntToString(iCounting)+". Talento: "+IntToString(iPCtalento) );
                RemoveKnownFeat(oPC, iPCtalento);

        }


This code, has iPCtalento being set to the value of a feat, while it has iCounting increasing.
Eg - What if the feat number/const for the feat in index 7 is Armor Proficency Medium, which has a feat number of 4. This script would say 7 is greater than 4, so we exit out of the loop.

This 'may' be causing it to skip some feats, but as for why your getting -1 in return values.
Thats generally a return value to indicate an error or empty result.

I would try a while loop instead of a for loop.
eg - While the feat number is positive, keep looping until you get a bad return value.

Code:


void RemoveAllFeats(object oPC)
{

int iNum = 1; // Not sure where the index starts, 0 or 1
int iFeat = GetKnownFeat(oPC,iNum);
while(iFeat)  //While the feat is valid
{
if(GetKnowsFeat(iFeat,oPC)) //If we actually know it
   {
      RemoveKnownFeat(oPC,iFeat);  //Remove it
   }
iNum++   //Move to next feat
iFeat = GetKnownFeat(oPC,iNum);  // Assign it into iFeat, and loop again
}

}



This code, will keep looping until all feats are gone, or at least until the plugin returns a 0 or negative value for whether or not the Player has a feat.
Back to top
View user's profile Send private message
ShaDoOoW



Joined: 20 Aug 2005
Posts: 584

PostPosted: Sat Jul 17, 2010 3:28    Post subject: Reply with quote

nevermind
_________________
Community Patch / NWNX Patch / NWNX Files / NWNX Connect


Last edited by ShaDoOoW on Sat Jul 17, 2010 16:40; edited 1 time in total
Back to top
View user's profile Send private message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Sat Jul 17, 2010 3:54    Post subject: Reply with quote

I thought about that too, the only bad thing is that it loops over 1000 times, whereas the methods provided, allow for smaller loops.
Back to top
View user's profile Send private message
ShaDoOoW



Joined: 20 Aug 2005
Posts: 584

PostPosted: Sat Jul 17, 2010 5:13    Post subject: Reply with quote

Yea, you are right, I didnt even looked into your post when I responded...
_________________
Community Patch / NWNX Patch / NWNX Files / NWNX Connect
Back to top
View user's profile Send private message
Epitaffio



Joined: 13 Jul 2010
Posts: 29
Location: Italy

PostPosted: Sat Jul 17, 2010 15:21    Post subject: Reply with quote

Fixed with this:

Code:


        for (iCounting=(iPCnTalenti-1); iCounting>-1; iCounting--){

            int iPCtalento = GetKnownFeat(oPC, iCounting);

                SendMessageToPC(oPC, "iCounting: "+IntToString(iCounting)+". Talento: "+IntToString(iPCtalento) );
                RemoveKnownFeat(oPC, iPCtalento);

        }




It's time for ability and HP...
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Scripts and Modules All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group