Author Topic: OnAcquireItem problem  (Read 323 times)

Legacy_Bubba McThudd

  • Sr. Member
  • ****
  • Posts: 254
  • Karma: +0/-0
OnAcquireItem problem
« on: May 16, 2011, 12:14:17 am »


                 

Greetings All,




I’m scripting a battle and
I want four things to happen when you capture the goblins’ banner;

1) a journal entry is made

2) a local integer is set
(nVictorLV)

3) two sound items play.

4) the script "gob_retreat"
fires, causing the goblins to flee.

 

I tested this with an
invisible character taking the banner out of a barrel right in front of the
goblin lines, and it worked perfectly. 
But when I put the banner in the goblins’ shield slot, the gob_retreat script
fired instantly and the goblin army scampered away as soon as the area
loaded.  But the local integer was not
set, the journal entry was not made, nor did the sounds play.  Below is the relevant section of my
OnAcquireItem script.

 

Any ideas?

 

   else
if(GetTag(oItem)=="GoblinStandard")

        {

       
AddJournalQuestEntry("GoblinStandard", 2, oPC);

        SetLocalInt(oPC,
"nVictorLV", 1);

        object oPC =
GetPCSpeaker();

        object oTarget;

        oTarget =
GetObjectByTag("sCheers1lv");

       
SoundObjectPlay(oTarget);

        oTarget =
GetObjectByTag("sCheers2lv");

       
SoundObjectPlay(oTarget);

       
ExecuteScript("gob_retreat", OBJECT_SELF);

  }

}
               
               

               
            

Legacy_MrZork

  • Hero Member
  • *****
  • Posts: 1643
  • Karma: +0/-0
OnAcquireItem problem
« Reply #1 on: May 16, 2011, 12:39:07 am »


               Hard to tell from that script fragment, but it looks like oPC may be declared after it is used. It's possible that it is also declared elsewhere in your script, but we can't see that here. Try putting the
object oPC = GetPCSpeaker();
line as the first thing in the
if
block. Also, since this may not be part of a conversation, I don't know if GetPCSpeaker will do what you want. You would be better off using a different function to get the PC.
               
               

               


                     Modifié par MrZork, 15 mai 2011 - 11:42 .
                     
                  


            

Legacy_Bubba McThudd

  • Sr. Member
  • ****
  • Posts: 254
  • Karma: +0/-0
OnAcquireItem problem
« Reply #2 on: May 16, 2011, 03:15:36 am »


               After some experimenting, I'm fairly sure that the problem resides in the line

ExecuteScript("gob_retreat", OBJECT_SELF);

Not sure what the correct formulation is though.
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
OnAcquireItem problem
« Reply #3 on: May 16, 2011, 03:38:00 am »


               Probably just need to change OBJECT_SELF to oPC if the script is supposed to run on whoever acquired the item. But also like MrZork already said, you are using oPC in a function before you even define it. Unless you are doing it twice in your script for some reason.

Something else I don't understand though...if this is an OnAcquire script then why are you even using GetPCSpeaker? You should be using GetModuleItemAcquiredBy. And if this is a tag based script then you also need a check at the top of your script for the item event if you don't already have one. I guess I'm not really clear as to what is going on here.

You really should post the whole script.

I see you have a tag check for the item which means you are probably not using tag based scripting for this. Probably putting everything into an OnAcquire script? This is all just speculation of course.

Your script should/might look something like so:

void main()
{
    //object oPC = GetPCSpeaker();
    object oPC = GetModuleItemAcquiredBy();
    //stuff
    //other stuff
    //if (//stuff)
    //{
        //stuff
    //}

    else if(GetTag(oItem)=="GoblinStandard")
    {
        object oTarget;

        AddJournalQuestEntry("GoblinStandard", 2, oPC);
        SetLocalInt(oPC, "nVictorLV", 1);

        oTarget = GetObjectByTag("sCheers1lv");
        SoundObjectPlay(oTarget);

        oTarget = GetObjectByTag("sCheers2lv");
        SoundObjectPlay(oTarget);

        ExecuteScript("gob_retreat", oPC);
    }
}
               
               

               


                     Modifié par GhostOfGod, 16 mai 2011 - 02:54 .
                     
                  


            

Legacy_The Amethyst Dragon

  • Hero Member
  • *****
  • Posts: 2981
  • Karma: +0/-0
OnAcquireItem problem
« Reply #4 on: May 16, 2011, 04:23:31 am »


               Also, you might want to have the script check to make sure the desired outcomes (journal, variable, retreat call) don't happen unless the one that acquired the flag is a player character.  Use GetIsPC(oPC)     '<img'>
               
               

               


                     Modifié par The Amethyst Dragon, 16 mai 2011 - 03:23 .
                     
                  


            

Legacy_Khuzadrepa

  • Sr. Member
  • ****
  • Posts: 347
  • Karma: +0/-0
OnAcquireItem problem
« Reply #5 on: May 17, 2011, 04:25:19 am »


               I agree, posting the entire script would help a lot. '<img'>
               
               

               


                     Modifié par Khuzadrepa, 17 mai 2011 - 03:29 .