Author Topic: Best way to define the PC object in a script  (Read 460 times)

Legacy_UnrealJedi

  • Full Member
  • ***
  • Posts: 226
  • Karma: +0/-0
Best way to define the PC object in a script
« on: December 12, 2013, 11:03:05 am »


               If I need to run a script that is executed because of an ExecuteScript function from another script, how would I define the PC object? This is related to the topic I posted two days ago (Gestalt Cutscene Issue - Henchman attacks NPC before cutscene ends). I want to have a cutscene script execute another script that causes the NPC's reputation to adjust and then have the NPC attack the PC. Since I can't get this to work in the cutscene script I thought I would try this method. However, I am not sure how to define the PC object when the PC is just in the area and hasn't triggered the script (e.g. by entering the area or trigger, or by conversation). Can anyone assist?

Thanks!
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Best way to define the PC object in a script
« Reply #1 on: December 12, 2013, 12:18:39 pm »


               It all depends on where and how  you are running the script.  

IF you are not changing the object the script is running on and not adding a delay to the script, anything theat would work in the script you are calling from will work in the script you are running.   In fact you are still in the same event.   the event will not finish untill after the calling script finishes.   the calling script will not finish untill the called script finishes.    That is all assumeing that you are calling the script without delay and onto the same object that the first one is running on.
               
               

               
            

Legacy_UnrealJedi

  • Full Member
  • ***
  • Posts: 226
  • Karma: +0/-0
Best way to define the PC object in a script
« Reply #2 on: December 12, 2013, 01:19:26 pm »


               Hmmm...the event starts by the PC entering a trigger. The script on the trigger, in accordance with the Gestalt system, runs and executes a cutscene script (see the topic I posted two days ago for that script code). If I understand correctly, I should not have to define the objects (actors) used in the cutscene in a second called script because they have already been defined in the cutscene script. If that is the case then the called script will not compile correctly, but that should not matter. Because it is a called script it should run just fine.

Am I understanding correctly?
               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Best way to define the PC object in a script
« Reply #3 on: December 12, 2013, 02:12:21 pm »


               No, I don't think so...

The executed script does not have access to variables defined in the scope of the first script.

I think Lightfoot was saying you can get the PC object in the executed script the same way you got it in the first script. For example GetEnteringObject() if that's what you used.
               
               

               
            

Legacy_UnrealJedi

  • Full Member
  • ***
  • Posts: 226
  • Karma: +0/-0
Best way to define the PC object in a script
« Reply #4 on: December 12, 2013, 02:19:24 pm »


               Ah, okay. I think I have it now.

Thanks!
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Best way to define the PC object in a script
« Reply #5 on: December 12, 2013, 03:03:59 pm »


               Yes that is what I was saying.  however since gesalt runs mostly off of delayed commands the event accosors will not work.   your best bet with what you are doing will be to run the script on oPC.  THen the PC will be OBJECT_SELF in the script.
               
               

               
            

Legacy_UnrealJedi

  • Full Member
  • ***
  • Posts: 226
  • Karma: +0/-0
Best way to define the PC object in a script
« Reply #6 on: December 12, 2013, 04:26:03 pm »


               meaglyn and Lightfoot, might I ask a favor? Would you mind looking at the code I posted a couple of days back and help me figure out how to fix it? Gestalt has a function to make a cut scene actors attack the PC but not an AdjustReputation function. To my understanding, an NPC will not attack the PC unless reputation is also adjusted.

Thanks.
               
               

               
            

Legacy_Squatting Monk

  • Hero Member
  • *****
  • Posts: 776
  • Karma: +0/-0
Best way to define the PC object in a script
« Reply #7 on: December 12, 2013, 04:54:03 pm »


               Normally, adjusting the reputation would be handled by the NPC's OnPhysicalAttacked or OnDamaged event. If you've removed those scripts or altered them so they no longer adjust the PC's reputation, you can just DelayCommand() your AdjustReputation() inside your cut-scene script.
               
               

               
            

Legacy_UnrealJedi

  • Full Member
  • ***
  • Posts: 226
  • Karma: +0/-0
Best way to define the PC object in a script
« Reply #8 on: December 12, 2013, 05:16:58 pm »


               Thanks SquattingMonk. I am trying that right now.
               
               

               
            

Legacy_UnrealJedi

  • Full Member
  • ***
  • Posts: 226
  • Karma: +0/-0
Best way to define the PC object in a script
« Reply #9 on: December 12, 2013, 05:32:47 pm »


               Okay, this is weird. I used DelayCommands as suggested. The DetermineCombatRound function has disappeared from the compiler so my script will not compile. I assume Gestalt may have removed it for some reason but sure why. Any thoughts?
               
               

               
            

Legacy_Squatting Monk

  • Hero Member
  • *****
  • Posts: 776
  • Karma: +0/-0
Best way to define the PC object in a script
« Reply #10 on: December 12, 2013, 05:59:43 pm »


               DetermineCombatRound() requires nw_i0_generic. Did you remove an include directive pointing to that file?
               
               

               
            

Legacy_UnrealJedi

  • Full Member
  • ***
  • Posts: 226
  • Karma: +0/-0
Best way to define the PC object in a script
« Reply #11 on: December 12, 2013, 06:27:54 pm »


               Squatting Monk, that include file conflicts with Gestalt's Cutscene system. So I don't have to repeat myself,  you can look at the topic referenced in my original post for details.

I think it works without the DetermineCombatRound. Just gotta get the cutscene timing down now.
               
               

               
            

Legacy_UnrealJedi

  • Full Member
  • ***
  • Posts: 226
  • Karma: +0/-0
Best way to define the PC object in a script
« Reply #12 on: December 13, 2013, 04:59:05 pm »


               Okay, it does not work without DetermineCombatRound. I tried altering Gestalt's cutscene system so it would not conflict with the standard NWN scripts but that didn't work either. I am back to trying to call the below script from the cutscene script I made. However, I am still getting compiler error messages, specifically UNKNOWN STATE IN COMPILER (for the line "object oTarget =  GetObjectByTag("Jacinn");". I am still a n00b to scripting so help is appreciated.

Thanks!


Here is the script:

1) #include "nw_i0_generic"
2)
3) void main()
4) {
5)
6) object oPC = GetLocalObject(GetModule()
7)
8) object oTarget =  GetObjectByTag("Jacinn");
9)
10) AdjustReputation(oPC, oTarget, -100);
11)
12) SetIsTemporaryEnemy(oPC, oTarget);
13)
14) AssignCommand(oTarget, ActionAttack(oPC));
15)
16) AssignCommand(oTarget, DetermineCombatRound(oPC));
17)
18) }
 
               
               

               


                     Modifié par UnrealJedi, 13 décembre 2013 - 05:01 .
                     
                  


            

Legacy_Squatting Monk

  • Hero Member
  • *****
  • Posts: 776
  • Karma: +0/-0
Best way to define the PC object in a script
« Reply #13 on: December 13, 2013, 06:20:39 pm »


               You need a semicolon at the end of line 6.
               
               

               
            

Legacy_MrZork

  • Hero Member
  • *****
  • Posts: 1643
  • Karma: +0/-0
Best way to define the PC object in a script
« Reply #14 on: December 13, 2013, 06:52:41 pm »


               And a closing parenthesis.