05.07.2014, 17:39
This is quite a weird problem, can't find anything wrong in the script, yet I can't fix it either. I've scripted something to place the player to the closest chair to him, but the object's coordinates are not returned.
A part of the command:
Prints:
Functions:
So the object ID is returned correctly, but GetObjectPos is not returning its coords. What would be the problem?
A part of the command:
pawn Код:
new cid = GetNearest_Chair(playerid, 5.0);
printf("%d %d", cid, tamHQ[23]);
if(IsChair(cid))
{
if(sitting[playerid] == false)
{
new Float:x, Float:y, Float:z;
new Float:rx, Float:ry, Float:rz;
GetObjectPos(cid, x, y, z);
printf("%f %f %f", x, y, z);
GetObjectRot(cid, rx, ry, rz);
SetPlayerPos(playerid, x, y, z);
SetPlayerFacingAngle(playerid, ry+270);
TogglePlayerControllable(playerid, 0);
}
else return SendError(playerid, "You're already sitting on a chair!");
}
Код:
28 28 0.000000 0.000000 0.000000
pawn Код:
stock IsChair(objectid)
{
if(objectid == tamHQ[23]) return 1;
else return 0;
}
stock GetNearest_Chair(playerid, Float:distance)
{
new
Float:xX,
Float:yY,
Float:zZ,
retElement = -1
;
for(new i = 0; i < MAX_OBJECTS; i++)
{
if(IsValidObject(i) && IsChair(i)) continue;
GetObjectPos(i, xX, yY, zZ);
new Float:odist = GetPlayerDistanceFromPoint(playerid, xX, yY, zZ);
if (retElement == -1 && IsChair(i))
{
retElement = i;
distance = odist;
}
else if (odist < distance && IsChair(i))
{
retElement = i;
distance = odist;
}
}
return retElement;
}