Raised This Month: $ Target: $400
 0% 

Why does this code give this error? Can you fix it please?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
cs1.7
Senior Member
Join Date: Oct 2008
Old 03-20-2010 , 23:48   Why does this code give this error? Can you fix it please?
Reply With Quote #1

Hi,

what is wrong in the below code?

It gives this error in console:

Quote:
PM Got a NaN velocity 0
PM Got a NaN velocity 1
PHP Code:
stock create_velocity_vector(victim,attacker,Float:velocity[3])
{
    if(!
is_user_alive(attacker) || is_user_bot(attacker))
        return 
0;

    new 
Float:vicorigin[3];
    new 
Float:attorigin[3];
    
pevvictimpev_originvicorigin);
    
pevattackerpev_originattorigin);
    
    new 
Float:cheese floatpower(vicorigin[0]-attorigin[0], 2.0) + floatpower(vicorigin[1]-attorigin[1] ,2.0) + floatpower(vicorigin[2]-attorigin[2], 2.0 );
    new 
distance floatroundfloatpowercheese0.5 ) );

    new 
Float:origin2[3]
    
origin2[0] = vicorigin[0] - attorigin[0];
    
origin2[1] = vicorigin[1] - attorigin[1];

    new 
Float:largestnum 0.0;

    if(
floatabs(origin2[0])>largestnumlargestnum floatabs(origin2[0]);
    if(
floatabs(origin2[1])>largestnumlargestnum floatabs(origin2[1]);

    
origin2[0] /= largestnum;
    
origin2[1] /= largestnum;

    
velocity[0] = ( origin2[0] * 200000 ) / (distance 50);
    
velocity[1] = ( origin2[1] * 200000 ) / (distance 50);
    if(
velocity[0] <= 20.0 || velocity[1] <= 20.0)
        
velocity[2] = random_float(275.0 300.0);

    return 
1;

__________________
_____________
/_____\
[° ||| °]
./..............\▓

Last edited by cs1.7; 04-15-2010 at 06:43.
cs1.7 is offline
cs1.7
Senior Member
Join Date: Oct 2008
Old 04-15-2010 , 06:28   Re: Why does this code give this error?
Reply With Quote #2

can no one help?

i am not sure but i think it also freezes / crashes the server but i have to test if it's really this code which causes the server freeze.
__________________
_____________
/_____\
[° ||| °]
./..............\▓
cs1.7 is offline
Xanimos
Veteran Member
Join Date: Apr 2005
Location: Florida
Old 04-15-2010 , 14:43   Re: Why does this code give this error? Can you fix it please?
Reply With Quote #3

Id check to see if the victim is alive

Correct me if I'm wrong but with the following:
PHP Code:
    new Float:cheese floatpower(vicorigin[0]-attorigin[0], 2.0) + floatpower(vicorigin[1]-attorigin[1] ,2.0) + floatpower(vicorigin[2]-attorigin[2], 2.0 );
    new 
distance floatroundfloatpowercheese0.5 ) ); 
You're doing
Quote:
Originally Posted by Algebra
( ( vx - ax )² + (vy - ay)² + ( vz - az )² )½
Which would simplify to
Quote:
Originally Posted by Algebra
(vx - ax) + (vy - ay) + (vz - az)
So in code you can simplify to:
PHP Code:
    new distance floatround( (vicorigin[0]-attorigin[0]) + (vicorigin[1]-attorigin[1] ) + ( vicorigin[2]-attorigin[2] ) ); 
-------------

The following code can be simplified:
PHP Code:
    new Float:largestnum 0.0;

    if(
floatabs(origin2[0])>largestnumlargestnum floatabs(origin2[0]);
    if(
floatabs(origin2[1])>largestnumlargestnum floatabs(origin2[1]); 
to
PHP Code:
    new Float:largestnum floatabs(origin2[0]);
    if(
floatabs(origin2[1])>largestnumlargestnum floatabs(origin2[1]); 
because when largetsnum is 0 the first if will always be true.


To answer your question, I don't see anything in your code that is causing an error. I'm assuming in your code surrounding this function there is some problem.
Xanimos is offline
Send a message via AIM to Xanimos Send a message via MSN to Xanimos
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 04-15-2010 , 15:34   Re: Why does this code give this error? Can you fix it please?
Reply With Quote #4

I think it means the PM_* functions (engine) are receiving an invalid (NaN = Not a Number) velocity value for the X (0) and Y (1) values.

PHP Code:
// this
velocity[0] = ( origin2[0] * 200000 ) / (distance 50);
// can be simplified to
velocity[0] = ( origin2[0] * 200000 ) / distance 50;
// which can be simplified to
velocity[0] = ( origin2[0] * 200000 50 ) / distance;
// which can be simplified to
velocity[0] = ( origin2[0] * 10000000 ) / distance
Now, since Pawn limits values to 32 bits, you are probably breaking this barrier.
I would suggest writing it like this:

PHP Code:
velocity[0] = origin2[0] * ( 10000000 distance ); 
This way, you are multiplying by a smaller number so you don't try to break the barrier and then reduce.

So, with what Xanimos and I both said:

PHP Code:
stock create_velocity_vector(victim,attacker,Float:velocity[3])
{
    if(!
is_user_alive(attacker) || is_user_bot(attacker))
        return 
0;

    new 
Float:vicorigin[3];
    new 
Float:attorigin[3];
    
pevvictimpev_originvicorigin);
    
pevattackerpev_originattorigin);
    
    new 
distance floatround( (vicorigin[0]-attorigin[0]) + (vicorigin[1]-attorigin[1] ) + ( vicorigin[2]-attorigin[2] ) );  

    new 
Float:origin2[3]
    
origin2[0] = vicorigin[0] - attorigin[0];
    
origin2[1] = vicorigin[1] - attorigin[1];

    new 
Float:largestnum floatabs(origin2[0]);
    if(
floatabs(origin2[1])>largestnumlargestnum floatabs(origin2[1]);

    
origin2[0] /= largestnum;
    
origin2[1] /= largestnum;

    
velocity[0] = origin2[0] * ( 10000000 distance );  
    
velocity[1] = origin2[1] * ( 10000000 distance );  
    if(
velocity[0] <= 20.0 || velocity[1] <= 20.0)
        
velocity[2] = random_float(275.0 300.0);

    return 
1;

__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Reply



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 08:38.


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