Jump to content

Usage of RegisterForCrosshairRef()


OverlordManny

Recommended Posts

I'm having difficulties with RegisterForCrosshairRef(), perhaps I'm using it wrong. I'm trying to put a script on a weapon that when equipped will return my target's ref. I want to do this to eventually check the target's relationship to the player. I haven't gotten all of that written because I can't even get the ref to return. Here is what I have. Is it that fact that I have it attached to a weapon that is the problem? If so, how would I then accomplish my goal?

Scriptname DKMDyingBreath extends ObjectReference  

Event OnEquipped(Actor akActor)
	If akActor ==  Game.GetPlayer()
		RegisterForCrosshairRef()
		Debug.Notification("I was equipped")
	EndIf
EndEvent
 
Event OnCrosshairRefChange(ObjectReference ref)
	If ref
		Debug.Notification("Crosshair had " + ref + " targeted.")
	EndIf
EndEvent

Event OnUnEquipped(Actor akActor)
	If akActor ==  Game.GetPlayer()
		UnregisterForCrosshairRef()
		Debug.Notification("I was unequipped")
	EndIf
EndEvent
Edited by OverlordManny
Link to comment
Share on other sites

As a guess why it fails, the weapon is not a persistent reference so the OnCrosshairRefChange() isn't being called once the weapon is equipped.

This is only an assumption on my behalf and I haven't tested it , nor have I used the RegisterForCrosshairRef() functions yet.

Quote about OnEquipped from http://www.creationkit.com/OnEquipped_-_ObjectReference:

 

 

Notes

When an object is equipped it is inside a container, which means that you cannot call Member Functions on it. (Unless it is a persistent reference)

 

Ways around it could be create the weapon as a persistent item in the game, eg: place the weapon in the game world in CK.

Or

Use PlacAtMe with the abForcePersist bool set to True.

Or

Instead of attaching the script to your weapon, attach a script to the actor/player and use OnObjectEquipped and OnObjectUnequipped and check that the weapon un/equipped is your weapon when those events fire.

Edited by sLoPpYdOtBiGhOlE
Link to comment
Share on other sites

  • Recently Browsing   0 members

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