Thread: [Solved] Check if Vector is valid
View Single Post
LenHard
Senior Member
Join Date: Jan 2016
Old 07-20-2018 , 17:42   Re: Check if Vector is valid
Reply With Quote #7

Quote:
Originally Posted by scorpius2k1 View Post
Here is an example
PHP Code:
stock void SpawnEntity(int client) {
    
    
float fOrigin[3];
    
    
GetClientAbsOrigin(clientfOrigin);

    
int iEntity CreateEntityByName("prop_physics");

    if(
IsValidEntity()) {
        
GetEntPropVector(iEntityProp_Send"m_vecOrigin"fOrigin);

        
TeleportEntity(iEntityfOriginNULL_VECTORNULL_VECTOR
        
// Sometimes 'fPosition' is getting console errors
        // ==> Bad SetLocalOrigin(nan,nan,nan) on prop_physics
    
}

Well first of all, you need to spawn the prop before getting its location (unless that's just part of your example?), also you're getting the location before the prop really has an origin. So you need to teleport the entity/set its origin before retrieving its location.

For the stock, I'm not sure but I presume null vectors were to be 0.00000 for x, y, and z. So maybe

PHP Code:
stock bool IsValidVector(float fVec[3])
{
    
int iCheck;
    
    for (
int i 03; ++i)
    {
        if (
fVec[i] == 0.0000)
            ++
iCheck;
        else 
            break;
    }
    return 
view_as<bool>(iCheck != 3);

__________________

Last edited by LenHard; 07-20-2018 at 17:51.
LenHard is offline