Aller au contenu

Photo

OnAquireItem Problem


  • Veuillez vous connecter pour répondre
7 réponses à ce sujet

#1
JerrodAmolyan

JerrodAmolyan
  • Members
  • 89 messages
 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 ?

#2
JerrodAmolyan

JerrodAmolyan
  • Members
  • 89 messages
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?

#3
Squatting Monk

Squatting Monk
  • Members
  • 446 messages
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 .


#4
JerrodAmolyan

JerrodAmolyan
  • Members
  • 89 messages
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

#5
JerrodAmolyan

JerrodAmolyan
  • Members
  • 89 messages
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 .


#6
Squatting Monk

Squatting Monk
  • Members
  • 446 messages
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.

#7
Squatting Monk

Squatting Monk
  • Members
  • 446 messages
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 .


#8
JerrodAmolyan

JerrodAmolyan
  • Members
  • 89 messages
There we go now it works like a charm. Thanks :)