Author Topic: Looking for Script Help  (Read 662 times)

Legacy_wekoronshei

  • Newbie
  • *
  • Posts: 20
  • Karma: +0/-0
Looking for Script Help
« on: December 17, 2010, 09:19:28 pm »


                I'm looking for a comprehensive script that will effectually make an NPC cease combat with the PC at or below a certain percentage (or raw number, if possible, depending on the NPC itself) of HP. I've tried several already, and haven't gotten any to work; I wouldn't be able to give an example of them, either, because I've since deleted them out of frustration '-_-';

Any and all help would be extremely appreciated.

--Weko
               
               

               
            

Legacy__Knightmare_

  • Full Member
  • ***
  • Posts: 191
  • Karma: +0/-0
Looking for Script Help
« Reply #1 on: December 17, 2010, 09:30:51 pm »


               Here's a similar question in the NWN2 section of the forums. The games use the same scripting.
http://social.biowar...4/index/5284179
               
               

               


                     Modifié par _Knightmare_, 17 décembre 2010 - 09:31 .
                     
                  


            

Legacy_wekoronshei

  • Newbie
  • *
  • Posts: 20
  • Karma: +0/-0
Looking for Script Help
« Reply #2 on: December 17, 2010, 09:38:09 pm »


               Ah, thank you. I suppose I ought to have perused the new forums instead of relying on the old ones.
               
               

               
            

Legacy_wekoronshei

  • Newbie
  • *
  • Posts: 20
  • Karma: +0/-0
Looking for Script Help
« Reply #3 on: December 17, 2010, 09:41:31 pm »


               Hmm...



I've tested that exact script, and on the line

. . . if((!GetIsPC(oNPC)) && (!GetIsOwnedByPlayer(oNPC)) && (!GetIsPlayerCreated(oNPC))) . . .

it says there is an unknown state in the compiler. Not being a scripting genius, I haven't the slightest clue how to tweak this and make it compile correctly. Any suggestions?
               
               

               
            

Legacy_wekoronshei

  • Newbie
  • *
  • Posts: 20
  • Karma: +0/-0
Looking for Script Help
« Reply #4 on: December 17, 2010, 09:56:11 pm »


               I do have my NPC set to immortal, as you suggested in that post, and I placed the script into the OnDamaged portion of its scripts.
               
               

               
            

Legacy_wekoronshei

  • Newbie
  • *
  • Posts: 20
  • Karma: +0/-0
Looking for Script Help
« Reply #5 on: December 17, 2010, 10:03:52 pm »


               So I've changed that line to

. . . if((GetIsObjectValid(oNPC)) . . .

and it continues, although now it tells me that here,

. . . if((!GetIsObjectValid(oNPC))

{

ChangeToStandardFaction(oNPC, STANDARD_FACTION_COMMONER);

}

oNPC = GetNextObjectInShape(SHAPE_SPHERE, 20.0f, lLoc, FALSE, OBJECT_TYPE_CREATURE);

} . . .

that first left bracket below the if statement has no right bracket on the expression. Wouldn't that be the one right below the ChangeToStandardFaction line?
               
               

               
            

Legacy__Knightmare_

  • Full Member
  • ***
  • Posts: 191
  • Karma: +0/-0
Looking for Script Help
« Reply #6 on: December 17, 2010, 10:54:33 pm »


               What the script calls a "Right/Left Bracket" the rest of the English speaking world calls a parenthesis.



I think the original problem might be that NWN1 has no function called "GetIsPlayerCreated()" as that's used for NWN2 where you can make a whole party of player created PCs where in NWN1 you can only have a single player-made PC in a party. Try removing that part from the "if" line and see if it compiles for you.
               
               

               
            

Legacy_wekoronshei

  • Newbie
  • *
  • Posts: 20
  • Karma: +0/-0
Looking for Script Help
« Reply #7 on: December 17, 2010, 11:00:10 pm »


               I did change the if from the original to what you see there, i.e. GetIsObjectValid(oNPC) and it was fine. It was calling for a right bracket on the "{" right before ChangeToStandardFaction.



I'm gonna play around with it some more...but I don't foresee much progress as my scripting skills are anything other than on par to be doing what I'm doing.



Thanks, Knightmare.
               
               

               
            

Legacy_wekoronshei

  • Newbie
  • *
  • Posts: 20
  • Karma: +0/-0
Looking for Script Help
« Reply #8 on: December 17, 2010, 11:07:06 pm »


               If it helps, this is what I'm currently looking at:



1 void main()

2 {

3 object oSelf = OBJECT_SELF;

4 location lLoc = GetLocation(oSelf);

5 int nHP = GetCurrentHitPoints(oSelf);

6

7 // If the NPC currently has 1 Hit Point left

8 if(nHP == 1)

9 {

10 // Search through all creatures in a 20 meter radius centered on oSelf

11 object oNPC = GetFirstObjectInShape(SHAPE_SPHERE, 20.0f, lLoc, FALSE, OBJECT_TYPE_CREATURE);

12

13 while(GetIsObjectValid(oNPC))

14 {

15 // Clear combat states for every creature found in search

16 AssignCommand(oNPC, ClearAllActions(TRUE));

17

18 // Change NPC to Commoner Faction so no longer hostile

19 if((!GetIsObjectValid(oNPC))

20 {

21 ChangeToStandardFaction(oNPC, STANDARD_FACTION_COMMONER);

22 }

23 oNPC = GetNextObjectInShape(SHAPE_SPHERE, 20.0f, lLoc, FALSE, OBJECT_TYPE_CREATURE);

24 }

25

26 // Have the NPC begin a conversation with PC

27 object oPC = GetFirstPC(TRUE); // In a SP module, this is the player’s originally created character

28 AssignCommand(oSelf, ActionStartConversation(oPC, "vampirelord", FALSE, FALSE, TRUE, FALSE ));

29}

30

31 // Else NPC is not yet at 1 Hitpoint, so fire normal OnDamaged script

32 else

33 {

34 ExecuteScript("x2_def_ondamage", oSelf);

35 }

36 }



Line 20 is where the compiler stops and gives me the aforementioned error.
               
               

               
            

Legacy_wekoronshei

  • Newbie
  • *
  • Posts: 20
  • Karma: +0/-0
Looking for Script Help
« Reply #9 on: December 17, 2010, 11:09:43 pm »


               Erm...could the problem possibly lie with a lack of a return command after the "if" statement?
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
Looking for Script Help
« Reply #10 on: December 17, 2010, 11:12:59 pm »


               I would say if npc hp > 25 or so since hitting exactly 1 hp is rather difficult.
Also line 19 says, in effect, if oNpc is not valid.  Usually you get an error right after a line mistake.
               
               

               


                     Modifié par ffbj, 17 décembre 2010 - 11:15 .
                     
                  


            

Legacy_KenquinnTheInsaneOne

  • Newbie
  • *
  • Posts: 48
  • Karma: +0/-0
Looking for Script Help
« Reply #11 on: December 17, 2010, 11:32:48 pm »


               Wekoronshei if statements don't return anything. They either execute the code inside them, or they don't.

Here are the issues I see with your script. One line 19 needs an extra right bracket, two GetFirstPC(TRUE) should be GetFirstPC(), three one line 28 ActionStartConversation has six variables put into it, when it can only take four
               
               

               


                     Modifié par KenquinnTheInsaneOne, 17 décembre 2010 - 11:34 .
                     
                  


            

Legacy__Knightmare_

  • Full Member
  • ***
  • Posts: 191
  • Karma: +0/-0
Looking for Script Help
« Reply #12 on: December 17, 2010, 11:38:59 pm »


               Your problem actually lies in line 19 for a couple reasons (even though the compiler says line 20):

- You have 3 opening brackets, but only two closing brackets - this is your missing right bracket - delete one of the first left brackets (parenthesis) so there is 2 opening and 2 closing.

- The line as you have it written says in layman's terms "if oNPC is not a valid object" - an exclamation point means "not."

- The way I had it written originally was meant to exclude any party members from the loop, as we don't want to change the faction of characters in the player's party

Try this simple line for line 20:

if(!GetIsPC(oNPC))

Which says/means "if oNPC is not a player character."

Lastly, as noted by some others just prior to me (ninjaed!!!!) there may be some difference in some function parameters. The original script I linked to is meant for NWN2.
               
               

               


                     Modifié par _Knightmare_, 17 décembre 2010 - 11:43 .
                     
                  


            

Legacy_Greyfort

  • Sr. Member
  • ****
  • Posts: 442
  • Karma: +0/-0
Looking for Script Help
« Reply #13 on: December 18, 2010, 04:34:12 am »


               //Here's an example for you. For this to work, set the NPC as Immortal = True in its properties.

//This will allow the NPC to take damage down to 1 hit point but not be killed.

//

//In the NPCs OnDamaged script slot, have something like the following:



void main()

{



object oSelf = OBJECT_SELF;

object oPC = GetLastDamager(oSelf);

location lLoc = GetLocation(oSelf);

int nHP = GetCurrentHitPoints(oSelf);



// If the NPC currently has 1 Hit Point left

if(nHP == 1)

{

// stop player char from attacking NPC

AssignCommand(oPC, ClearAllActions(TRUE));



// stop NPC from attacking player

ClearPersonalReputation(oPC,oSelf);

ChangeToStandardFaction(oSelf, STANDARD_FACTION_COMMONER);

AssignCommand(oSelf, ClearAllActions(TRUE));



// Search through all creatures in a 20 meter radius centered on oSelf

object oNPC = GetFirstObjectInShape(SHAPE_SPHERE, 20.0f, lLoc, FALSE, OBJECT_TYPE_CREATURE);



while(GetIsObjectValid(oNPC))

   {

   // Clear combat states for every creature found in search

   ClearPersonalReputation(oPC,oNPC);

   AssignCommand(oNPC, ClearAllActions(TRUE));



   // Change NPC to Commoner Faction so no longer hostile

   if( (!GetIsPC(oNPC)) ) //&& (!GetIsOwnedByPlayer(oNPC) ) )//&& (!GetIsPlayerCreated(oNPC)))

   {

   ChangeToStandardFaction(oNPC, STANDARD_FACTION_COMMONER);

   }

   oNPC = GetNextObjectInShape(SHAPE_SPHERE, 20.0f, lLoc, FALSE, OBJECT_TYPE_CREATURE);

   }//end of while



// Have the NPC begin a conversation with PC

//This "" will execute npc conversation set by npc properties or execute a file

//ActionStartConversation(oPC, "name of conversation file", FALSE, TRUE )

AssignCommand(oSelf, ActionStartConversation(oPC, "", FALSE, TRUE ));

}

// Else NPC is not yet at 1 Hitpoint, so fire normal OnDamaged script

else

   {

   ExecuteScript("nw_c2_default6", oSelf);

   }

//end of script

}



This is the script from the link edited to work in nwn1.  ChangeToStandardFaction wasn’t working so I used ClearPersonalReputation.  script compiles and works.  you can either direct npc to a conversation file or place the conversation file in the creatures properties on the basic tab when you edit a creature.  If you have any more question please ask us.
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Looking for Script Help
« Reply #14 on: December 18, 2010, 05:50:45 am »


               Here is the script you had the compile error on, fixed. It had an extra left bracket on the line you had the error on, and two of the fuctions had unnecessary parameters - GetFirstPC() instead of GetFirstPC(TRUE), and removed the last two FALSES from the StartConvo functions. That's one reason why cribbing scripts from NWN 2 is probably not a great idea.


void main() {

object oSelf = OBJECT_SELF;
location lLoc = GetLocation(oSelf);
int nHP = GetCurrentHitPoints(oSelf);

// If the NPC currently has 1 Hit Point left
if(nHP == 1) {

    // Search through all creatures in a 20 meter radius centered on oSelf
    object oNPC = GetFirstObjectInShape(SHAPE_SPHERE, 20.0f, lLoc, FALSE, OBJECT_TYPE_CREATURE);
    while(GetIsObjectValid(oNPC)) {

        // Clear combat states for every creature found in search
        AssignCommand(oNPC, ClearAllActions(TRUE));
        // Change NPC to Commoner Faction so no longer hostile
        if (!GetIsObjectValid(oNPC)) {
            ChangeToStandardFaction(oNPC, STANDARD_FACTION_COMMONER);
        }
        oNPC = GetNextObjectInShape(SHAPE_SPHERE, 20.0f, lLoc, FALSE, OBJECT_TYPE_CREATURE);
    }

    // Have the NPC begin a conversation with PC
    object oPC = GetFirstPC(); // In a SP module, this is the player’s originally created character
    AssignCommand(oSelf, ActionStartConversation(oPC, "vampirelord", FALSE, FALSE));
    }
    // Else NPC is not yet at 1 Hitpoint, so fire normal OnDamaged script
    else {

    ExecuteScript("x2_def_ondamage", oSelf);

    }
}



That script, as some have pointed out, has many issues - only firing on exactly one hp, which only works if immortal is set, and only resetting in a 20.0 meter sphere are the ones that lept out at me. 

Funky