Aller au contenu

Photo

SCRIPTING SOLUTIONS


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

#1
Mudeye

Mudeye
  • Members
  • 126 messages
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.

#2
Mudeye

Mudeye
  • Members
  • 126 messages
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.  :)

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


#3
Mudeye

Mudeye
  • Members
  • 126 messages
RANDOM NAME GENERATOR

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

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

#4
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
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

#5
Mudeye

Mudeye
  • Members
  • 126 messages
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 .


#6
Mudeye

Mudeye
  • Members
  • 126 messages
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 .


#7
Mudeye

Mudeye
  • Members
  • 126 messages
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 .


#8
Mudeye

Mudeye
  • Members
  • 126 messages
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);
    }

}

#9
Mudeye

Mudeye
  • Members
  • 126 messages
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);
 }

}

#10
Snarkblat

Snarkblat
  • Members
  • 52 messages

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);

#11
Mudeye

Mudeye
  • Members
  • 126 messages
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 .


#12
Xardex

Xardex
  • Members
  • 217 messages

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 .


#13
Mudeye

Mudeye
  • Members
  • 126 messages

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.

#14
Xardex

Xardex
  • Members
  • 217 messages

effect eDeath = SupernaturalEffect(EffectDeath());