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
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;
}
if(IsValidObject(i) && IsChair(i)) continue;
There's something I can't understand : why this line ?
pawn Код:
Actually, if the object is valid (so if it exists) and if it's a chair, you shouldn't skip his ID. |
if(!IsValidObject(i) && IsChair(i)) continue;
-1 28
for(new i = 0; i < MAX_OBJECTS; i++) { }
Assuming it's per-player objects, use GetPlayerObjectPos instead.
|
if(!IsChair(i)) continue;
GetDynamicObjectPos(i, xX, yY, zZ);
28 28 0.000000 0.000000 0.000000
//
new cid = GetNearest_Chair(playerid, 5.0);
printf("%d %d", cid, tamHQ[23]);
if(IsChair(cid))
{
if(sitting[playerid]) return SendError(playerid, "You're already sitting on a chair!");
new Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz;
GetDynamicObjectPos(cid, x, y, z);
printf("%f %f %f", x, y, z);
GetDynamicObjectRot(cid, rx, ry, rz);
SetPlayerPos(playerid, x, y, z);
SetPlayerFacingAngle(playerid, ry + 270); //Shouldn't it be 'rz + 270'? :l
TogglePlayerControllable(playerid, 0);
}
//
GetNearest_Chair(playerid, Float:distance)
{
new Float:xX, Float:yY, Float:zZ, Float:odist, retElement = -1;
for(new i = 0; i < MAX_OBJECTS; i++)
{
if(!IsChair(i)) continue;
GetDynamicObjectPos(i, xX, yY, zZ);
odist = GetPlayerDistanceFromPoint(playerid, xX, yY, zZ);
if(retElement == -1 || odist < distance)
{
retElement = i;
distance = odist;
}
}
return retElement;
}