Howdy, Stranger!

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

Categories

New Premium Module: Tyrants of the Moonsea! Read More
Attention, new and old users! Please read the new rules of conduct for the forums, and we hope you enjoy your stay!

How to count all resrefs in a numbered list

So say I have a list of random treasure using resrefs with:

Poor_Item001
Poor_Item002
Up until Poor_Item250

And I keep adding to that list day by day. The problem is that I also a script of random treasure from 001 to the last of the poor item I create, which means I need to be constantly updating the number in the random treasure script that gives you a random item between 1 to the last number; is there a way to count all the resrefs with "Poor_Item" so I won't have to change that last number manually every time?

I hope my problem is understood

-Val

Comments

  • ProlericProleric Member Posts: 557
    Given that you need to create the resrefs manually, ensuring there are no gaps, editing the number is surely no big deal? Best defined as a const int at the top of the script, so it's easy to find.

    If you really needed to compute it, you could CreateItemInObject in an inaccessible container, looping from 001 onwards until it returns OBJECT_INVALID.

  • FreshLemonBunFreshLemonBun Member Posts: 749
    Precomputing values where you can is always the best option.

    Even if you did loop through all entries to get the total you would just save the result as a local variable so you don't have to keep doing it every time loot is spawned.

  • ValeriyaValeriya Member Posts: 48
    edited January 2019
    I think I'll be doing it manually then, sounds easier and it's not that big of a problem come to think of it. Thanks

  • SherincallSherincall Member Posts: 375
    I think it's better to compute it all once as the module loads, rather than having an extra manual step. Proleric's idea is good, but you don't need to loop through all of them, you can only try a couple of ones to quickly find where the limit is. Here's a sample code:
    // utlity to convert to string with leading zeros if necessary

    (untested, and also I'm not sure how it will fare if there are no items at all)

  • antirelicantirelic Member Posts: 20
    edited February 2019
    Can't you just use the bioware tokenizer? Just keep appending new "poor" objects to a string, with a | separating the entries. The tokenizer functions will handle counting the string, and allowing you to pull resrefs by token number.

    To go a step further, Trigger Based Spawn System (TBSP) uses this approach quite nicely.

Sign In or Register to comment.