Raised This Month: $32 Target: $400
 8% 

Solved Check if Vector is valid


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
scorpius2k1
Senior Member
Join Date: Feb 2016
Old 07-20-2018 , 15:11   Check if Vector is valid
Reply With Quote #1

How would I go about checking if all parts of a Vector[3] are valid? I am guessing the proper description would be NULL_VECTOR? I have a script I am trying to debug with this error in my console:

Code:
Bad SetLocalOrigin(nan,nan,nan) on info_particle_system
Presumably, this happens when I am calling
PHP Code:
TeleportEntity(iEntityfOriginNULL_VECTORNULL_VECTOR
I'm sure it's simple, just need to make sure I am doing it right, thanks all!
__________________
{__ PIRATES COVE __} ● HIGH-KILL Community | Stats ●
Half-Life 2: Deathmatch
66.151.244.149:27016 => CONNECT

Last edited by scorpius2k1; 07-21-2018 at 11:47. Reason: Solved
scorpius2k1 is offline
mug1wara
AlliedModders Donor
Join Date: Jun 2018
Old 07-20-2018 , 15:22   Re: Check if Vector is valid
Reply With Quote #2

afaik there's no check for valid vectors.

send more code ( ͡° ͜ʖ ͡°), easier to help
mug1wara is offline
scorpius2k1
Senior Member
Join Date: Feb 2016
Old 07-20-2018 , 15:42   Re: Check if Vector is valid
Reply With Quote #3

Quote:
Originally Posted by mug1wara View Post
afaik there's no check for valid vectors.

send more code ( ͡° ͜ʖ ͡°), easier to help
Surely there is a simple way to do this. Something really simply just to check to see if a vector is valid and not NULL, etc. If I were to make a stock, something like this:

PHP Code:
stock bool IsValidVector(float fVector[3])
{
    
/// code to check if 'fVector' IS VALID (NOT NULL, EMPTY, ETC)

__________________
{__ PIRATES COVE __} ● HIGH-KILL Community | Stats ●
Half-Life 2: Deathmatch
66.151.244.149:27016 => CONNECT
scorpius2k1 is offline
micapat
Veteran Member
Join Date: Feb 2010
Location: Nyuu, nyuu (France).
Old 07-20-2018 , 15:51   Re: Check if Vector is valid
Reply With Quote #4

Maybe you could show us how you're computing "fOrigin"?
__________________
micapat is offline
scorpius2k1
Senior Member
Join Date: Feb 2016
Old 07-20-2018 , 16:15   Re: Check if Vector is valid
Reply With Quote #5

Quote:
Originally Posted by micapat View Post
Maybe you could show us how you're computing "fOrigin"?
Any vector, just check if it actually has a value in it. That's all, really simple. I'm not sure what else I could describe here.
__________________
{__ PIRATES COVE __} ● HIGH-KILL Community | Stats ●
Half-Life 2: Deathmatch
66.151.244.149:27016 => CONNECT
scorpius2k1 is offline
scorpius2k1
Senior Member
Join Date: Feb 2016
Old 07-20-2018 , 16:53   Re: Check if Vector is valid
Reply With Quote #6

Quote:
Originally Posted by micapat View Post
Maybe you could show us how you're computing "fOrigin"?
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
    
}

__________________
{__ PIRATES COVE __} ● HIGH-KILL Community | Stats ●
Half-Life 2: Deathmatch
66.151.244.149:27016 => CONNECT

Last edited by scorpius2k1; 07-20-2018 at 16:54.
scorpius2k1 is offline
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
scorpius2k1
Senior Member
Join Date: Feb 2016
Old 07-20-2018 , 17:54   Re: Check if Vector is valid
Reply With Quote #8

Quote:
Originally Posted by LenHard View Post
unless that's just part of your example?
}[/PHP]
Thanks for your reply, yes that was just a bare and stripped down (non-functional) example of the actual code. Just looking to see if a vector (regardless of how it was assigned values) is valid and not NaN or NULL. Nothing fancy. I will give your code a shot this weekend, much appreciated.

Thanks for everyone's replies.
__________________
{__ PIRATES COVE __} ● HIGH-KILL Community | Stats ●
Half-Life 2: Deathmatch
66.151.244.149:27016 => CONNECT
scorpius2k1 is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 07-20-2018 , 18:16   Re: Check if Vector is valid
Reply With Quote #9

If the problem is just that the values are NaN, then you can check by comparing the value to itself. NaN always compares as inequal, even to itself.

It's possible for {0, 0, 0} to be a valid location in a map. It's unlikely that anything will be exactly at that spot unless it was intentionally spawned there (or someone forgot to set coordinates).
Fyren is offline
scorpius2k1
Senior Member
Join Date: Feb 2016
Old 07-21-2018 , 11:43   Re: Check if Vector is valid
Reply With Quote #10

Quote:
Originally Posted by Fyren View Post
If the problem is just that the values are NaN, then you can check by comparing the value to itself. NaN always compares as inequal, even to itself.

It's possible for {0, 0, 0} to be a valid location in a map. It's unlikely that anything will be exactly at that spot unless it was intentionally spawned there (or someone forgot to set coordinates).
Thanks for you input you're absolutely right, it makes sense now how to do this. Here is the simple solution I came up with to check for invalid NaN vectors if anyone wants it. The NaN reference is in accordance to IEEE standards, which looks odd, but works.

Thanks everyone for your help

PHP Code:
stock bool IsValidVector(float fVector[3])
{
    
// NaN Check
    
if(fVector[0] != fVector[0] || fVector[1] != fVector[1] || fVector[2] != fVector[2])
    { return 
false; }

    
// Valid Vector
    
return true;

__________________
{__ PIRATES COVE __} ● HIGH-KILL Community | Stats ●
Half-Life 2: Deathmatch
66.151.244.149:27016 => CONNECT

Last edited by scorpius2k1; 07-21-2018 at 15:49. Reason: Updated stock; cannot use NULL_VECTOR per asherkin
scorpius2k1 is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 01:26.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode