Jump to content

How to decrement the function 'GetNumRefs'?


DavaScript

Recommended Posts

How do you decrement 'GetNumRefs 36' without resorting to using a script? GetNumRefs 36, counts how many creatures are in the current cell, but it does not decrement when I kill a creature in that cell. To my understanding, it counts dead bodies as well? Is there any other way to decrement it, for instance, by using conditional functions? Been pulling my hair on this for a while. Thanks in advance.

Edited by DavidSkx
Link to comment
Share on other sites

What do you mean by "without resorting to using a script"? It's a script function, of course you're going to use a script...

 

To answer your question, yes, GetNumRefs doesn't care if creature is alive or dead, as both are still references. To count only alive creatures you'll need to create a script loop to walk through creature references one by one, checking with GetDead if they're alive or not. If you're feeling fancy, this can be made into a user-defined function, or just added to a script directly.

Link to comment
Share on other sites

What do you mean by "without resorting to using a script"? It's a script function, of course you're going to use a script...

 

To answer your question, yes, GetNumRefs doesn't care if creature is alive or dead, as both are still references. To count only alive creatures you'll need to create a script loop to walk through creature references one by one, checking with GetDead if they're alive or not. If you're feeling fancy, this can be made into a user-defined function, or just added to a script directly.

 

I'm using HUD Status Bars to check how many creatures are in the current cell. How would I use GetNumRefs 36 to only count creatures that are alive? I've tried using GetDead along with it, but it doesn't seem to want to work.

Link to comment
Share on other sites

 

Kinda like this:

set rItem to Apple
set rItem to GetFirstRef 36 1
while (rItem)
    if rItem.GetDead == 0
        ;Actor is alive, do your stuff
    endif
    set rItem to Apple
    set rItem to GetNextRef
loop

 

Aside from using a script, how would I implement this into hud_val for HUD Status Bars?

Link to comment
Share on other sites

HUD Status Bars can use Quest variables as source for value display.
You would need to add a local counter set to 0 at the start of the loop, incrementing for each non-dead creature found, and update the quest variable's value to this one's after the loop.

So, if the above is in a quest script already, just introduce 2 new number variables:

int iNumCreatures
int iCount
 
Begin GameMode
 
set iCount to 0
set rItem to Apple
set rItem to GetFirstRef 36 1
while (rItem)
    if rItem.GetDead == 0
        ;Actor is alive, do your stuff
        set iCount to iCount + 1
    endif
    set rItem to Apple
    set rItem to GetNextRef
loop
set iNumCreatures to iCount

End

Then you can tell HUD Status Bars to use "<your quest name>.iNumCreatures" as the display value for the element.

(I'm doing it with 2 variables instead of 1, so you won't see the number repeatedly starting by 0 and going up, which you would do, if you used "iCount" directly for display instead.)

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...