Jump to content

[LE] How do LOS work ?


Archaros

Recommended Posts

Hi !

I'm beginner and I'd like to understand how the LOS events work. I kinda need a bit of help, please ? :smile:

 

EDIT : Let's make it much simpler, here's my code :

Scriptname sun extends Actor


Function SomeFunction()
  RegisterForSingleLOSGain(Game.GetPlayer(), self) 
EndFunction


Event OnGainLOS(Actor akViewer, ObjectReference akTarget)
  if akViewer == Game.GetPlayer()
  if akTarget == self
    ; do stuff
  Endif
  Endif
EndEvent


Event OnLostLOS(Actor akViewer, ObjectReference akTarget)
  if akViewer == Game.GetPlayer()
  if akTarget == self
    ; stop doing stuff
  Endif
  Endif
EndEvent

I don't understand why it doesn't work x(
It should "do stuff" when the player is seeing the object having this script.

Edited by Archaros
Link to comment
Share on other sites

1. OnDeath cares about what form the event is attached to, since it only triggers when that reference dies.

With OnGainLOS, it's different, I think. As far as I understand by reading on the wiki, you can register any script for LOS gain no matter what it is attached to, since the event doesn't care about what the "self" is at any point, but rather uses two variables (akViewer and akTarget) to define which references will actually trigger the event. So, because you've already defined what viewer and target you're interested in as you registered, you will not need to check what akViewer and akTarget refers to in the OnGainLOS event, unless you have registered "self" more than once using the same viewer or target. The wiki probably explains these things better than me, though, so take a look at the pages I linked you to.

 

2. Yes, the keyword "self" can be used to refer to the form or reference that the script is attached to (or more correctly stated; the instance of the script).

Link to comment
Share on other sites

If called on the player, LOS is restricted to whether the camera can see the object, not whether the object could be seen by the character itself. In other words, if a bag is behind by a crate, and the camera can't see the bag because of the crate, LOS will be false. It checks three spots in the camera's FOV. Top, middle and bottom, if any of these is not obscured, LOS will be true.

That's how I understand it.

Edited by Rasikko
Link to comment
Share on other sites

You will find these in next scripts, which stands for classes Form.psc, Alias.psc and ActiveMagicEffect.psc

; --- register

; Requirement for all three register functions:
; "If the viewer is not the player, the target must be another actor!"

; Register for LOS gain and lost events between the viewer and the target
; A loss or gain event will be sent immediately, depending on whether or
; not the viewer is already looking at the target or not
Function RegisterForLOS(Actor akViewer, ObjectReference akTarget) native

; Register for only the first LOS gain event between the viewer and the target
; If the viewer is already looking at the target, an event will be received almost immediately
Function RegisterForSingleLOSGain(Actor akViewer, ObjectReference akTarget) native

; Register for only the first LOS lost event between the viewer and the target
; If the viewer is already not looking at the target, an event will be received almost immediately
Function RegisterForSingleLOSLost(Actor akViewer, ObjectReference akTarget) native

; --- unregister

; Unregister for any LOS events between the viewer and target
Function UnregisterForLOS(Actor akViewer, ObjectReference akTarget) native

; --- events

; LOS event, sent whenever the viewer first sees the target (after registering)
Event OnGainLOS(Actor akViewer, ObjectReference akTarget)
EndEvent

; Lost LOS event, sent whenever the viewer first loses sight of the target (after registering)
Event OnLostLOS(Actor akViewer, ObjectReference akTarget)
EndEvent

and a sample script for you:

xyzLOS_TestActorScript

 

Scriptname xyzLOS_TestActorScript extends Actor
; https://forums.nexusmods.com/index.php?/topic/7356241-how-do-los-work/
; 'Actor' is a subclass of 'form' class.

; DLC1 sample script as ActiveMagicEffect: "DLC1DeerFXGlowScript.psc"

; -- FUNCTION --

;----------------------
FUNCTION SomeFunction()
;----------------------
; We assume this script is attached to NPC and not to the player.
; "Player can be here only the target, not the viewer to get the event triggered!" (Maybe I am wrong with this, ReDragon)

    RegisterForSingleLOSGain(self, Game.GetPlayer())       ;* register..
ENDFUNCTION


; -- EVENTs --

EVENT OnCellLoad()
    SomeFunction()        ; make registration only, if useful
ENDEVENT


EVENT OnGainLOS(Actor akViewer, ObjectReference akTarget)   ;* ..for this event
; viewer is already looking at the target
    RegisterForSingleLOSLost(akViewer, akTarget)            ;**

    Debug.Notification("NPC is looking at the player.")
    Debug.Trace(" OnGainLOS() - akViewer = " +akViewer+ ", akTarget = " +(akTarget as Actor)+ " == " +Game.GetPlayer())
ENDEVENT


EVENT OnLostLOS(Actor akViewer, ObjectReference akTarget)   ;**
; viewer first loses sight of the target

    Debug.Notification("NPC loses sight of the player.")
    Debug.Trace(" OnLostLOS() - akViewer = " +akViewer+ ", akTarget = " +(akTarget as Actor)+ " == " +Game.GetPlayer())
ENDEVENT

 

 

Edited by ReDragon2013
Link to comment
Share on other sites

  • Recently Browsing   0 members

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