21.12.2013, 08:56
Why this code does not work properly?
How can I do it correctly?
pawn Код:
if(DistanceBetweenObjectAndPlayer(playerid) < 3.5){
//this close to the object
}else{
//not close to the object
}
pawn Код:
stock DistanceBetweenObjectAndPlayer(playerid){
new Float:pos1[3],Float:pos2[3],Float:distance;
for(new slots=1,idx=MAX_SLOTS;slots!=idx;slots++){
GetObjectPos(VarObject[slots], pos1[0], pos1[1], pos1[2]);
GetPlayerPos(playerid, pos2[0], pos2[1], pos2[2]);
distance = floatsqroot(floatpower(floatabs(floatsub(pos1[0], pos2[0])),2)+floatpower(floatabs(floatsub(pos1[1], pos2[1])),2)+floatpower(floatabs(floatsub(pos1[2], pos2[2])),2));
} return floatround(distance);
}