Author Topic: Simple Script Not Working  (Read 1333 times)

Legacy_JediMindTrix

  • Sr. Member
  • ****
  • Posts: 383
  • Karma: +0/-0
Simple Script Not Working
« on: August 17, 2012, 09:46:33 am »


               I've spent about an hour on this particular script and it will not function correctly. I've decided it to leave it in the hands of those better then I for I am now just wasting time.

The relavent scripts

nc_observesystem
#include "inc_common"

void main()
{
object oPC = GetEnteringObject();
if (!GetIsPC(oPC)) return;

string sObservation = GetLocalString(OBJECT_SELF, "sMessage");  //Checks the trigger for the message the player is to receive
                                                                //iMsgType checks the trigger for the type of message to play. 1 = Spoken Aloud, 2 = Chat Window
if (HasDoneThisBefore(oPC)) return;

if (GetLocalInt(OBJECT_SELF, "iMsgType") != 1)                  //Spoken Aloud
 {
 SpeakThisOnce(oPC, sObservation);
 int iXPBonus = GetLocalInt(OBJECT_SELF, "iXPBonus");           //XP Bonus Check

 if (iXPBonus)
 GiveXPToCreature(oPC, iXPBonus);
 }
if (GetLocalInt(OBJECT_SELF, "iMsgType") != 2)             //Chat Window
 {
 SayThisOnce(oPC, sObservation);
 int iXPBonus = GetLocalInt(OBJECT_SELF, "iXPBonus");           //XP Bonus Check

 if (iXPBonus)
 GiveXPToCreature(oPC, iXPBonus);
 }
}




inc_common

// Thanks to Axe_Murderer for helping me with these.

// int HasDoneThisBefore( object oPC )
//   Determines if a given PC has interacted with OBJECT_SELF before.
int HasDoneThisBefore( object oPC );
int HasDoneThisBefore( object oPC )
{
return GetLocalInt( oPC, GetTag( OBJECT_SELF ));
}

// void SayThisOnce( object oPC, string sObservation )
//   Causes a given PC to make an observation verbally unless he has done it
//   already once before by interacting with OBJECT_SELF some time earlier.
void SayThisOnce( object oPC, string sObservation );
void SayThisOnce( object oPC, string sObservation )
{ if( GetLocalInt( oPC, GetTag( OBJECT_SELF )) || (sObservation == "") ) return;
  SetLocalInt( oPC, GetTag( OBJECT_SELF ), TRUE );
  AssignCommand(oPC, ClearAllActions());
  SendMessageToPC(oPC, sObservation);
}

// void SpeakThisOnce( object oPC, string sObservation )
//   Causes a given PC to make an observation verbally unless he has done it
//   already once before by interacting with OBJECT_SELF some time earlier.
void SpeakThisOnce( object oPC, string sObservation );
void SpeakThisOnce( object oPC, string sObservation )
{ if( GetLocalInt( oPC, GetTag( OBJECT_SELF )) || (sObservation == "") ) return;
  SetLocalInt( oPC, GetTag( OBJECT_SELF ), TRUE );
  AssignCommand(oPC, ClearAllActions());
  AssignCommand(oPC, ActionSpeakString(sObservation));
}




// Function to do a private version of this skill check, no result
// is told to the PC
// From the NWN Lexicon
int GetIsSkillSuccessfulPrivate(object oTarget, int nSkill, int nDifficulty)
{
    // Do the roll for the skill
    if(GetSkillRank(nSkill, oTarget) + d20() >= nDifficulty)
    {
        // They passed the DC
        return TRUE;
    }
    // Failed the check
    return FALSE;
}

The goal
Now the goal of this script is for a message to be sent OR spoken by a player. The message is taken off a string variable stored on the area or trigger it's placed on and whether or not to send in it the chat window or speak it aloud are decided by an integer, also stored on the variable.

The Symptoms
No matter what the iMsgType was set too (1 or 2), the script will act as if the variable is set to 2 and send the message to the chat window.
I commented out the 2nd "if" block (relavent to chat window messages) and when I walked over the trigger, absolutely nothing happened. My actions weren't even cleared (which I included to see if it was firing at all).

NineCoronas is frustrated and jacked up on Coffee >.<

P.S.

Can a conversation be started with an NPC via scripting that they don't actually have as their main conversation file?

P.P.S.S.

Would a script like this possibly work in a Text Appears When conditional?
#include "inc_common"

int StartingConditional()
{
    object oPC = GetPCSpeaker();
    if (GetIsSkillSuccessfulPrivate(oPC, SKILL_ANIMAL_EMPATHY, 26)) return FALSE;
    return TRUE;
}

               
               

               


                     Modifié par NineCoronas2021, 17 août 2012 - 09:11 .
                     
                  


            

Legacy_Krevett

  • Full Member
  • ***
  • Posts: 203
  • Karma: +0/-0
Simple Script Not Working
« Reply #1 on: August 17, 2012, 12:37:59 pm »


               Your if statement test if the local int is != and not == to 1 or 2, perhaps that's the problem '<img'>

I think PPSS should work!
               
               

               


                     Modifié par Krevett, 17 août 2012 - 11:38 .
                     
                  


            

Legacy_Squatting Monk

  • Hero Member
  • *****
  • Posts: 776
  • Karma: +0/-0
Simple Script Not Working
« Reply #2 on: August 18, 2012, 01:08:27 am »


               Krevett is correct. You should be checking to see if iMsgType == 1.

How I'd do it:

#include "inc_common"
void main()
{
    object oPC = GetEnteringObject();

    if (!GetIsPC(oPC)) return;

    if (HasDoneThisBefore(oPC)) return;

    // Checks the trigger for the message the player is to receive
    string sObservation = GetLocalString(OBJECT_SELF, "sMessage");

    // Checks the trigger for the type of message to play.
    // 1 = Spoken Aloud, 2 = Chat Window
    // 0 can be a toggle to temporarily turn off the message without deleting it
    int iMessageType = GetLocalInt(OBJECT_SELF, "iMsgType");

    // Make sure there's an observation and that we're allowed to send it
    if (sObservation != "" && iMessageType)
    {
        // Speak or send the message...
        if (iMessageType == 1)
            SpeakThisOnce(oPC, sObservation);
        else // We screened 0 values, so if it's not 1, it's 2
            SayThisOnce(oPC, sObservation);

        // Check if the PC is supposed to receive an XP bonus
        int iXPBonus = GetLocalInt(OBJECT_SELF, "iXPBonus");

        if (iXPBonus)
            GiveXPToCreature(oPC, iXPBonus);
    }
}

Note for avoiding confusion later on: think about changing SayThisOnce() to SendMessageToPCOnce(). That way there's no getting Say/SpeakThisOnce() mixed up.

As for the P.S., yes you can use ActionStartConversation() or BeginConversation(). Both let you specify which dialog you want to use.

The P.P.S. should work, but keep in mind that it will be returning FALSE if you succeed on the check. If that's not what you want to do use this:

int StartingConditional()
{
    object oPC = GetPCSpeaker();
    return GetIsSkillSuccessfulPrivate(oPC, SKILL_ANIMAL_EMPATHY, 26);
}

               
               

               


                     Modifié par Squatting Monk, 18 août 2012 - 12:36 .
                     
                  


            

Legacy_JediMindTrix

  • Sr. Member
  • ****
  • Posts: 383
  • Karma: +0/-0
Simple Script Not Working
« Reply #3 on: August 18, 2012, 06:40:35 am »


               I wasn't able to get the NPC to start the conversation I wanted it to unless I had specified the actual file on the NPC. >.<

void main()
{

//if (GetLocalInt(OBJECT_SELF, "iStop")>= 1) return;

object oPC = GetEnteringObject();
if (!GetIsPC(oPC)) return;

object oTrigger = OBJECT_SELF;
object oSpeaker = GetObjectByTag(GetLocalString(oTrigger, "sSpeaker"));

AssignCommand(oPC, ActionStartConversation(oSpeaker, GetLocalString(oTrigger, "sConversation")));
}

What's the difference between having the return at the beginning instead of a Return True, Return False?


P.S. Took your advice, changed the names.



P.P.S.S.
void main()
{
object oPC = GetPCSpeaker();
AdjustAlignment(oPC, ALIGNMENT_GOOD, -3);
}

Since that is negative three, will it actually shift the alignment 3 points towards evil?
Also when your alignment shifts, will the game automatically tell the player or does the script have too?
               
               

               


                     Modifié par NineCoronas2021, 18 août 2012 - 08:59 .
                     
                  


            

Legacy_Squatting Monk

  • Hero Member
  • *****
  • Posts: 776
  • Karma: +0/-0
Simple Script Not Working
« Reply #4 on: August 18, 2012, 01:20:36 pm »


               Did you want the NPC to just use the conversation you set on it in the toolset? If so, just do this:

AssignCommand(oSpeaker, ActionStartConversation(oPC));

Leaving the second parameter of ActionStartConversation() blank will use the NPC's default conversation file.

Was that what you were looking for? If not, I don't think I understood.

NineCoronas2021 wrote...

What's the difference between having the return at the beginning instead of a Return True, Return False?

GetIsSkillSuccessfulPrivate() itself returns either TRUE or FALSE. So instead of having an extra conditional to check it, you can just return it. Essentially, there's no point in doing this...

if (TRUE)
    return TRUE;
else
    return FALSE;

...when this will work just fine:

return TRUE;

Note: This will not work for anything other than an int-returning function. Let's say you have a conditional script that will only return TRUE if the PC has a deity set. You can't write this:

return GetDeity(oPC);

...because GetDeity() is a string-returning function. However, you can still do this:

return (GetDeity(oPC) != "");

...because the conditional (GetDeity(oPC) != "") resolves to either TRUE or FALSE.

Does that make things clearer?

P.P.S.S.
void main()
{
object oPC = GetPCSpeaker();
AdjustAlignment(oPC, ALIGNMENT_GOOD, -3);
}

Since that is negative three, will it actually shift the alignment 3 points towards evil?
Also when your alignment shifts, will the game automatically tell the player or does the script have too?

Yes, I believe that's exactly how that'll work. I'm at work, so I don't have NWN in front of me but, IIRC, the message about the alignment shift is handled by this function as well. Only way to know for sure is to test and see. '<img'>
               
               

               


                     Modifié par Squatting Monk, 18 août 2012 - 12:41 .
                     
                  


            

Legacy_JediMindTrix

  • Sr. Member
  • ****
  • Posts: 383
  • Karma: +0/-0
Simple Script Not Working
« Reply #5 on: August 19, 2012, 12:43:51 am »


               

Squatting Monk wrote...

Did you want the NPC to just use the conversation you set on it in the toolset? If so, just do this:


No, I want the NPC to use a specific conversation file that exists in the module but is not set to the NPC.

Squatting Monk wrote...
Does that make things clearer?

Much clearer '<img'> Thanks!
               
               

               
            

Legacy_Squatting Monk

  • Hero Member
  • *****
  • Posts: 776
  • Karma: +0/-0
Simple Script Not Working
« Reply #6 on: August 19, 2012, 04:17:53 am »


               

NineCoronas2021 wrote...

Squatting Monk wrote...

Did you want the NPC to just use the conversation you set on it in the toolset? If so, just do this:

No, I want the NPC to use a specific conversation file that exists in the module but is not set to the NPC.

Oh, okay. That's what I thought originally.

Did the code you pasted above work, or no?
               
               

               


                     Modifié par Squatting Monk, 19 août 2012 - 03:18 .
                     
                  


            

Legacy_JediMindTrix

  • Sr. Member
  • ****
  • Posts: 383
  • Karma: +0/-0
Simple Script Not Working
« Reply #7 on: August 19, 2012, 04:53:19 am »


               It didn't work, for whatever reason. I would pass through the trigger, clearallactions would fire, and the script would try to initiate dialog with the NPC (the blue circle would appear around the NPC), but no conversation would fire UNTIL I set it on the NPC in toolset.
               
               

               


                     Modifié par NineCoronas2021, 19 août 2012 - 03:53 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Simple Script Not Working
« Reply #8 on: August 19, 2012, 05:17:27 am »


               AssignCommand(oPC, ActionStartConversation(oSpeaker, GetLocalString(oTrigger, "sConversation")));


ActionStartConversation: Is an Action, therefore it will get added to the PC's Action que. If you wanted them to try and start the conversation right then you would have to have them ClearAllActions first.    
               
               

               


                     Modifié par Lightfoot8, 19 août 2012 - 04:19 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Simple Script Not Working
« Reply #9 on: August 19, 2012, 05:18:41 am »


               oops.
               
               

               


                     Modifié par Lightfoot8, 19 août 2012 - 04:19 .
                     
                  


            

Legacy_Squatting Monk

  • Hero Member
  • *****
  • Posts: 776
  • Karma: +0/-0
Simple Script Not Working
« Reply #10 on: August 19, 2012, 05:32:15 am »


               I tested this code just now and it works fine, no ClearAllActions() needed. Check your variables and make sure the conversation you specified is correct.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Simple Script Not Working
« Reply #11 on: August 19, 2012, 05:50:45 am »


               

Squatting Monk wrote...

I tested this code just now and it works fine, no ClearAllActions() needed. Check your variables and make sure the conversation you specified is correct.


Would not be the first time I was wrong.
               
               

               
            

Legacy_JediMindTrix

  • Sr. Member
  • ****
  • Posts: 383
  • Karma: +0/-0
Simple Script Not Working
« Reply #12 on: August 19, 2012, 05:51:45 am »


               

Lightfoot8 wrote...

oops.


I actually had that in there before I posted this, in my troubleshooting I removed it to see if it was somehow involved.
               
               

               
            

Legacy_JediMindTrix

  • Sr. Member
  • ****
  • Posts: 383
  • Karma: +0/-0
Simple Script Not Working
« Reply #13 on: August 19, 2012, 05:53:57 am »


               (Double Post)
               
               

               


                     Modifié par NineCoronas2021, 19 août 2012 - 04:54 .
                     
                  


            

Legacy_Squatting Monk

  • Hero Member
  • *****
  • Posts: 776
  • Karma: +0/-0
Simple Script Not Working
« Reply #14 on: August 19, 2012, 05:54:32 am »


               

Lightfoot8 wrote...

Would not be the first time I was wrong.


Having clearAllActions() in there is smart, of course. I just didn't think that'd be the problem here, considering he did have the blue circle around the NPC (which shouldn't be there if the ActionStartConversation() was getting stuck behind another action).