Author Topic: Another script needs help  (Read 684 times)

Legacy_archer4217

  • Full Member
  • ***
  • Posts: 206
  • Karma: +0/-0
Another script needs help
« on: September 07, 2011, 01:22:02 am »


               Hi all,

Could someone fix this script so that 2 blueberries are needed instead of just 1? The generator doesn't give the option to set a specific number of a needed item.

Thank you so much. '<img'>

/*BLACKSMITH SCRIPT
Created by
Lilac Soul's NWN Script Generator, v. 2.3
for download info please visit
http://nwvault.ign.c...&id=4683&id=625
*/

int lsn=1;
//lsstype=2

void SetItemLocals()
{
SetLocalString(OBJECT_SELF, "lsn1", "blueberrypie");
SetLocalInt(OBJECT_SELF, "lsc_blueberrypie", 1);
SetLocalString(OBJECT_SELF, "lsi1_blueberrypie", "FoodBlueberries");
SetLocalInt(OBJECT_SELF, "lss_blueberrypie", -10);
SetLocalInt(OBJECT_SELF, "lsv_blueberrypie", VFX_FNF_SMOKE_PUFF);

}

void CreateGold(object oTarget, int nAmount)
{
CreateItemOnObject("nw_it_gold001", oTarget, nAmount);
}

void main()
{
object oOwner=OBJECT_SELF;

if (!GetLocalInt(OBJECT_SELF, "lsvar_set"))
{
SetItemLocals();
SetLocalInt(OBJECT_SELF, "lsvar_set", TRUE);
}

if (lsn==0) return;

object oItem;
int bOkay, nGold, nCount, nNum, nLoop, nLoops, nHasGold, nVis;
string sCur, sReq;

for (nLoop=1; nLoop<=lsn; nLoop++)
   {
   sCur=GetLocalString(OBJECT_SELF, "lsn"+IntToString(nLoop));

   nNum=GetLocalInt(OBJECT_SELF, "lsc_"+sCur);

   for (nLoops=1; nLoops<=nNum; nLoops++)
      {

      sReq=GetLocalString(OBJECT_SELF, "lsi"+IntToString(nLoops)+"_"+sCur);
      if (GetStringLeft(sReq, 8)=="  gold  ")
         {
         nGold=StringToInt(GetStringRight(sReq, GetStringLength(sReq)-8));
         if (GetGold(oOwner)>=nGold) nCount++;

         }
      else if (GetItemPossessedBy(oOwner, sReq)!=OBJECT_INVALID)
         {
         SetLocalObject(OBJECT_SELF, "ls__"+IntToString(nLoops), GetItemPossessedBy(oOwner, sReq));

         nCount++;
         }
      }

   if (GetLocalInt(OBJECT_SELF, "lss_"+sCur)==-10) bOkay=TRUE;
   else if (GetLastSpell()==GetLocalInt(OBJECT_SELF, "lss_"+sCur)) bOkay=TRUE;
   else bOkay=FALSE;

   if (bOkay && (nCount==nNum)) bOkay=TRUE;
   else bOkay=FALSE;
   if (bOkay==TRUE)
      {

      if (nGold>0)
      {
      nHasGold=GetGold(oOwner);
      DestroyObject(GetItemPossessedBy(oOwner, "NW_IT_GOLD001"));
      DelayCommand(0.2, CreateGold(oOwner, nHasGold-nGold));
      }
      for (nLoops=1; nLoops<=nNum; nLoops++)
         {
         oItem=GetLocalObject(OBJECT_SELF, "ls__"+IntToString(nLoops));
         DestroyObject(oItem);
         }
      CreateItemOnObject(sCur, oOwner);
      int nVis=GetLocalInt(OBJECT_SELF, "lsv_"+sCur);
      if (nVis!=-10) ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(nVis), oOwner);
      }

   oItem=OBJECT_INVALID;
   bOkay=FALSE;
   nGold=0;
   nCount=0;
   sCur="";
   sReq="";
   nNum=0;
   }
}
               
               

               
            

Legacy_Baragg

  • Sr. Member
  • ****
  • Posts: 496
  • Karma: +0/-0
Another script needs help
« Reply #1 on: September 07, 2011, 01:42:38 am »


               Can't get to my toolset right now, there is a GetNumItems function in one of the includes but without getting to the toolset I can't recall the include.
               
               

               
            

Legacy_Kato -

  • Hero Member
  • *****
  • Posts: 747
  • Karma: +0/-0
Another script needs help
« Reply #2 on: September 07, 2011, 05:04:36 am »


               GetNumItems() is in nw_i0_plot. '<img'>

Kato
               
               

               
            

Legacy_archer4217

  • Full Member
  • ***
  • Posts: 206
  • Karma: +0/-0
Another script needs help
« Reply #3 on: September 08, 2011, 08:05:22 pm »


               Thanks sweeties.
               
               

               
            

Legacy_archer4217

  • Full Member
  • ***
  • Posts: 206
  • Karma: +0/-0
Another script needs help
« Reply #4 on: September 09, 2011, 12:29:33 am »


               Hiya sweeties,

I seem to have never ending script problems this week. ':crying:' Here's my lastest dud. I want to feed a chicken some corn kernels and have it lay an egg. The chicken is eating the corn, but not laying the egg. I checked to make sure the tags are correct. Once again, I'm stumped and any help is greatly appreciated.

Thank you in advance. '<img'>

/*   Script generated by
Lilac Soul's NWN Script Generator, v. 2.3

For download info, please visit:
http://nwvault.ign.c...=4683&id=625    */

//Put this on action taken in the conversation editor
void main()
{

object oPC = GetPCSpeaker();

object oItem;
oItem = GetItemPossessedBy(oPC, "CornKernels");

if (GetIsObjectValid(oItem))
   DestroyObject(oItem);

ActionPutDownItem(GetObjectByTag("ChickenEgg"));

}
               
               

               
            

Legacy_Hardcore UFO

  • Full Member
  • ***
  • Posts: 157
  • Karma: +0/-0
Another script needs help
« Reply #5 on: September 09, 2011, 04:01:03 am »


               The way it's structured, the PC is called to lay the egg. Also, ActionPutDownItem makes an item drop from your inventory, you might want to use CreateObject instead. This might work (I'm fuzzy on my chicken fetching, I haven't done many conversation triggered scripts yet):

void main()
{

object oPC = GetPCSpeaker();
object oChicken = OBJECT_SELF; //Presuming this is in the chicken's conversation node
location lLay = GetLocation(oChicken);

object oItem;
oItem = GetItemPossessedBy(oPC, "CornKernels");

if (GetIsObjectValid(oItem))
DestroyObject(oItem);

CreateObject(OBJECT_TYPE_ITEM, "RESREF of the egg from Item Properties Advanced tab", lLay, FALSE);

}
               
               

               


                     Modifié par Hardcore UFO, 09 septembre 2011 - 03:01 .
                     
                  


            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Another script needs help
« Reply #6 on: September 09, 2011, 05:42:03 am »


               

Hardcore UFO wrote...

The way it's structured, the PC is called to lay the egg.


As long as the conversation belongs to the chicken this is not true. Any actions that are not specifically assigned will be carried out by the NPC owner of the conversation.

I think the problem you might be having is that you are just getting object by tag instead of getting an egg that is possessed by the chicken. If you just call GetObjectByTag, it's going to grab the first item in the module it ffinds with that tag. The other problem might be that the chicken doesn't actually have the eggs in it's inventory.

If in fact you want the chicken to drop the eggs that it possesses in it's inventory then you should probably do something more like so:


void main()
{
    object oPC = GetPCSpeaker();
    object oKernel = GetItemPossessedBy(oPC, "CornKernels");
    object oEgg = GetItemPossessedBy(OBJECT_SELF, "ChickenEgg");

    if (!GetIsObjectValid(oKernel))//PC has no corn.
    {
        SendMessageToPC(oPC, "You do not have any corn kernels.");
        return;
    }

    if (!GetIsObjectValid(oEgg))//Chicken has no eggs.
    {
        SendMessageToPC(oPC, "This chicken doesn't seem to want to lay any eggs right now.");
        return;
    }

    DestroyObject(oKernel);
    ActionPutDownItem(oEgg);
}


If you want to just create an egg where the chicken is at then you should use UFOs suggestion with the CreateObject function. On a side note if you want more than one corn kernel taken you will need to use other functions like GetNum/TakeNumItems instead of just using DestroyObject.
               
               

               


                     Modifié par GhostOfGod, 09 septembre 2011 - 04:55 .
                     
                  


            

Legacy_archer4217

  • Full Member
  • ***
  • Posts: 206
  • Karma: +0/-0
Another script needs help
« Reply #7 on: September 09, 2011, 09:04:32 am »


               UFO's script worked perfectly. It did exactly what I needed. Thank you both so very much. *hugs*