Author Topic: OnAquireItem Problem  (Read 261 times)

Legacy_JerrodAmolyan

  • Full Member
  • ***
  • Posts: 175
  • Karma: +0/-0
OnAquireItem Problem
« on: August 10, 2013, 09:00:21 pm »


                It looks like it atleast. For some reason, when I pick one of my custom items (In this case it's an item that has a "Unique Power: Self" property, which would spawn a placeable next to you when used...) it fires the script when you pick the item up. That's some weird stuff, and help would be much appreciated. 

Here's the script that fires when it's not supposed to (when you acquire it): 

void main(){object oPC;
object oTarget;object oSpawn;location lTarget;oPC = GetItemActivator();
oTarget = oPC;
lTarget = GetLocation(oTarget);
oSpawn = CreateObject(OBJECT_TYPE_PLACEABLE, "jer_boombarrel", lTarget);
object oItem;oItem = GetItemPossessedBy(oPC, "jer_explosives");
if (GetIsObjectValid(oItem))   DelayCommand(1.0, DestroyObject(oItem));
}

I think I should also mention that I have x2_mod_def_aqu as my "OnAquireItem" event (default) in my module

Anyone can help me with this ?
               
               

               
            

Legacy_JerrodAmolyan

  • Full Member
  • ***
  • Posts: 175
  • Karma: +0/-0
OnAquireItem Problem
« Reply #1 on: August 10, 2013, 09:19:58 pm »


               Small correction: It starts doing this after you have used it once, dropped it and picked it up again (Then all the items with the same tag start doing this) Is there a way to stop that from happening?
               
               

               
            

Legacy_Squatting Monk

  • Hero Member
  • *****
  • Posts: 776
  • Karma: +0/-0
OnAquireItem Problem
« Reply #2 on: August 10, 2013, 09:34:43 pm »


               This is a tag-based script. It will fire whenever any of the following events happen with this item:  OnActivateItem, OnAcquireItem, OnPlayerEquipItem   , OnPlayerUnEquipItem, OnUnAcquireItem, OnSpellCastAt, and OnHitCast. What you need to do is figure out which event is being called and execute your code only for that event.


#include "x2_inc_switches"

void main()
{
    // Abort if we're not activating the item
    if (GetUserDefinedItemEventNumber() != X2_ITEM_EVENT_ACTIVATE)
        return;
       
    object oPC = GetItemActivator();
    CreateObject(OBJECT_TYPE_PLACEABLE, "jer_boombarrel", GetLocation(oPC));
   
    // Should this be...?
    // object oItem = GetItemActivated();
    object oItem = GetItemPossessedBy(oPC, "jer_explosives");

    if (GetIsObjectValid(oItem))
        DestroyObject(oItem, 1.0);
}

               
               

               


                     Modifié par Squatting Monk, 10 août 2013 - 08:56 .
                     
                  


            

Legacy_JerrodAmolyan

  • Full Member
  • ***
  • Posts: 175
  • Karma: +0/-0
OnAquireItem Problem
« Reply #3 on: August 10, 2013, 09:54:17 pm »


               Basicly: You pick up the Gunpowder Keg, You use it's unique power: self, it spawns the "jer_boombarrel" which is a barrel placeable to replace the inventory item. But all the other scripts work just fine. Except when I shoot the barrel with a gun, it blows up before the gun fires. LoL, maybe I should have made the blow up script "OnDamaged" rather than "OnPhysicalAttacked"...

Thanks for the help, I figured out it has to do with the user defined events when I looked through the treasuremap script you gave me and saw that line. Just haven't been able to apply it, it just says "missing right bracket" or something, but then again I also forgot to include switches... *babbles on* Well anyway, lots of thanks, will try out this script now and see if it needs that ItemActivated part. \\o
               
               

               
            

Legacy_JerrodAmolyan

  • Full Member
  • ***
  • Posts: 175
  • Karma: +0/-0
OnAquireItem Problem
« Reply #4 on: August 10, 2013, 09:56:08 pm »


               Ahha. Yeah. I'm still getting:

jer_explosives.nss(6): ERROR: NO LEFT BRACKET ON EXPRESSION

Which points at the if sentence...

Why?
               
               

               


                     Modifié par JerrodAmolyan, 10 août 2013 - 08:56 .
                     
                  


            

Legacy_Squatting Monk

  • Hero Member
  • *****
  • Posts: 776
  • Karma: +0/-0
OnAquireItem Problem
« Reply #5 on: August 10, 2013, 09:56:33 pm »


               I see. If "jer_explosives" is the tag of the item being activated, you can replace the GetIemPossessedBy() line with the GetItemActivated() line I commented out.
               
               

               
            

Legacy_Squatting Monk

  • Hero Member
  • *****
  • Posts: 776
  • Karma: +0/-0
OnAquireItem Problem
« Reply #6 on: August 10, 2013, 09:57:44 pm »


               My bad. I am coding this at work, so I don't have a compiler to test for errors. Change line 4 to this:

    if (GetUserDefinedItemEventNumber() != X2_ITEM_EVENT_ACTIVATE)
I forgot that initial parenthesis before GetUserDefinedItemNumber().
               
               

               


                     Modifié par Squatting Monk, 10 août 2013 - 08:59 .
                     
                  


            

Legacy_JerrodAmolyan

  • Full Member
  • ***
  • Posts: 175
  • Karma: +0/-0
OnAquireItem Problem
« Reply #7 on: August 10, 2013, 10:01:41 pm »


               There we go now it works like a charm. Thanks '<img'>