Author Topic: Universal Yes/No Script?  (Read 356 times)

Legacy_Xxtayce

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
Universal Yes/No Script?
« on: February 07, 2011, 02:37:30 pm »


               I'm trying to make a universal set of scripts for yes/no for use in conversation. When a PC talks to an NPC, it should set a series of variables for has met, said yes, said no on the NPC for use with quests, and the variable should inclue the PC's first name so that it can be the same script used on all NPC conversations, but will store "HasMet_Tom" when Tom talks to the NPC, "HasMet_Bob" when Bob talks to the NPC, etc. Or, vice-versa, to have the name of the NPC stored on the PC with either yes/no/hasmet.

I'm close, but I'm certain that I'm calling the string wrong. Can anyone help?

[nwscript]int StartingConditional()
{
    object oPC = GetPCSpeaker();
    object oNPC = OBJECT_SELF;
    string sName = GetTag(oNPC);

    if(GetLocalInt(oPC, "No"+"sName")){
        return TRUE;
        }

    return FALSE;
}
[/nwscript]

Second attempt:

[nwscript]void main()
{
    //DeleteLocalInt(GetLastSpeaker(), "SaidYes");
    //SetLocalInt(GetLastSpeaker(), "SaidNo", TRUE);
    object oPC = GetPCSpeaker();
    object oNPC = GetLastSpeaker();
    string sName = GetTag(oNPC);

    if (GetLocalInt(oPC, "Yes"+"sName")){
        DeleteLocalInt(oPC, "Yes"+"sName");
        }

    SetLocalInt(oPC, "No"+"sName", TRUE);
    //AssignCommand(oNPC, SpeakString("Set int 'No'+sName.", TALKVOLUME_TALK));
}
[/nwscript]


PS: What's the code for showing code on these boards? NWScript doesn't seem to do it.
               
               

               


                     Modifié par Xxtayce, 07 février 2011 - 02:43 .
                     
                  


            

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
Universal Yes/No Script?
« Reply #1 on: February 07, 2011, 03:46:38 pm »


               1. Using First Name as a variable name, is insecure.  What happens if you are playing, doing a quest, and ur character is called Bob, and If I join your server, and decide to call my Character 'Bob' - My character would have access, and the ability to override/overwrite variables relating to your character.

- An Alternative to using FirstName, is using 'PlayerName'  -  no two players will have identical player names.



2. Your description of what you are trying to do, differs from what your code is doing.

You say you are going to use the Players Name as part of the variable, but in actual fact, this code seems to be using the NPC's tag as part of the variable. Further more - the variable is stored on the player, not the NPC.



3. There is no easy way of making a singlular unified script that handles All types of conversations, unless you start getting into CustomTokens and lots of complicated LocalVars.



This code might be close to what you need.

It involves 3 conditional scripts, and 3 void main action scripts.




int StartingConditional()    //Starting Conditional if the player has said NO
{
    object oPC = GetPCSpeaker();
    object oNPC = OBJECT_SELF;
    string sName = GetPCPlayerName(oPC);

    if(GetLocalInt(oNPC, "No_"+"sName")){
        return TRUE;
        }

    return FALSE;
}

int StartingConditional()    //Starting Conditional if the player has said YES
{
    object oPC = GetPCSpeaker();
    object oNPC = OBJECT_SELF;
    string sName = GetPCPlayerName(oPC);

    if(GetLocalInt(oNPC, "Yes_"+"sName")){
        return TRUE;
        }

    return FALSE;
}


int StartingConditional()    //Starting Conditional if the player has Met the NPC
{
    object oPC = GetPCSpeaker();
    object oNPC = OBJECT_SELF;
    string sName = GetPCPlayerName(oPC);

    if(GetLocalInt(oNPC, "HasMet_"+"sName")){
        return TRUE;
        }

    return FALSE;
}




void main()  //Player Meets the NPC
{

    object oPC = GetPCSpeaker();
    object oNPC = GetLastSpeaker();
    string sName = GetPCPlayerName(oPC);

   SetLocalInt(oNPC,"HasMet_"+sName,1);  //Player has now met the npc - put this in the Actions Taken for the introduction sequence of the conversation

}

void main()  //Player Says NO to the NPC
{

    object oPC = GetPCSpeaker();
    object oNPC = GetLastSpeaker();
    string sName = GetPCPlayerName(oPC);

   SetLocalInt(oNPC,"No_"+sName,1);  //Player has now said NO to the npc, put this in the Actions Taken for the NO Conversation item.

}

void main()  //Player Says Yes to the NPC
{

    object oPC = GetPCSpeaker();
    object oNPC = GetLastSpeaker();
    string sName = GetPCPlayerName(oPC);

   SetLocalInt(oNPC,"Yes_"+sName,1);  //Player has now said Yes to the npc, put this in the Actions Taken for the Yes Conversation item.

}

               
               

               
            

Legacy_Xxtayce

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
Universal Yes/No Script?
« Reply #2 on: February 07, 2011, 06:44:27 pm »


               Sorry! I think I had it the way I'd described originally but as it wasn't working, I changed it back again. I was having problems mostly with setting the string, I think. Even trying it to use the NPC's name set on the PC it wasn't working for me.



I'll try these and let you know how it goes! Thank you!
               
               

               
            

Legacy_Xovian

  • Full Member
  • ***
  • Posts: 158
  • Karma: +0/-0
Universal Yes/No Script?
« Reply #3 on: February 08, 2011, 01:02:21 am »


               

Xxtayce wrote...

PS: What's the code for showing code on these boards? NWScript doesn't seem to do it.


Use [ code ]  & [ / code ] , with out the spaces, though as far as can tell it isn't much different then how you wrote it.
It's not as good as it use to be in the old forums where it was in its own small window.
               
               

               


                     Modifié par Xovian, 08 février 2011 - 01:02 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Universal Yes/No Script?
« Reply #4 on: February 08, 2011, 01:39:47 am »


               Get rid of the Quotes around sName.  with the Quotes you are useing the string "sName"  that the variable that contains the tag that you stored.
 
I think you need to use OBJECT_SELF for oNpc instead of GetLastSpeaker()

Xxtayce wrote...

I'm trying to make a universal set of scripts for yes/no for use in conversation. When a PC talks to an NPC, it should set a series of variables for has met, said yes, said no on the NPC for use with quests, and the variable should inclue the PC's first name so that it can be the same script used on all NPC conversations, but will store "HasMet_Tom" when Tom talks to the NPC, "HasMet_Bob" when Bob talks to the NPC, etc. Or, vice-versa, to have the name of the NPC stored on the PC with either yes/no/hasmet.

I'm close, but I'm certain that I'm calling the string wrong. Can anyone help?

[nwscript]int StartingConditional()
{
    object oPC = GetPCSpeaker();
    object oNPC = OBJECT_SELF;
    string sName = GetTag(oNPC);

    if(GetLocalInt(oPC, "No"+"sName")){
        return TRUE;
        }

    return FALSE;
}
[/nwscript]

Second attempt:

[nwscript]void main()
{
    //DeleteLocalInt(GetLastSpeaker(), "SaidYes");
    //SetLocalInt(GetLastSpeaker(), "SaidNo", TRUE);
    object oPC = GetPCSpeaker();
    object oNPC =  GetLastSpeaker();
    string sName = GetTag(oNPC);

    if (GetLocalInt(oPC, "Yes"+"sName")){
        DeleteLocalInt(oPC, "Yes"+"sName");
        }

    SetLocalInt(oPC, "No"+"sNamecolor=red]"[/color], TRUE);
    //AssignCommand(oNPC, SpeakString("Set int 'No'+sName.", TALKVOLUME_TALK));
}
[/nwscript]


PS: What's the code for showing code on these boards? NWScript doesn't seem to do it.



I agree with Baaleos that it is a bad Idea to use the players name to store locals on the NPC,  So it is a good thing that you where not doing that,  It is good that you are useing the tag of the NPC to store the information on the PC.  
               
               

               


                     Modifié par Lightfoot8, 08 février 2011 - 01:44 .
                     
                  


            

Legacy_Xxtayce

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
Universal Yes/No Script?
« Reply #5 on: February 08, 2011, 04:31:26 pm »


               Works perfectly; thank you!

I've uploaded it to the vault and it should be visible at the following link once it's approved if anyone wants to download/use it: http://nwvault.ign.c....Detail&id=3794
               
               

               


                     Modifié par Xxtayce, 08 février 2011 - 04:31 .