Jump to content

how to check if an NPC is loaded?


irswat

Recommended Posts

I am working on a mod where I add snipers throughout the wasteland. There will be hundreds of them. OnLoad I add them to a formlist, and OnDeath I remove them from the formlist. I would like to be able to remove the NPC from the FormList if the player leaves the area and the NPC is unloaded from memory. Is there a function similar to OnDeath or GetDead like OnUnload or a way to check if an object is loaded in the games memory?

Link to comment
Share on other sites


scn SniperScriptAddToFormList

ref rSniper

Begin OnLoad

set rSniper to SMSniper01.GetSelf

if (rSniper.IsInList SMSnipers == 0)
AddFormToFormList SMSnipers rSniper
endif

if IsPlayerMovingIntoNewSpace
if (rSniper.IsInList SMSnipers)
ListRemoveForm rSniper SMSnipers
endif
endif
end

Begin OnReset

set rSniper to SMSniper01.GetSelf

if (rSniper.IsInList SMSnipers)
ListRemoveForm rSniper SMSnipers
endif

end

Begin OnDeath

set rSniper to SMSniper01.GetSelf

if (rSniper.GetDead)
if (rSniper.IsInList SMSnipers)
ListRemoveForm rSniper SMSnipers
endif
endif

 

Link to comment
Share on other sites

I would like to be able to remove the NPC from the FormList if the player leaves the area and the NPC is unloaded from memory. Is there a function similar to OnDeath or GetDead like OnUnload or a way to check if an object is loaded in the games memory?

It's not really a binary (either in memory or not), rather I suspect what your looking for is if an actor is in "high memory" (playing animations, AI packages etc). There is a function getActorsInHigh that will check the number of actors in high mem for you.

 

If there was a way to determine/test each ref to see if it was in high mem, you could put a block in another quest script that tests each and makes a new form list which is dynamically updated.

Edited by devinpatterson
Link to comment
Share on other sites

I'm not sure I understand. I want to keep a form list of snipers that are currently "active". I will be using this form list and applying that SniperAlert script that I was working on. I want to be able to go through the form list of active snipers (snipers that are loaded, no dead, and within a few cells of the player) and one by one get the distance of the sniper from the player. With that said is the getActorsInHigh function still the one I am looking for, or do you think the script I whipped up will suffice?

Link to comment
Share on other sites

I'm not sure I understand. I want to keep a form list of snipers that are currently "active". I will be using this form list and applying that SniperAlert script that I was working on. I want to be able to go through the form list of active snipers (snipers that are loaded, no dead, and within a few cells of the player) and one by one get the distance of the sniper from the player. With that said is the getActorsInHigh function still the one I am looking for, or do you think the script I whipped up will suffice?

No unfortunately it (getActorsInHigh) won't be useful for that scenario I was referring more to the concept of high memory being "active" snipers. A couple of points though;

Reset will happen approximately every 3 days of game time, so it's not a very effective "garbage collector"

 

isPlayerMovingIntoNewSpace with a quest script is problematic. Say you leave it at default (once per 5 seconds) it would be possible for the script to miss the transition (and of course it gets worse the longer the delay). But if you use getInWorldSpace of the Mojave as a check, it will filter out all dlc's, interiors and mini-worlds, without any baggage.

 

I don't see anything in teh code above to add snipers to the formlist if they are close (close being a relative term in this case, with long distance sniping). You had mentioned you wanted to include snipers that are withing a few cells. It would be duplicated effort to use getDistance to determine if they are near since the whole point of the script is for you to generate a form list to use as an argument for that function (getDistance)....that's one of your primary objectives right? You could use getInSameCell....I believe (unlike getInCell) it functions on an exterior cell fine. But I'm guessing from your other posts that one cell may be too small?

Link to comment
Share on other sites

 

I'm not sure I understand. I want to keep a form list of snipers that are currently "active". I will be using this form list and applying that SniperAlert script that I was working on. I want to be able to go through the form list of active snipers (snipers that are loaded, no dead, and within a few cells of the player) and one by one get the distance of the sniper from the player. With that said is the getActorsInHigh function still the one I am looking for, or do you think the script I whipped up will suffice?

No unfortunately it (getActorsInHigh) won't be useful for that scenario I was referring more to the concept of high memory being "active" snipers. A couple of points though;

Reset will happen approximately every 3 days of game time, so it's not a very effective "garbage collector"

 

isPlayerMovingIntoNewSpace with a quest script is problematic. Say you leave it at default (once per 5 seconds) it would be possible for the script to miss the transition (and of course it gets worse the longer the delay). But if you use getInWorldSpace of the Mojave as a check, it will filter out all dlc's, interiors and mini-worlds, without any baggage.

 

I don't see anything in teh code above to add snipers to the formlist if they are close (close being a relative term in this case, with long distance sniping). You had mentioned you wanted to include snipers that are withing a few cells. It would be duplicated effort to use getDistance to determine if they are near since the whole point of the script is for you to generate a form list to use as an argument for that function (getDistance)....that's one of your primary objectives right? You could use getInSameCell....I believe (unlike getInCell) it functions on an exterior cell fine. But I'm guessing from your other posts that one cell may be too small?

 

 

I was going to use GetInSameCell but as you correctly guessed it isn't appropriate for what I need it for.

 

The objective of the FormList is to create something like a For...While loop that will go through the list of active snipers (those that are within 3 cells of the player [OnLoad & !GetDead]) and apply the SniperAlert script we had talked about previously. This way I can target all snipers in the area and get their distance from the player.

 

I'm really not even sure what I'm doing. Before I had the SniperAlert script attached to the Base object (the tower sniper NPC) but it didn't seem to be firing. I couldn't even get the script to fire using a primative, but I tried (im not sure what to attach the IsPlayerInTrigger script to). My new idea was to fill a FormList of active snipers, and create a quest script that runs constantly to check if any of the active snipers are within (20,000 units) range. This range will be modified once I determine what is the furthest a player can see the snipers from. I want the snipers to react from the same distance.

 

OnLoad AddFormToFormList should fulfill the requirement of snipers that are within 3 cells since that is how far away objects are loaded into memory (from what I've read), removing those that are dead should fulfill the second requirement.

 

 

OnReset Run once when scripted object's cell is reset

 

I thought it would be good to use this in conjunction with RemoveFormFromList, so when the cells reset I won't have duplicates in my FormList. My thought would be the cell would be reset, all NPC's would be removed from the FormList, and as they reload they will be readded to the form list.

I'll probably get rid of IsPlayerMovingIntoNewWorldSpace.

 

Link to comment
Share on other sites

I added some debug messages to see if these functions were working as they were supposed to. I didn't get one message saying snipers were being added or removed from the form list. I'm about to give up on modding this game. Lol. Please keep in mind this script is attached to the NPC Base Object.

scn SniperScriptAddToFormList

ref rSniper

Begin OnLoad

	set rSniper to SMSniper01.GetSelf

	if (rSniper.IsInList SMSnipers == 0)
		AddFormToFormList SMSnipers rSniper
		ShowMessage SniperAddedtoFormList
	endif

	if IsPlayerMovingIntoNewSpace
		if (rSniper.IsInList SMSnipers)
			ListRemoveForm rSniper SMSnipers
			ShowMessage SniperRemovedFromFormList
		endif
	endif
end

Begin OnReset

	set rSniper to SMSniper01.GetSelf

	if (rSniper.IsInList SMSnipers)
		ListRemoveForm rSniper SMSnipers
		ShowMessage SniperRemovedFromFormList
	endif

end

Begin OnDeath

	set rSniper to SMSniper01.GetSelf

	if (rSniper.GetDead)
		if (rSniper.IsInList SMSnipers)
			ListRemoveForm rSniper SMSnipers
			ShowMessage SniperRemovedFromFormList
		endif
	endif

end

Link to comment
Share on other sites

  • Recently Browsing   0 members

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