Get references of close actors

Post » Tue May 17, 2011 12:44 pm

Hi guys,

I had moded Obli during many years, but I'm just starting with the Geck and FOSE (after a long moding break).
And I'm quite disappointed to see that some major needed scripting functions are still missing in the GECK...

The main thing I'm talking about is to be able to get the ref of actors near the player (extremly usefull for a lots of creative things).

With the Tescs I had found a simple way to do that : I used an invisible custom area spell (ignore LOS activated) that was casted, for example, every 5 seconds by an object in the player inventory. So in the spell's ScriptEffect I was able to save every actors ref (near the player) I wanted in quest ref variable for example. Possibilities was infinite with this simple system (improve the sneaking system in certain circumstances, add AI Packages/dialogs/NPC reactions to the NPCs near the player in function of the player actions/NPCs stats. Etc, etc, etc).




I'm searching a way to do the same thing in Fallout 3.
I have 2 ideas to be able to do that :

1) the same thing that I described for Obli. But spell system seems to be really different (so I'm a little lost with it after only one day on the Geck)...
Two major problems :
-> the http://geck.gamesas.com/index.php/Cast function seems to be broken
-> the http://geck.gamesas.com/index.php/CastImmediateOnSelf function works only for spells that are target self (no area effect)......

So is there anyway to cast an invisible area spell, to apply a ScriptEffect on actors near the player ?




2) Use FOSE functions http://cs.elderscrolls.com/constwiki/index.php/GetNextRef and http://cs.elderscrolls.com/constwiki/index.php/GetFirstRef to get back refs of nearest actors (or to apply them spell's ScriptEffect with CastImmediateOnSelf).
It seems to be possible :
-> I test for example 30 actors refs in the cell, and keep only the 5 nearest refs of the player.
*But "the order of references as returned by GetFirst/NextRef is essentially undefined"... So if there are 40 actors in the cell, I'm not sure at all to get the 5 nearest if I've only tested 30 of them...
*Another problem : If I'm just near the limit of an exterior cell -> I won't test at all actors in the adjacent cell even if they are close to me. And if I test adjacents cells, I will have to do 8x more tests in one single script frame...



That's why I would like to find a lighter system than the second one.



I'm asking to your creativity guys :D, any better idea to get refs of actors close to player ?
Since yesterday I've read a lot of function descriptions of Geck 1.1 and FOSE but I didn't find anything relevant (but it's very possible that I didnt see something).

Any advice, idea will be welcome !


Thanks.
User avatar
Chris BEvan
 
Posts: 3359
Joined: Mon Jul 02, 2007 4:40 pm

Post » Tue May 17, 2011 1:35 am

When you perform your "ref-walk", use an additional check using GetDistance to determine how close the found actor is to the player. Store the closest 5 in a form list. Then use the form list to perform whatever actions you want on the actors. When ref-walking in exterior cells, increase the "Depth" value to include more cells in your "ref-walk". 0 = the current cell, 1 will include all cells adjacent to the current cell and so on. Here is an example of a ref-walk I use that stores found refs in a form list. You can modify this to use your GetDistance requirement.

Spoiler

                Set Depth to 3 * (player.IsInInterior ==0)		Set rCurRef to Apple		set rCurRef to GetFirstRef 200 Depth 0			;All actors		Label 10		if (rCurRef)			If rCurRef.GetDisabled == 0 && rCurRef.GetDead == 0				If Player.GetLos rCurRef || Player.GetDistance rCurRef < 1000					Set Found to -1					Set Count to (ListGetCount UCFXListNew -2)					Label 15					If Count > -1						Set rOldRef to ListGetNthForm UCFXListNew Count						If rCurRef == rOldRef							Set Found to Count						EndIf						Set Count to Count - 1						Goto 15					EndIf ;Count					If Found == -1						rCurRef.ListAddReference UCFXListNew 0						If rCurRef.GetIsCreatureType 6 == 1							rCurRef.PMS UCNightVisionFXS2						Else							rCurRef.PMS UCNightVisionFXS1						EndIf ;Creature Type;						printc "New Ref added %n  %i" rCurRef rCurRef								Endif ;Found				EndIf ;LOS + Distance			Endif ;Disabled			Set rCurRef to apple			set rCurRef to GetNextRef			Goto 10		EndIf ;CurRef

User avatar
gemma king
 
Posts: 3523
Joined: Fri Feb 09, 2007 12:11 pm

Post » Tue May 17, 2011 12:02 am

Hi pkleiss,

First of all ty for your answer.

I've tested more deeply these FOSE functions, and yea they are definitly powerful.
I will use them ;)


But I still saw a strange bug.
I've done a small simple script to test these functions, that simply try to count the number of NPC in the current cell when player press the "attack" control.

-> First I put this script on an armor, just to test. The script works perfectly on the first loading of the game. But as soon as I re-load any saved game (even saves where this script was or wasn't already loaded) : the script just crash (not the game, but the script simply dont run anymore).

-> Then I test exactly the same script but this time as a quest script (with a very low script quest delay (0.1) to be able to correctly track if player is pressing his "attack" control)... This time no bug at all. Script is running very well, even after a saved game reloading...


So I will probably use a quest script, but any idea why this script is crashing when attached to an object?


Here is the script, with some explanations even if it's very simple :
short NPCcount							;Variable to count the NPCs number in the current cellfloat timer							;Timer to be sure to avoid multiple counting tests at the same timeref NPCref							;Reference to verify if the test is finished or not ( If NPCref == 0 -> the test is finished )Begin GameModeIf IsControlPressed 4 == 1 && timer == 0			;* * * Test begin when Player press the "Attack" control (LeftMouse by default). Timer must be set to 0 to avoid multiple tests at the same time.	set timer to 1						;Timer is set to 1 to begin the test ( test condition :   If timer > 0 )	set NPCcount to 0					;Variable NPCcount is reseted for the next testEndifIf timer > 0							;* * * Test will start	set timer to timer + getsecondspassed			;Timer incrementation		If timer >= 3					;* * *Real test starts 2 seconds after Player press the "Attack" control																		set NPCref to GetFirstRef 42 0 0	;Get the ref of the 1st NPC, only in the current cell, ignoring inactive references			label 1					;Loop Start																If NPCref != 0				;* * * NPCref exists				set NPCcount to NPCcount + 1	;So NPCcount is increased				set NPCref to GetNextRef	;Get the ref of the next NPC				Goto 1				;Loop continu as long as NPCref exists			Else					;* * * No More NPC in the Cell (NPCref == 0) -> Loop Exit = Test is finished				set timer to 0			;So timer is reseted, to be able to restart the test when Player press the "Attack" control ( IsControlPressed 4 == 1 )				showmessage AAtestMess0 NPCcount;Display The number of NPCs counted in the Curent cell during this test			Endif		EndifEndifEnd

User avatar
Joe Alvarado
 
Posts: 3467
Joined: Sat Nov 24, 2007 11:13 pm

Post » Tue May 17, 2011 3:24 am

I'm not sure if this is your problem, but Getnexref has bugs that are worked around by setting the ref to something before calling GetNextRef, like this:

set NPCref to Pencil01set NPCref to GetNextRef

User avatar
Dustin Brown
 
Posts: 3307
Joined: Sun Sep 30, 2007 6:55 am

Post » Tue May 17, 2011 3:20 pm

You could always just use an Explosion attach an Object Effect to it and it will function exactly the same as an Oblivion Touch AOE, with the bonus that you can call it with Player.PlaceAtMe Explosion and not have to deal with an Activator casting spells so there is less to track -> also Explosions are automaticly garbage cleaned so you do not have to worry about save game bloat.
User avatar
Robert Devlin
 
Posts: 3521
Joined: Mon Jul 23, 2007 2:19 pm

Post » Tue May 17, 2011 2:28 pm

You could always just use an Explosion attach an Object Effect to it and it will function exactly the same as an Oblivion Touch AOE, with the bonus that you can call it with Player.PlaceAtMe Explosion and not have to deal with an Activator casting spells so there is less to track -> also Explosions are automaticly garbage cleaned so you do not have to worry about save game bloat.



Hi !

Omg yes! So explosions are working like area spell effect in Oblivion?! That's perfect!
It will be really smoother do deal with this (and no need FOSE). Thank you very very much SaidenStorm.
I will try to learn how explosions are working in F3.

I will post here later if I have a question about that.

Thanks guys! :)

Edit : ok just seen that it's possible to attach an object effect to an explosion. Will try that, thanks again ^^
Just a small question : what is the unit measure of the radius in the explosion tab? Units like oblivion -> ~70 units = 1 meters ?
User avatar
Leilene Nessel
 
Posts: 3428
Joined: Sun Apr 15, 2007 2:11 am

Post » Tue May 17, 2011 4:27 am

Hi !

Omg yes! So explosions are working like area spell effect in Oblivion?! That's perfect!
It will be really smoother do deal with this (and no need FOSE). Thank you very very much SaidenStorm.
I will try to learn how explosions are working in F3.

I will post here later if I have a question about that.

Thanks guys! :)

Edit : ok just seen that it's possible to attach an object effect to an explosion. Will try that, thanks again ^^
Just a small question : what is the unit measure of the radius in the explosion tab? Units like oblivion -> ~70 units = 1 meters ?


Unit Measures are identical with both games.

Force -> PushBack this is force applied to Havoked Objects, Including Knocked Down Actors.
Radius -> AOE range.
IS Radius -> Image Space Modifier range to have this IS applied to the player.
World Orientation -> basically always Upright this only applies to the Effect.nif if one is set.
Radiation -> this is whats left over of the Oblivion Fog Type Magic Effect, works the same way.
Light -> Does not work.
Enchantment -> Object Effect (Magic Effect).
IS Mod -> Image Space Modifier
Impact Data Set -> Effects and Decals left over from the explosion on surfaces.
Sound Level -> set this to Silent for a script that only needs to collect references otherwise it will give your position away to NPC's.
Placed Impact Object -> this allows you to call another secondary object to the location of the Explosion -> excedingly useful for many effects, http://www.youtube.com/watch?v=YF6bnoZemeY and http://www.youtube.com/watch?v=cOILLRjhkQU.
User avatar
Manuel rivera
 
Posts: 3395
Joined: Mon Sep 10, 2007 4:12 pm

Post » Tue May 17, 2011 1:57 pm

Yop,

So using explosions to deal with references close to player is working perfectly. :woot:
Just a little thing if it could help someone :

To correctly apply a script effect by an invisible explosion, it must have an invisible nif attached to it (without nif it sometimes works in interior cells, but not in exterior, or inversely).
The explosion models "FakeForceBall" are perfect for that :
-just change the geck ID
-change the Radius in function of what you need
-Select your custom enchantment to apply to refs
-select "ignore LOS check/Always use world orientation" if you need
-and finally, for all other parameters : 0/None/Silent/Never

See you :wavey:

PS : excellent vids Saiden, keep up the amazing work :thumbsup:
User avatar
Ron
 
Posts: 3408
Joined: Tue Jan 16, 2007 4:34 am


Return to Fallout 3