Deleted58209541User Posted December 19, 2018 Share Posted December 19, 2018 Hello everyone. In my Oblivion dungeon I'm trying to make various objects that activate when a creature with a light source comes within a certain distance of them. I want this effect to happen even when it is a non-player character that approaches the object. Essentially I want the following code for traps/doors/spooky haunted things: begin GameMode ref nearestActor = GetNearestActor() if GetDistance(nearestActor) && nearestActor.GetActorLightAmount() > 30 ;Do spooky stuff endif end However, I can find no means to get a reference to the nearest actor. GetNearestActor() does not exist. Does anyone here know of a way to get a reference to the nearest actor? I'm willing to use Oblivion Script Extender functions. Link to comment Share on other sites More sharing options...
QQuix Posted December 19, 2018 Share Posted December 19, 2018 Use GetFirstRef and GetNextRef to cycle thru all references in the same cell as the PC GetNextRef page has a sample script Link to comment Share on other sites More sharing options...
Rizalgar Posted December 19, 2018 Share Posted December 19, 2018 Hmm. Interesting. This is just a guess, since I've never tried it before, but maybe something like this? ref target ref target2 etc... begin gamemode set target to GetFirstRef 69 1 set target2 to GetNextRef etc... if GetDistance(target) && target.GetActorLightAmount() > 30 ; spooky stuff endif end That is theory though, so no guarantees. Although I have been trying to figure out if I can a spell to jump from one actor to another, maybe something like this would work? Time to find out... Link to comment Share on other sites More sharing options...
QQuix Posted December 19, 2018 Share Posted December 19, 2018 Not quite . . . you have to make a loop to check the distance of each and every Actor in the cell something along the line . . . set target to GetFirstRef 69 1 while target if GetDistance(target) < 200 && target.GetActorLightAmount() > 30 ; spooky stuff to this particular actor which is less than 200 units from the object set target to GetNextRef loop Link to comment Share on other sites More sharing options...
Rizalgar Posted December 19, 2018 Share Posted December 19, 2018 AH, indeed. Like I said, never tried it before. Interesting to know now though! Link to comment Share on other sites More sharing options...
Moktah Posted December 20, 2018 Share Posted December 20, 2018 a bit different approachhow bout using activators such as pressure plates and such object window worldobjects activator dungeons caves triggers when pressure plate is stepped on,put your 'spooky stuff' to launch in the Begin OnActivate scriptfor the pressure platesince you want it to react to an npc or playerjust be sure it saysBegin OnActivateand NOTBegin OnActivate Player <<<< this will cause the pressure plate to only react to the player and ignore NPCs Link to comment Share on other sites More sharing options...
Deleted58209541User Posted December 20, 2018 Author Share Posted December 20, 2018 (edited) Not quite . . . you have to make a loop to check the distance of each and every Actor in the cell something along the line . . . set target to GetFirstRef 69 1 while target if GetDistance(target) < 200 && target.GetActorLightAmount() > 30 ; spooky stuff to this particular actor which is less than 200 units from the object set target to GetNextRef loopThank you for the advice! I'm sorry I didn't respond yesterday. I went to a friend's house shortly after posting. Your strategy works perfectly, with only one oddity. "GetFirstRef 69 1" and "GetNextRef" do not appear to find the player as an actor. I had to add a player-specific condition. For anyone interested, here is the working code for a door that opens and closes based on the proximity of creatures with light sources: ScriptName LohithaLightOpenDarkClose ;A door opens or closes based on the nearness of a creature with a light. float triggerDist float requiredLight ref curActor short shouldOpen Begin GameMode set curActor to GetFirstRef 69 1 set triggerDist to 300 set requiredLight to 1 set shouldOpen to 0 if GetDistance PlayerRef < triggerDist && PlayerRef.GetActorLightAmount > requiredLight set shouldOpen to 1 endif while (curActor && shouldOpen == 0) if GetDistance curActor < triggerDist && curActor.GetActorLightAmount > requiredLight set shouldOpen to 1 break endif set curActor to GetNextRef loop if shouldOpen == 1 SetOpenState 1 else SetOpenState 0 endif End Edited December 20, 2018 by Guest Link to comment Share on other sites More sharing options...
Recommended Posts