Skip to content

No success making an activatable magic weapon ...

AtrophiedericAtrophiederic Member, Mobile Tester Posts: 147
edited January 2021 in Builders - Scripting
Greetings, forum friends, and Happy Hollidays!

I have been attempting to create a magic item that is a standard long sword, until its power is activated, and then all sorts of nifty bonuses are applied. Then, when you activate the power again, the nifty bonuses are stripped off the weapon, so you are left with a normal longsword again. So far, I've had no success with it, as the thread title suggests.

Can anyone offer any eyeballs and suggestions? This is what I have so far ...

I start with a longsword item, tag of "magicfiresword". It has the "unique power self only unlimited" on it. It also has a variable on it, also "magicfiresword", set to 0.

I have an entry in my module's "x2_mod_def_act" script that looks like this:
{
    if (GetTag(GetItemActivated()) == "magicfiresword")
    ExecuteScript("magicfiresword", OBJECT_SELF);
{

Everything compiles fine, so far. Now for the "magicfiresword" script itself - this is what it looks like:
void main()
{
    object oTarget;
    oTarget = GetObjectByTag("magicfiresword");

    // If the local int is exactly 0.
    if (GetLocalInt(oTarget, "mfs") == 0)
    {
        // Run scripts to add properties to item.
        ExecuteScript("_dmgbns_1d10fir", OBJECT_SELF);
        ExecuteScript("_viseff_fir", OBJECT_SELF);
        ExecuteScript("_lgtbrt_orng", OBJECT_SELF);
        // Set local int to 1
        SetLocalInt(oTarget, "mfs", 1);
    }
    else
    // If the local int is exactly 1.
    if (GetLocalInt(oTarget, "mfs") == 1)
    {
        // Run scripts to remove properties from item.
        ExecuteScript("remove_fir1d10", OBJECT_SELF);
        ExecuteScript("rmv_viseff_fir", OBJECT_SELF);
        ExecuteScript("rmv_brt_lgt_orng", OBJECT_SELF);
        // Set local int to 0.
        SetLocalInt(oTarget, "mfs", 0);
    }
}

I was thinking to use the variable to notate when the sword is powered or not.

The script compiles with no errors. Whenever I activate the sword's power, I get nothing.
I have other items which assign properties in the "ExecuteScript" fashion, so I am not sure what I am doing wrong.

If anyone can offer any assistance, I will be eternally grateful! And I apologize in advance if I have left out any relevant pieces of information!

Eric

(The code in this post was edited to reflect a change in the variable used, from "magicfiresword" to "mfs", to help reduce confusion.)
Post edited by Atrophiederic on

Comments

  • BaireswolfBaireswolf Member Posts: 22
    edited January 2021
    What happens if you define "oTarget = OBJECT_SELF;" ?

    And there's no need to refefine it inside the conditionals. It will work just at the beginning.
  • AtrophiedericAtrophiederic Member, Mobile Tester Posts: 147
    Friend @Baireswolf ,

    I removed the definition inside the conditionals, as you can see in the edit of my original script above.

    As far as going from
    oTarget = GetObjectByTag("magicfiresword");
    
    to
    oTarget = OBJECT_SELF;
    
    - the script compiles fine, but gives the same result as my initial script, nothing.

    Regardless, thank you for your help!

    Eric
  • BaireswolfBaireswolf Member Posts: 22
    edited January 2021
    The "_dmgbns_1d10fir" script works OK on its own? (I mean without being called)
  • Old_GithOld_Gith Member Posts: 152
    I'm no expert, but typically any item in which you assign a unique property is going to require some sort of tag-based scripting approach. I usually have "#include "x2_inc_switches" as my include, and then some sort of void OnActivate(); followed by the standard:
    void main()
        {
        int nEvent = GetUserDefinedItemEventNumber();
        int nResult = X2_EXECUTE_SCRIPT_CONTINUE;
        switch (nEvent)
            {
            case X2_ITEM_EVENT_ACTIVATE:
                OnActivate();
                nResult = X2_EXECUTE_SCRIPT_END;
                break;
            case X2_ITEM_EVENT_EQUIP:
            case X2_ITEM_EVENT_UNEQUIP:
            case X2_ITEM_EVENT_ACQUIRE:
            case X2_ITEM_EVENT_UNACQUIRE:
            case X2_ITEM_EVENT_SPELLCAST_AT:
            case X2_ITEM_EVENT_ONHITCAST:
                break;
            }
            SetExecutedScriptReturnValue(nResult);
        }
    
    void OnActivate()
        {
        object oPC = GetItemActivator();
    

    and so on where you put what's actually going to happen. Also, I would probably delaycommand some of those execute script commands so they're not all trying to fire at once, like 0.2, 0.4, 0.6, and then delay command the variable to 1.0.

    Also, make sure you have in your module's OnModuleLoad event the following not commented out:
    SetModuleSwitch
            (MODULE_SWITCH_ENABLE_TAGBASED_SCRIPTS, TRUE);
    
  • WilliamDracoWilliamDraco Member Posts: 175
    Issue is likely that OBJECT_SELF does not refer to what yu think it does at various steps. Obviously without seeing all of the other scripts being called it's hard to know exactly, but in every script shown OBJECT_SELF is the module. I'd wager the add/removal scripts want OBJECT_SELF to be the sword.
    While I'd personally avoid all of those other ExecuteScript calls and just do it directly, probably the smallest-change to fix for your code is to change the `x2_mod_def_act` section to be as follows
    {
        if (GetTag(GetItemActivated()) == "magicfiresword")
        ExecuteScript("magicfiresword", GetItemActivated());
    {
    

    Now once you get to the magicfiresword script, the sword itself will be OBJECT_SELF, and hopefully the other executes will work accordingly.
  • AtrophiedericAtrophiederic Member, Mobile Tester Posts: 147
    Thank you all so very much for your responses. I have absorbed suggestions in order to make my scripting better (and will credit accordingly), but I am abandoning my attempt to make a uniquepowerselfonly magical weapon. The commands involved are just beyond my grasp. I have another direction I'm going in, and it seems to be working out well, so there's that.

    Once again, thank you all for your help, ideas, etc. Just one of many reasons why I still play NwN and why I love this community so much!

    Be safe and be well!
Sign In or Register to comment.