Skip to content

On Hit: Unique Power and Removing Random Loot Drops

nwfan87nwfan87 Member Posts: 99
edited August 2023 in Builders - Scripting
It's been a while since I posted!

Two script related questions:

On Hit: Unique Power
How to script it (As an example: a sword that turns the target when hit, into a chicken), where the script needs to go (on item Activate or tag based system). Links to good tutorials welcome.

I've tried it before using the OnItemActivate scripting system, since I've never been able to get the tag based system to work properly, so I'm only using the old system of having one script with tag based checks, therefore some solution that would work with that would be very helpful!

Removing Random Loot Drops
Any good advice on how to remove random loot drops from creatures? What I mean by this, is a script or some measure that will ensure that no loot is dropped when the creatures dies at all.

Thanks everyone and hope you had a good summer :smiley:

Comments

  • QuilistanQuilistan Member Posts: 186
    for On Hit: Unique power

    I make sure the script name matches the Tag and Blueprint name of the item.

    so Script name would be sword1 Tag of the item would be sword1 and blueprint of the item would be sword1. thought I am not 100% sure if it goes off tag or blueprint, I just make them all the same regardless to make it work. Easily testable though.

  • ForSeriousForSerious Member Posts: 466
    nw_c2_default9 line 297. Delete or comment it out.
    Not sure why, but zs_nw_c9_default is another variation of the same script I seem to have used.
  • TarotRedhandTarotRedhand Member Posts: 1,481
    Re. Removing Random Loot Drops - Just a thought but on the creatures properties, advanced tab there is a check box that says something like "Leaves Lootable Corpse". If you make sure that is not checked, the body should not be accessible and will fade away in 5 seconds by default (this time is editable). In this case no scripting required, just open the creatures properties. If all else fails, there is also a drop-down box marked treasure type that can be set to bones (which are hopefully valueless in your module.

    TR

  • ForSeriousForSerious Member Posts: 466
    Sorry @TarotRedhand, That's not how those Advanced options work at all.
    The nw_c2_default9 script is the OnSpawn script. And the 'Leaves Lootable Corpse' just changes it so that you take the loot out of the dead creature body instead of a remains container.
  • nwfan87nwfan87 Member Posts: 99
    edited August 2023
    @Quilistan

    I'm not sure either, I've tried tag but that does not seem to work, not tried resref yet. I'm quite comfortable using the old tag based checks though, unless there are complex requirements.

    Edit: Also found that the On Hit : Cast Spell Unique Power is dealt with via X2_S3_OnHitCast. It can just be edited or I found this thread here for more complex items

    @ForSerious

    You mean:
    CTG_GenerateNPCTreasure(TREASURE_TYPE_MONSTER, OBJECT_SELF);
    
    ?

    Did some desperate reading yesterday and thought this might be the cause, so I just
    /* */
    
    that whole line. Also can create a duplicate verison for specific creatures. Never heard of zs_nw_c9_default, and can't find it in the default script resources, but shouldn't be a problem I suppose.

    I think you are right about the advanced options. The random loot appears to be more fundamental and is dealt with by scripting.

    The end result I'm hoping is that there is no random loot at all and therefore, no remains container.

    @TarotRedhand

    My thoughts were that Leaves Lootable Corpse just acts in a similar way as
    SetIsDestroyable(FALSE, FALSE, FALSE);
    

    With the exception that the coded version is more powerful, as the corpse will never decay, unless you script something else.

    In other words, the 'leaves lootable corpse' checkbox leaves the creature model as a loot object for the set amount of time shown in 'corpse decay time', after which, the corpse fades away, replaced with whatever treasure model you have selected.

    None of those options though deal with whether random loot is dropped or not.
  • ForSeriousForSerious Member Posts: 466
    That is the function.
    There is another script that's put in there on some creatures, but it calls that script.
  • NeverwinterWightsNeverwinterWights Member Posts: 339
    edited September 2023
    @nwfan87 Not sure if you got the OnHit worked out or not yet. Sounds like you are having issues getting the tag based scripting to work. The first thing you should check is your modules OnModuleLoad event script. Whether its the default script or a custom one, there should be a set of module switches in there that you can turn on and off. For tag based scripting to work you should look for the following and make sure it's set to TRUE:
    // * Item Event Scripts: The game's default event scripts allow routing of all item related events
        // * into a single file, based on the tag of that item. If an item's tag is "test", it will fire a
        // * script called "test" when an item based event (equip, unequip, acquire, unacquire, activate,...)
        // * is triggered. Check "x2_it_example.nss" for an example.
        // * This feature is disabled by default.
        SetModuleSwitch (MODULE_SWITCH_ENABLE_TAGBASED_SCRIPTS, TRUE);
    

    Immediately after that module switch there should be a chunk that looks like this:
    //if (GetModuleSwitchValue (MODULE_SWITCH_ENABLE_TAGBASED_SCRIPTS) == TRUE)
        //{
            // * If Tagbased scripts are enabled, and you are running a Local Vault Server
            // * you should use the line below to add a layer of security to your server, preventing
            // * people to execute script you don't want them to. If you use the feature below,
            // * all called item scrips will be the prefix + the Tag of the item you want to execute, up to a
            // * maximum of 16 chars, instead of the pure tag of the object.
            // * i.e. without the line below a user activating an item with the tag "test",
            // * will result in the execution of a script called "test". If you uncomment the line below
            // * the script called will be "1_test.nss"
            // SetUserDefinedItemEventPrefix("1_");
    
    If that's all commented out, you shouldn't have to worry about any script prefixes and you can just get to testing a tag based script for an item.

    One easy way to do it: Just make a dagger and give it a unique tag, "test_tag_dagger" or whatever. Give it the item properties "On Hit Cast Spell: Unique Power (On Hit)" and "Cast Spell: Unique Power Self Only (set to unlimited uses per day for testing)".

    Now make the following script and give it the exact name as the tag you made for the dagger above (ie "test_tag_dagger"):
    #include "x2_inc_switches"
    
    void main()
    {
        object oPC;
        int nEvent = GetUserDefinedItemEventNumber();
    
        if (nEvent == X2_ITEM_EVENT_ACTIVATE)// do active stuff
        {
            oPC = GetItemActivator();
            object oTarget = GetItemActivatedTarget();
    
            if (GetIsObjectValid(oTarget))
            {
                SendMessageToPC(oPC, "OnActivate Fired Properly!");
            }
        }
    
        if (nEvent == X2_ITEM_EVENT_ONHITCAST)// do on hit stuff
        {
            oPC = OBJECT_SELF;
            SendMessageToPC(oPC, "OnHit Fired Properly!");
        }
    }
    

    If all is working as it should, you can pick up the dagger and use the unique power to see if you get the "OnActivate Fired Properly" message. Then go around hitting stuff (stuff has to be able to take damage) with the dagger and on successful hits you should be seeing the "OnHit Fired Properly" message. Hope it helps. Good luck.
    Post edited by NeverwinterWights on
  • nwfan87nwfan87 Member Posts: 99
    @NeverwinterWights

    That is very helpful thankyou! I'll have to try this at some future date. :smile:
  • MelkiorMelkior Member Posts: 204
    On the item drops, I believe you can use a module variable to override the default loot drop system and disable it. However, some monsters such as skeletons already have droppable items in their inventories and these items are not affected by the default loot drop system, so to prevent them from dropping their items you have to create a copy, remove the droppable item from the copy's inventory and then use only the copy instead of the original.
    An alternative to creating copies would be to edit the default onspawn script to either delete default items or make them undroppable before adding any droppable loot to the monster's inventory. Personally, I prefer to create loot drop items ondeath instead of onspawn, as it prevents the enemy from using a one-shot item like a potion which you intended to give to the player as a reward.
  • Drewbert_ahoyDrewbert_ahoy Member Posts: 97
    Module Switch name: MODULE_SWITCH_NO_RANDOM_MONSTER_LOOT
    Variable name: X2_L_NOTREASURE
    Description: Setting this variable to TRUE on the module will disable the call to the random loot generation in most creatures' OnSpawn script.
Sign In or Register to comment.