Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Dark Dreams of Furiae - a new module for NWN:EE! Buy now
Attention, new and old users! Please read the new rules of conduct for the forums, and we hope you enjoy your stay!

Why don't items feature a "scripts" tab?

I noticed this while digging HotU. Having a script tab would allow us to "bake" unique item powers into the item, rather than having to rely on module properties.

Comments

  • SherincallSherincall Member Posts: 387
    The engine considers item events to be the events of the module itself. There's a few technical reasons for this that aren't very relevant. The important thing is that you can still have per-item scripts. The most common approach is what HotU introduced called Tag-based scripting. It's detailed here:
    https://nwnlexicon.com/index.php/Grimlar_-_Introduction_To_Tag_Based_Scripting

    Basically, the idea is to have one script per item (or one per-item, per-event), and then from the module's OnItemUsed and similar events fire off the correct script based on the tag of the used item. This achieves the exact same result as you'd have with per-item script tab, while keeping the resource usage reasonable.

    NWN_Tömlsquattingmonk
  • Dark_AnsemDark_Ansem Member Posts: 972

    The engine considers item events to be the events of the module itself. There's a few technical reasons for this that aren't very relevant. The important thing is that you can still have per-item scripts. The most common approach is what HotU introduced called Tag-based scripting. It's detailed here:
    https://nwnlexicon.com/index.php/Grimlar_-_Introduction_To_Tag_Based_Scripting

    Basically, the idea is to have one script per item (or one per-item, per-event), and then from the module's OnItemUsed and similar events fire off the correct script based on the tag of the used item. This achieves the exact same result as you'd have with per-item script tab, while keeping the resource usage reasonable.

    I didn't know about that. I guess that having a dedicated "script" tab would allow for easy porting of the item between modules...

  • squattingmonksquattingmonk Member Posts: 59
    Not really. Even if the script was specified on the item, the other module would still have to have the script for the item to function.

  • Dark_AnsemDark_Ansem Member Posts: 972

    Not really. Even if the script was specified on the item, the other module would still have to have the script for the item to function.

    Wouldn't ERF exporting do that?

  • FinalStandFinalStand Member Posts: 87
    Tag based scripting works well for items, I like it more than separate events (for items at least). All your code for that item is in one file. Otherwise you would have like 8 files per item. Have 20 custom items and that is 160 scripts!

  • Dark_AnsemDark_Ansem Member Posts: 972

    Tag based scripting works well for items, I like it more than separate events (for items at least). All your code for that item is in one file. Otherwise you would have like 8 files per item. Have 20 custom items and that is 160 scripts!

    I'm sorry, I don't follow the math. Please explain?

  • squattingmonksquattingmonk Member Posts: 59
    The math's slightly off, but the statement is still solid. Tagbased scripts make use of the GetUserDefinedItemEventNumber() function to determine if they're being called from 7 different events:
    1. OnActivateItem
    2. OnAcquireItem
    3. OnUnAcquireItem
    4. OnPlayerEquipItem
    5. OnPlayerUnEquipItem
    6. OnHitCast
    7. OnSpellCastAt
    By having one script that handles all the events, you avoid having to have 7 different scripts per item in the module.

    Dark_Ansem
Sign In or Register to comment.