DavaScript Posted October 3, 2020 Posted October 3, 2020 (edited) 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 October 3, 2020 by DavidSkx
qwertyasdfgh Posted October 3, 2020 Posted October 3, 2020 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.
DavaScript Posted October 3, 2020 Author Posted October 3, 2020 On 10/3/2020 at 8:55 PM, qwertyasdfgh said: 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.
qwertyasdfgh Posted October 3, 2020 Posted October 3, 2020 (edited) 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 Edited October 3, 2020 by qwertyasdfgh
DavaScript Posted October 3, 2020 Author Posted October 3, 2020 On 10/3/2020 at 9:29 PM, qwertyasdfgh said: 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?
DrakeTheDragon Posted October 4, 2020 Posted October 4, 2020 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 EndThen 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.)
Recommended Posts