IsPlayerInRangeOfPoint
#1

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(playeridparams[])
{
    new 
string[128];
    for(new 
0;sizeof(BusinessInfo);i++)
    {
        if(!
IsPlayerInRangeOfPoint(playerid5.0 ,BusinessInfo[i][bEntranceX], BusinessInfo[i][bEntranceY], BusinessInfo[i][bEntranceZ])) return SendClientMessage(playeridCOLOR_RED"You arn't near any business");
        if(
BusinessInfo[i][bPrice] > GetPlayerMoney(playerid)) return SendClientMessage(playeridCOLOR_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(playeridCOLOR_REDstring);
        }
        
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 !
Reply
#2

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.
Reply
#3

I made the same loop in OnGameModInt() to create all the pickups and it worked so i think it is not in the loop
Reply
#4

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
Reply
#5

Ok it worked by the stock that apear in the next topic xD
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)