Author Topic: OnAcquire Help  (Read 336 times)

Legacy_Xanodus

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
OnAcquire Help
« on: October 30, 2010, 06:41:56 am »


               Hey guys I'm back with another question.  Alright so to reduce the number of objects I have to create, I created an OnAcquire script that gives the item tagged a random Damage property.  The script works perfectly, even coloring the name '<img'> but i've run into a problem.

Even if the Object is already given its item properties, at times if the item is dropped and then picked up again then another weapon within the user's inventory can recieve the same random properties.

Is there any way to prevent this from occuring?  If discovered a player could easily abuse it and continue to populate his basic longsword collection full of elemental damage, and then proceed to sell them for profit.  I'm not very experienced in the ItemProperty area so please let me know if i'm doing something wrong.


CONTENTS BELOW
1. eleweap (tagbased system, the effect)
2. snippet of GetWeaponType function
3. aq_eleweap (part of tagbased system)

eleweap
sWeapon = GetWeaponType(oItem);   returns a string with the weapon's "type" based on a local variable placed upon the item.

#include "x2_inc_itemprop"
#include "csu_library"

void main()
{
    object oItem = GetModuleItemAcquired();
    itemproperty ipAdd;

    string sName;
    string sWeapon;

    int nProp = GetLocalInt( oItem, "Enchanted");
    int nRand = d4();


    if (nProp == 0)
    {
        switch (nRand)
        {
            case 1:
                ipAdd = ItemPropertyDamageBonus(IP_CONST_DAMAGETYPE_ACID, IP_CONST_DAMAGEBONUS_1d6);
                sName = "Acid";
                break;
            case 2:
                ipAdd = ItemPropertyDamageBonus(IP_CONST_DAMAGETYPE_FIRE, IP_CONST_DAMAGEBONUS_1d6);
                sName = "Flame";
                break;
            case 3:
                ipAdd = ItemPropertyDamageBonus(IP_CONST_DAMAGETYPE_COLD, IP_CONST_DAMAGEBONUS_1d6);
                sName = "Ice";
                break;
            case 4:
                ipAdd = ItemPropertyDamageBonus(IP_CONST_DAMAGETYPE_ELECTRICAL, IP_CONST_DAMAGEBONUS_1d6);
                sName = "Thunder";
                break;
            default:
                break;
        }
        sWeapon = GetWeaponType(oItem);
        IPSafeAddItemProperty(oItem, ipAdd);
        sName = ColorString(("Elemental " + sWeapon + " of " + sName), 0, 255, 0);
        SetName(oItem , sName);
        SetLocalInt( oItem, "Enchanted", nRand);
    }
    else
    {
        // Do Nothing
    }
}


GetWeaponType snippet. just a shortened example of the function

// CHECKS INT "Type" & RETURNS WEAPON TYPE
string GetWeaponType(object oItem)
{
    string sType = "Weapon";
    int nType = GetLocalInt( oItem, "Type");

    switch (nType)
    {
        // Bladed
        case 1:
            sType = "Dagger";
            break;
        case 2:
            sType = "Shortsword";
            break;
        case 3:
            sType = "Longsword";
            break;
        case 4:
            sType = "Greatsword";
            break;
        default:
            sType = "0";
            break;
    }
    return sType;
}


aq_eleweap
(taken from Lilac's Script Generator)


#include "x2_inc_switches"

void main()
{
    int nEvent =GetUserDefinedItemEventNumber();

    switch (nEvent)
    {
        case X2_ITEM_EVENT_ACTIVATE:
            ExecuteScript("ac_"+GetTag(GetItemActivated()), OBJECT_SELF);
            break;
        case X2_ITEM_EVENT_EQUIP:
            ExecuteScript("eq_"+GetTag(GetPCItemLastEquipped()), OBJECT_SELF);
            break;
        case X2_ITEM_EVENT_UNEQUIP:
            ExecuteScript("ue_"+GetTag(GetPCItemLastUnequipped()), OBJECT_SELF);
            break;
        case X2_ITEM_EVENT_ACQUIRE:
            ExecuteScript("aq_"+GetTag(GetModuleItemAcquired()), OBJECT_SELF);
            break;
        case X2_ITEM_EVENT_UNACQUIRE:
            ExecuteScript("ua_"+GetTag(GetModuleItemLost()), OBJECT_SELF);
            break;
        case X2_ITEM_EVENT_SPELLCAST_AT:
            ExecuteScript("sp_"+GetTag(GetModuleItemLost()), OBJECT_SELF);
            break;
        case X2_ITEM_EVENT_ONHITCAST:
            ExecuteScript("on_"+GetTag(GetSpellCastItem()), OBJECT_SELF);
            break;
   }
}


               
               

               


                     Modifié par Xanodus, 30 octobre 2010 - 05:43 .
                     
                  


            

Legacy_Builder_Anthony

  • Hero Member
  • *****
  • Posts: 786
  • Karma: +0/-0
OnAcquire Help
« Reply #1 on: October 30, 2010, 07:24:18 am »


               Ok well you have to explain why and how the pc gets this specail item.

My guess is that you should only do it once per pc so it doesnt fire every time he receives a item.

Or you could set a varible on the pc if he is holding the tagged item and A PROPERTY IS applied  then just ignore applying the effects.

How and why is the pc getteing item?
               
               

               


                     Modifié par Builder_Anthony, 30 octobre 2010 - 06:28 .
                     
                  


            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
OnAcquire Help
« Reply #2 on: October 30, 2010, 08:30:31 am »


               I'm pretty sure it's because you have your Lilac's activated script naming conventions backward. Your last script should be named "eleweap" and the first should be "aq_eleweap". If you switch those it should work.

However, and not in any way to put down Lilac's (since his generator is the reason I learned to script), Lilac's has a redundancy in the tag based scripting that you should probably unlearn. With Lilac's you need 2 scripts for every tag based event. The generic one that you have posted above that checks for the item event numbers and then the actual script that is executed.

Instead you can skip the generic item event check script and just add a check to each one of your main tag based scripts.

So in this case you would keep the name of your first script as is if that is the tag of the weapon that is acquired. And then you add the item event check at the top of that script to make sure that it is only going to do stuff if the item was acquired and NOT unacquired, activated, equipped, unequipped, etc..
So your first script would look like so:

#include "x2_inc_itemprop"
#include "csu_library"

void main()
{
    //Check to make sure this script only continues if the item was "acquired".
    //If not then end.
    int nEvent =GetUserDefinedItemEventNumber();
    if (nEvent != X2_ITEM_EVENT_ACQUIRE) return;

    object oItem = GetModuleItemAcquired();
    itemproperty ipAdd;

    string sName;
    string sWeapon;

    int nProp = GetLocalInt( oItem, "Enchanted");
    int nRand = d4();


    if (nProp == 0)
    {
        switch (nRand)
        {
            case 1:
                ipAdd = ItemPropertyDamageBonus(IP_CONST_DAMAGETYPE_ACID, IP_CONST_DAMAGEBONUS_1d6);
                sName = "Acid";
                break;
            case 2:
                ipAdd = ItemPropertyDamageBonus(IP_CONST_DAMAGETYPE_FIRE, IP_CONST_DAMAGEBONUS_1d6);
                sName = "Flame";
                break;
            case 3:
                ipAdd = ItemPropertyDamageBonus(IP_CONST_DAMAGETYPE_COLD, IP_CONST_DAMAGEBONUS_1d6);
                sName = "Ice";
                break;
            case 4:
                ipAdd = ItemPropertyDamageBonus(IP_CONST_DAMAGETYPE_ELECTRICAL, IP_CONST_DAMAGEBONUS_1d6);
                sName = "Thunder";
                break;
            default:
                break;
        }
        sWeapon = GetWeaponType(oItem);
        IPSafeAddItemProperty(oItem, ipAdd);
        sName = ColorString(("Elemental " + sWeapon + " of " + sName), 0, 255, 0);
        SetName(oItem , sName);
        SetLocalInt( oItem, "Enchanted", nRand);
    }
    else
    {
        // Do Nothing
    }
}

Hope that helps. Good luck.
               
               

               


                     Modifié par GhostOfGod, 30 octobre 2010 - 07:31 .
                     
                  


            

Legacy_Xanodus

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
OnAcquire Help
« Reply #3 on: October 30, 2010, 11:57:28 pm »


               W00t Thankees Man =) I shall indeed use the method you provided.  I've just been copy pasting his code and hoping he had everything down.  Never looked to see what it was doing.  



Just took a good look at it and yeah it'd be better to use a specific check method like you did if i'm only going to use one functionality of the tag-based system.