IsPlayerInRangeOfPoint - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: IsPlayerInRangeOfPoint (
/showthread.php?tid=562138)
IsPlayerInRangeOfPoint -
nezo2001 - 07.02.2015
Hello, I made a command to buy business but when i come inside the pickup i tell me that i am not in any business
PHP код:
CMD:buybiz(playerid, params[])
{
new string[128];
for(new i = 0;i < sizeof(BusinessInfo);i++)
{
if(!IsPlayerInRangeOfPoint(playerid, 5.0 ,BusinessInfo[i][bEntranceX], BusinessInfo[i][bEntranceY], BusinessInfo[i][bEntranceZ])) return SendClientMessage(playerid, COLOR_RED, "You arn't near any business");
if(BusinessInfo[i][bPrice] > GetPlayerMoney(playerid)) return SendClientMessage(playerid, COLOR_RED, "You don't habe enoght money");
if(BusinessInfo[i][bOwned] != 0)
{
format(string,sizeof(string),"This business is already owned by: %s",BusinessInfo[i][bOwner]);
SendClientMessage(playerid, COLOR_RED, string);
}
BusinessInfo[i][bOwned] = 1;
BusinessInfo[i][bOwner] = PlayerName(playerid);
BusinessInfo[i][bLocked] = 0;
BusinessInfo[i][bMoney] = 0;
GivePlayerMoney(playerid, -BusinessInfo[i][bPrice]);
}
return 1;
}
Please Help

!
Re: IsPlayerInRangeOfPoint -
dominik523 - 07.02.2015
I'm not sure is it because of this:
Код:
for(new i = 0;i < sizeof(BusinessInfo);i++)
but try to define somewhere MAX_BUSINESSES (Number) and then loop through them.
Re: IsPlayerInRangeOfPoint -
nezo2001 - 07.02.2015
I made the same loop in OnGameModInt() to create all the pickups and it worked so i think it is not in the loop
Re: IsPlayerInRangeOfPoint -
HazardouS - 07.02.2015
Check out your other topic, you made the same mistake here. Your loop goes through all the businesses and it gives you a message for every one of them that is not in range. One way of doing it is to declare a "success" variable initialized to 0 somewhere before the loop. Then, when your code gets executed, i.e. someone buys a business successfully, you make the "success" variable 1, like this:
pawn Код:
[bla bla]
GivePlayerMoney(playerid, -BusinessInfo[i][bPrice]);
success = 1;
[bla bla]
Then, when the loop is done, add an if statement like this:
[pawn]
if(success == 0)
{
//you weren't able to buy any business, so do something here.
}
https://sampforum.blast.hk/showthread.php?tid=562141
Re: IsPlayerInRangeOfPoint -
nezo2001 - 07.02.2015
Ok it worked by the stock that apear in the next topic xD