Author Topic: SCRIPTING SOLUTIONS  (Read 589 times)

Legacy_Mudeye

  • Full Member
  • ***
  • Posts: 238
  • Karma: +0/-0
SCRIPTING SOLUTIONS
« on: November 08, 2010, 04:09:45 pm »


               This thread is intended for solutions to scripting problems.  Don't post questions here.  Just put in solutions that you think would be useful for scripters to know.
               
               

               
            

Legacy_Mudeye

  • Full Member
  • ***
  • Posts: 238
  • Karma: +0/-0
SCRIPTING SOLUTIONS
« Reply #1 on: November 08, 2010, 04:10:58 pm »


               MAX HP ON LEVELUP

There is a setting in your nwnplayer.ini. Under the "Server Options" you will see:

Max Hit Points=0

Change it to:

Max Hit Points=1

This should get you Max HP on Leveling up.

I grabbed this from a post by GhostOfGod.  '<img'>
               
               

               


                     Modifié par Mudeye, 08 novembre 2010 - 04:11 .
                     
                  


            

Legacy_Mudeye

  • Full Member
  • ***
  • Posts: 238
  • Karma: +0/-0
SCRIPTING SOLUTIONS
« Reply #2 on: November 08, 2010, 04:58:44 pm »


               RANDOM NAME GENERATOR

A random name generator script that works for NPCs but not PCs.

http://nwn.wikia.com..._name_generator
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
SCRIPTING SOLUTIONS
« Reply #3 on: November 10, 2010, 02:26:11 am »


               Why do I always get an ERROR: SKIPPING DECLARATION VIA "case" STATEMENT DISALLOWED error when trying to compile a switch.   

http://social.biowar...5019199#5026795
               
               

               
            

Legacy_Mudeye

  • Full Member
  • ***
  • Posts: 238
  • Karma: +0/-0
SCRIPTING SOLUTIONS
« Reply #4 on: November 12, 2010, 10:20:18 pm »


               HENCHMAN THAT LEVELS UP WITH PC

To make a henchman that levels up with the PC.

You first make a level 1 henchman.  It must be level 1. You can give it any feats or anything you want.

In
the conversation where you take the henchman on, you add a little code
to the ActionsTake script where you get the henchman.  This will level
up the henchman to your level (or below if you like).  The variable
levelsBelowPC is the number of levels below the PC that you want the
henchman to be.  The PC level needs to be at least (1+levelsBelowPC).


  object pc = GetPCSpeaker();
  int pcLev = GetHitDice(pc);
  int i;
  int levelsBelowPC = 1;
  int lev = GetHitDice(OBJECT_SELF);
  lev = lev + levelsBelowPC;
  for( i=lev; i<pcLev; i++ )
  {
    LevelUpHenchman( OBJECT_SELF );
  }
 
 
That will level the henchman up to the level of the PC-1  when you first get them.

Now to keep them leveled up you put some code in the Modules event script for the event OnPlayerLevelUp

    object pc = GetPCLevelingUp();
    int maxHenchmen = GetMaxHenchmen();
    int i;
    for( i=1; i<=maxHenchmen; i++ )
    {
        object hench = GetHenchman(pc, i );
        if( GetIsObjectValid(hench) )
        {
            LevelUpHenchman( hench );
        }
    }
   
Every
time the PC levels up any henchmen will also level up.  If you drop a
henchman and regain them later the first script will level them up to
the right level and then when you level up again the second script will
keep them at the right level.

   
               
               

               


                     Modifié par Mudeye, 24 juin 2011 - 05:40 .
                     
                  


            

Legacy_Mudeye

  • Full Member
  • ***
  • Posts: 238
  • Karma: +0/-0
SCRIPTING SOLUTIONS
« Reply #5 on: November 18, 2010, 06:05:18 pm »


               F5 IS DANGEROUS

Here's one from Fester Pot:

Fester Pot wrote...

NEVER press F5!

It will reset every single placeable, making you have to reset them if you've gone and modified the z-axis of the placeable.

If
you want a door placeable to be in the opening of the house, you have
to manually modify the door's z-axis until it fits to the location you
are happy with.

FP!


I think that a door "placeable" here is one of the doors in the placeable menu and is not to be confused with a door from the door menu.
               
               

               


                     Modifié par Mudeye, 18 novembre 2010 - 06:07 .
                     
                  


            

Legacy_Mudeye

  • Full Member
  • ***
  • Posts: 238
  • Karma: +0/-0
SCRIPTING SOLUTIONS
« Reply #6 on: November 18, 2010, 06:10:59 pm »


               MAKING AN NPC REMEMBER YOU FROM A PREVIOUS CONVERSATION

Fester Pot wrote...

Your conversation treeview should be
the the highest response to the lowest. Meaning, the first time the NPC
talks to the PC should be the last conversation in the tree.

+ Good to see you again. (variable is equal to 1) [TEXT APPEARS SCRIPT]
+ Well look what we have here. Someone new in town I see. (variable is equal to 0) [ACTIONS TAKEN SCRIPT]


+ Good to see you again

This requires a TEXT APPEARS script.

+ Well look what we have here. Someone new in town I see.

This requires an ACTIONS TAKEN script.

The ACTIONS TAKEN script would look along the lines of:

void main()
{
   // Set the variables
       // We set the "metnpcabc" variable to equal 1 so we know the PC has spoken to the NPC
   SetLocalInt(GetPCSpeaker(), "metnpcabc", 1);
}
MAKING AN NPC REMEMBER YOU FROM A PREVIOUS CONVERSATION

This is also from Fester Pot:


The TEXT APPEARS script would look along the lines of:

int StartingConditional()
{

   // Inspect local variables
       // We check the "metnpcabc" variable to see if it equals 1 so we know if the PC has spoken to the NPC
   if(!(GetLocalInt(GetPCSpeaker(), "metnpcabc") == 1))
      return FALSE;

   return TRUE;
}


FP!


               
               

               


                     Modifié par Mudeye, 18 novembre 2010 - 06:11 .
                     
                  


            

Legacy_Mudeye

  • Full Member
  • ***
  • Posts: 238
  • Karma: +0/-0
SCRIPTING SOLUTIONS
« Reply #7 on: November 18, 2010, 06:29:04 pm »


               TRANSPORTING PARTY TO A LOCATION

This is from GhostOfGod and it is procedure to transport a pc and all in the party to a location.


void TransportAllFollowersToLocation(object oPC, location oLoc)
{
    // Jump the PC
    AssignCommand(oPC, ClearAllActions());
    AssignCommand(oPC, JumpToLocation(oLoc));

    // Not a PC, so has no associates
    if (!GetIsPC(oPC))
        return;

    object oFollower = GetFirstFactionMember(oPC, FALSE);
    // Jump any associates
    while (GetIsObjectValid(oFollower))
    {
        AssignCommand(oFollower, ClearAllActions());
        AssignCommand(oFollower, JumpToLocation(oLoc));
        oFollower = GetNextFactionMember(oPC, FALSE);
    }

}
               
               

               
            

Legacy_Mudeye

  • Full Member
  • ***
  • Posts: 238
  • Karma: +0/-0
SCRIPTING SOLUTIONS
« Reply #8 on: November 18, 2010, 06:32:17 pm »


               KILL A WHOLE FACTION AT ONCE

This is from Genisys.  It will get rid of all the members of a faction.  A fast cleanup tool.

void KillTheFaction(object oMember)  //
{
 object oTarget;
 effect eDeath = EffectDeath();  //This Simply Works (Apply Damage can crash the game)
 
oTarget = GetFirstFactionMember(oMember, TRUE);
 while(GetIsObjectValid(oTarget))
 {
    ApplyEffectToObject(DURATION_TYPE_INSTANT, eDeath, oTarget); 
    oTarget = GetNextFactionMember(oMember, TRUE);
 }

}
               
               

               
            

Legacy_Snarkblat

  • Full Member
  • ***
  • Posts: 104
  • Karma: +0/-0
SCRIPTING SOLUTIONS
« Reply #9 on: June 24, 2011, 05:40:45 pm »


               

Mudeye wrote...

HENCHMAN THAT LEVELS UP WITH PC

To make a henchman that levels up with the PC.

You first make a level 1 henchman.  It must be level 1. You can give it any feats or anything you want.

In
the conversation where you take the henchman on, you add a little code
to the ActionsTake script where you get the henchman.  This will level
up the henchman to your level (or below if you like).  The variable
levelsBelowPC is the number of levels below the PC that you want the
henchman to be.  The PC level needs to be at least (1+levelsBelowPC).


  object pc = GetPCSpeaker();
  int pcLev = GetHidDice(pc);
  int i;
  int levelsBelowPC = 1;
  int lev = GetHitDice(OBJECT_SELF);
  lev = lev + levelsBelowPC;
  for( i=lev; i<pcLev; i++ )
  {
    LevelUpHenchman( OBJECT_SELF );
  }
 
 
That will level the henchman up to the level of the PC-1  when you first get them.

Now to keep them leveled up you put some code in the Modules event script for the event OnPlayerLevelUp

    object pc = GetPCLevelingUp();
    int maxHenchmen = GetMaxHenchmen();
    int i;
    for( i=1; i<=maxHenchmen; i++ )
    {
        object hench = GetHenchman(pc, i );
        if( GetIsObjectValid(hench) )
        {
            LevelUpHenchman( hench );
        }
    }
   
Every
time the PC levels up any henchmen will also level up.  If you drop a
henchman and regain them later the first script will level them up to
the right level and then when you level up again the second script will
keep them at the right level.

   





I would really like to use this system for my module. However, when I compile the script I get a "PARSING VARIABLE LIST" error. Am I missing an inc file? This is the line that's giving me trouble:

int pcLev = GetHidDice(pc);
               
               

               
            

Legacy_Mudeye

  • Full Member
  • ***
  • Posts: 238
  • Karma: +0/-0
SCRIPTING SOLUTIONS
« Reply #10 on: June 24, 2011, 06:38:30 pm »


               It looks like I had a typo.  It should be a "t" instead of a "d" in Hit.  So "GetHitDice" instead of "GetHidDice".

Sorry about that.  I've updated the original post.
               
               

               


                     Modifié par Mudeye, 24 juin 2011 - 05:41 .
                     
                  


            

Legacy_Xardex

  • Sr. Member
  • ****
  • Posts: 414
  • Karma: +0/-0
SCRIPTING SOLUTIONS
« Reply #11 on: June 24, 2011, 09:11:51 pm »


               

const string COLORTOKEN = "                  ##################$%&'()*+,-./0123456789:;;==?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[[]^_`abcdefghijklmnopqrstuvwxyz{|}~~€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ¡¡¢£¤¥¦§¨©ª«¬¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþþ";

// returns a properly color-coded sText string based on specified RGB values
// ends color mode after sText if iEnd = 1
string ColorString(string sText, int nRed=255, int nGreen=255, int nBlue=255, int iEnd = 0);
string ColorString(string sText, int nRed=255, int nGreen=255, int nBlue=255, int iEnd = 0)
{
    string sEnd = "";
    if (iEnd == 1) {sEnd = "</c>";}
    return "<c" + GetSubString(COLORTOKEN, nRed, 1) + GetSubString(COLORTOKEN, nGreen, 1) + GetSubString(COLORTOKEN, nBlue, 1) + ">" + sText + sEnd;
}



void SetColors();
void SetColors()
{
    int r=0,g=0,b=0, in;
    while (1)
    {
        SetCustomToken(6000 + r*100 + g*10 + b*1, ColorString("", r*28+3, g*28+3, b*28+3));
             if ((r == 9) && (g == 9) && (b == 9)) {break;}
        else if (            (g == 9) && (b == 9)) {r++; g=0; b=0;}
        else if (                        (b == 9)) {     g++; b=0;}
        else                                       {          b++;}
        in++;
    }
    SetCustomToken(7000, "</c>");
}


Calling SetColors on module load will create 729 custom tokens that you can use in journal, conversation or whatever to create RGB colors. <CUSTOM6900> would be bright red, 6030 dark green, 6990 yellow and so on. 7000 ends the color.





OnModuleLoad

    SetLocalInt(OBJECT_SELF, "zero", Time());

Include script

// Returns current server time in seconds
int Time();

int Time()
{
    int iTime;
    int iH = FloatToInt(HoursToSeconds(1))/60; // Amount of minutes per hour
    iTime += GetTimeSecond();
    iTime += GetTimeMinute()*60;
    iTime += GetTimeHour()*iH*60;
    iTime += GetCalendarDay()*24*iH*60;
    iTime += GetCalendarMonth()*28*24*iH*60;
    iTime += GetCalendarYear()*12*28*24*iH*60;
    iTime -= GetLocalInt(GetModule(), "zero");
    return iTime;
}


Time() will return how many seconds the server has been on.





Mudeye, the kill faction function will fail to kill creatures immune to death magic. Making EffectDeath as a SupernaturalEffect would fix this.



[EDIT]
Modified Time() so module creators dont have to modify iH if they changed their 'minutes per hour' in the module options, thanks to Lightfoot8.
               
               

               


                     Modifié par Xardex, 25 juin 2011 - 03:31 .
                     
                  


            

Legacy_Mudeye

  • Full Member
  • ***
  • Posts: 238
  • Karma: +0/-0
SCRIPTING SOLUTIONS
« Reply #12 on: June 24, 2011, 09:38:36 pm »


               

Xardex wrote...

Mudeye, the kill faction function will fail to kill creatures immune to death magic. Making EffectDeath as a SupernaturalEffect would fix this.


Ok, sounds good.  Do you think you could write up how to do that as a solution?  I didn't write the original and I'm not quite sure what the modification would be.
               
               

               
            

Legacy_Xardex

  • Sr. Member
  • ****
  • Posts: 414
  • Karma: +0/-0
SCRIPTING SOLUTIONS
« Reply #13 on: June 25, 2011, 10:14:37 am »


               

effect eDeath = SupernaturalEffect(EffectDeath());