samisalreadytaken / vs_library

vscript library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

HPlayerEye.GetAngles() always returns vector : (0.000000, 0.000000, 0.000000)

eren-erver opened this issue · comments

I wasn't sure if this was a library bug or a coding mistake so I am posting it here.
The problem is when I execute StartTimer function. Console just prints vector : (0.000000, 0.000000, 0.000000)

IncludeScript("vs_library")

function StartTimer() {
	
	VS.Timer(false, 0.5 , Think)
	
	
    
}
function Think()
{
	HPlayer <- VS.GetLocalPlayer()
	HPlayerEye <- VS.CreateMeasure(HPlayer.GetName())
	printl(HPlayerEye.GetAngles())



	
}

Here are some screenshots of the event listeners:
event_listener-1
event_listener-2

Event listeners are irrelevant to angle measuring.

It's important to understand when to do what. Your code creates a new measure entity on each Think, and prints the freshly created entity's angles. Starting to measure is asynchronous, it starts measuring in the next frame.

You'll want to create the required entities first, then use another function to start all - asynchronous from the creation.

Checking if the entities were already created is also important to make sure duplicate entities are not created.

Where, when and how to call these functions depends on your map.

function InitEntities()
{
	if ( "hTimer" in this && hTimer )
		return

	hTimer <- VS.Timer( true, 0.5, Think ).weakref()
	HPlayer <- VS.GetLocalPlayer().weakref()
	HPlayerEye <- VS.CreateMeasure("").weakref()
}

function StartTimer()
{
	VS.SetMeasure( HPlayerEye, HPlayer.GetName() )
	// VS.OnTimer( hTimer, Think ) // can be used to change what function is called
	EntFireByHandle( hTimer, "Enable" )
}

function Think()
{
	printl( HPlayerEye.GetAngles() )
}