21.02.2020, 14:43
I have created this code where first I create a Baloon with /flare cmd over the player at a height of 50 from the current position of the player. Then that object starts moving down to the player position.
I am using /near function to detect whether the player is near to the object or not. if Yes "You are near the ballon" will be displayed else "You are far away" will be displayed.
There is no compilation error but I think I am lacking with some logic here. my else statement always gets executed. "You are far away".
I am using /near function to detect whether the player is near to the object or not. if Yes "You are near the ballon" will be displayed else "You are far away" will be displayed.
There is no compilation error but I think I am lacking with some logic here. my else statement always gets executed. "You are far away".
pawn Code:
new Float:x, Float:y, Float:z;
new baloon, movetime;
if (!strcmp("/flare", cmdtext, true))
{
GetPlayerPos(playerid, x, y, z);
baloon = CreateObject(19333, Float:x, Float:y, Float:z+50.00, 0, 0, 96.0,300.0);
SendClientMessage(playerid, -1, "Flare created");
new string[50];
//while(movetime)
movetime = MoveObject(baloon, x, y, z, 2.00);
format(string, sizeof(string), "Object will finish moving in %d milliseconds", movetime);
SendClientMessage(playerid, 0xFF000000, string);
//Now Lets detect if the player is near th object
return 1;
}
if (!strcmp("/near", cmdtext))
{
GetObjectPos(baloon, x, y, z);
if (IsPlayerInRangeOfPoint(playerid, 10.0, x, y, z))
{
SendClientMessage(playerid,0xFFFFFFFF,"You are near the object");
}
else
{
SendClientMessage(playerid,0xFFFFFFFF,"You are far away");
}
return 1;
}