Quote:
Originally Posted by JuanitoAlimana
Displaying debug trace (plugin "piss.amxx", version "2.0")
[AMXX] Run time error 11: divide
[AMXX] [0] piss.sma::make_pee (line 89)
How to solve this?
PHP Code:
public make_pee(ids[]) { new id=ids[0] new vec[3] new aimvec[3] new velocityvec[3] new length get_user_origin(id,vec) get_user_origin(id,aimvec,3) new distance = get_distance(vec,aimvec) new speed = floatround(distance*1.9)
velocityvec[0]=aimvec[0]-vec[0] velocityvec[1]=aimvec[1]-vec[1] velocityvec[2]=aimvec[2]-vec[2]
length=sqrt(velocityvec[0]*velocityvec[0]+velocityvec[1]*velocityvec[1]+velocityvec[2]*velocityvec[2])
velocityvec[0]=velocityvec[1]*speed/length /// line 89 velocityvec[1]=velocityvec[2]*speed/length velocityvec[2]=velocityvec[0]*speed/length
|
When you need to debug an error think about what may be happening. First thing that comes to mind is division by zero, which will produce an error.
So you can either do a server_print() or log() of the speed and length variables to ensure they are valid/expected values, or just ensure they are non-zero before executing that code.
PHP Code:
//Identify if division by zero is the issue, and then adjust code to ensure this doesnt happen to begin with
server_print( "speed=%d length=%d" , speed , length )
//or if this is expected, just have alternate code in place if you cannot do what is expected.
if ( speed && length )
{
velocityvec[0]=velocityvec[1]*speed/length /// line 89
velocityvec[1]=velocityvec[2]*speed/length
velocityvec[2]=velocityvec[0]*speed/length
}
else
{
//speed or length was zero so do something else.
}
__________________