Raised This Month: $51 Target: $400
 12% 

pev(id, pev_velocity, velocity) | I'm confused


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 12-15-2011 , 13:11   pev(id, pev_velocity, velocity) | I'm confused
Reply With Quote #1

Hi

This is my little code.

PHP Code:
 
think
(id)
{
 
    
// just for testing
    
static Float:vel[3];
    
pev(idpev_velocityvel);
    
client_print(idprint_chat"[SPEED: %i %i %i]"vel[0], vel[1], vel[2])
 
     if(
fm_get_ent_speed(id) < 50)
     {
           
g_nextthink 5.0
     
}
     else if(
fm_get_ent_speed(id) < 100)
     {
           
g_nextthink 4.0
     
}
     else if(
fm_get_ent_speed(id) < 200)
     {
           
g_nextthink 4.0
     
}
     else if(
fm_get_ent_speed(id) < 300)
     {
           
g_nextthink 2.0
     
}
     else if(
fm_get_ent_speed(id) < 400)
     {
           
g_nextthink 1.0
     
}
}
 
 
stock Float:fm_get_ent_speed(id)
{
 if(!
pev_valid(id))
  return 
0.0;
 
 static 
Float:vVelocity[3];
 
pev(idpev_velocityvVelocity);
 
 
vVelocity[2] = 0.0;
 
 return 
vector_length(vVelocity);

confusing place : how this working

PHP Code:
 
     
if(fm_get_ent_speed(id) < 50)
     {
           
g_nextthink 5.0
     
}
     else if(
fm_get_ent_speed(id) < 100)
     {
           
g_nextthink 4.0
     
}
     else if(
fm_get_ent_speed(id) < 200)
     {
           
g_nextthink 4.0
     
}
     else if(
fm_get_ent_speed(id) < 300)
     {
           
g_nextthink 2.0
     
}
     else if(
fm_get_ent_speed(id) < 400)
     {
           
g_nextthink 1.0
     

This code part is working fine.
When i slow, then think value will be small and when i are fast then think value will be high.

but

client_print show me a this

[SPEED: 102032010... 10302.... 0]
and when i jump

[SPEED: x x 1021322....]

the value that i have checked here
if(fm_get_ent_speed(id) < 400) < - ( this is how i check player speed, as i know the normal speed is 240, duck 120 , walk 160 or 180 )


is wrong but in game it work like i want, like i calculated in code.

it must work like this
PHP Code:
     if(fm_get_ent_speed(id) < 50)
     {
           
g_nextthink 5.0
     
}
     else if(
fm_get_ent_speed(id) < 100)
     {
           
g_nextthink 4.0
     
}
     else if(
fm_get_ent_speed(id) < 200)
     {
           
g_nextthink 4.0
     
}
     else if(
fm_get_ent_speed(id) < 300)
     {
           
g_nextthink 2.0
     
}
     else if(
fm_get_ent_speed(id) < 400
     {
           
g_nextthink 1.0
     
}
     else 
// this will be chosen
     
{
           
g_nextthink 0.5
     

because value what client_print show is very high and not one of my checking list, i think client print show me a wrong numbers.
or how it work like it work?

Last edited by .Dare Devil.; 12-15-2011 at 13:12.
.Dare Devil. is offline
StickP0le
Senior Member
Join Date: Jan 2010
Location: cuantocabron.com
Old 12-15-2011 , 15:05   Re: pev(id, pev_velocity, velocity) | I'm confused
Reply With Quote #2

you have to change this
PHP Code:
 client_print(idprint_chat"[SPEED: %i %i %i]"vel[0], vel[1], vel[2]) 
for this
PHP Code:
 client_print(idprint_chat"[SPEED: %f %f %f]"vel[0], vel[1], vel[2]) 
why %f? because the user current speed is a float, try that and let me know if work
StickP0le is offline
Xellath
Veteran Member
Join Date: Dec 2007
Location: Sweden
Old 12-15-2011 , 15:08   Re: pev(id, pev_velocity, velocity) | I'm confused
Reply With Quote #3

Not entirely sure what you're trying to accomplish...

Anyway, you're printing integers when the velocity is a floated number. %i -> %f
You should also store the value of fm_get_ent_speed in a variable instead of calling it x times.
__________________
Achievements API - a simple way for you to create your OWN custom achievements!
Xellath 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 17:31.


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