AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   pev(id, pev_velocity, velocity) | I'm confused (https://forums.alliedmods.net/showthread.php?t=174098)

.Dare Devil. 12-15-2011 13:11

pev(id, pev_velocity, velocity) | I'm confused
 
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?

StickP0le 12-15-2011 15:05

Re: pev(id, pev_velocity, velocity) | I'm confused
 
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

Xellath 12-15-2011 15:08

Re: pev(id, pev_velocity, velocity) | I'm confused
 
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.


All times are GMT -4. The time now is 12:11.

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