Author Topic: Make a starting conditional script so it only runs once  (Read 335 times)

Legacy_UnrealJedi

  • Full Member
  • ***
  • Posts: 226
  • Karma: +0/-0
Make a starting conditional script so it only runs once
« on: June 16, 2012, 07:21:48 pm »


               Hello all:

I used the wizard in the conversation editor to create thris script. It makes a line show up if the PC has a specific item in his/her inventory. I need it to only run once, even if the item is still in the PC's inventory. I tried using the Script Generator but I did not find an option to write starting conditional scripts so they run only once.

I'm sure this is an easy fix but I can't figure it out.

Thanks for any help!

//::///////////////////////////////////////////////
//:: FileName sc_atnote
//:://////////////////////////////////////////////
//:://////////////////////////////////////////////
//:: Created By: Script Wizard
//:: Created On: 2/11/2012 1:45:18 PM
//:://////////////////////////////////////////////
#include "nw_i0_tool"

int StartingConditional()
{

    // Make sure the PC speaker has these items in their inventory
    if(!HasItem(GetPCSpeaker(), "AncientTemple"))
        return FALSE;

    return TRUE;
}
               
               

               
            

Legacy_Kato -

  • Hero Member
  • *****
  • Posts: 747
  • Karma: +0/-0
Make a starting conditional script so it only runs once
« Reply #1 on: June 16, 2012, 07:47:43 pm »


               int StartingConditional()
{
    object oPC = GetPCSpeaker();
    string sVar = GetPCPlayerName(oPC) + GetName(oPC);
    if(GetLocalInt(OBJECT_SELF, sVar)) return FALSE;
    if(GetItemPossessedBy(oPC, "AncientTemple") != OBJECT_INVALID)
    {
        SetLocalInt(OBJECT_SELF, sVar, TRUE);
        return TRUE;
    }
    return FALSE;
}

EDIT: L8 solution is even better if his assumption is correct


Kato
               
               

               


                     Modifié par Kato_Yang, 16 juin 2012 - 06:52 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Make a starting conditional script so it only runs once
« Reply #2 on: June 16, 2012, 07:49:49 pm »


               Assumptions I made in the rewrite.  
The item is unique. 
You only want the item used once.  Passing it to another PC, Will not allow it to be used again.


int StartingConditional()
{
        object oItem = GetItemPossessedBy(GetPCSpeaker(), "AncientTemple");
        if (oItem != OBJECT_INVALID)
        {
           int nUsed = GetLocalInt(oItem,"used");
           if (!nUsed)
           {
              SetLocalInt(oItem,"used",TRUE);
              return TRUE;
           }
        }
        return FALSE;
}
               
               

               
            

Legacy_UnrealJedi

  • Full Member
  • ***
  • Posts: 226
  • Karma: +0/-0
Make a starting conditional script so it only runs once
« Reply #3 on: June 16, 2012, 07:52:58 pm »


               Thanks to both of you for your quick replies! It's a SP module so it will only be used once by default.

Thanks again!