IsPlayerInRangeOfPoint issue
#1

Hey, I got trouble with this cmd, the player should be able to buy the nearest service if it's not owned by someone else yet, if the service ID is 0 the command works perfectly fine, but anything above that I get the message 'You aren't near a service thats for sale' everytime I type this command near a service thats for sale. What could cause this problem?
pawn Код:
CMD:buyservice(playerid, params[])
{
    new playername[MAX_PLAYER_NAME];
    for(new x = 0; x < sizeof(ServiceInfo); x++)
    {
        if(IsPlayerInRangeOfPoint(playerid,4.0,ServiceInfo[x][sExteriorX],ServiceInfo[x][sExteriorY],ServiceInfo[x][sExteriorZ]))
        {
            if(ServiceInfo[x][sOwned] == 0)
            {
            if(PlayerInfo[playerid][pServiceOwner] >= 0) return SendClientMessage(playerid, COLOR_DARKRED, "[SERVER] {FFFFFF}You already own a service.");
            if(GetPlayerCash(playerid) < ServiceInfo[x][sPrice]) return SendClientMessage(playerid, COLOR_DARKRED, "[SERVER] {FFFFFF}You can't afford this service.");
            ServiceInfo[x][sOwned] = 1;
            PlayerInfo[playerid][pServiceOwner] = x;
            PlayerInfo[playerid][pService] = x;
            PlayerInfo[playerid][pSRank] = 6;
            GivePlayerCash(playerid,-ServiceInfo[x][sPrice]);
            GetPlayerName(playerid,playername, sizeof(playername));
            strmid(ServiceInfo[x][sOwner],playername,0,strlen(playername),255);
            SendClientMessage(playerid,COLOR_WHITE,"Congratulations on your purchase, contact a admin to set your service.");
            UpdateService(x);
            return 1;
            }
            else return SendClientMessage(playerid, COLOR_DARKRED, "[SERVER] {FFFFFF}This service isn't for sale.");
        }
        else return SendClientMessage(playerid, COLOR_DARKRED, "[SERVER] {FFFFFF}You aren't near any service thats for sale.");
    }
    return 1;
}
Reply
#2

That should work:
pawn Код:
CMD:buyservice(playerid, params[])
{
    new bool: inrange;
    for(new x = 0; x < sizeof(ServiceInfo); x++)
    {
        if(IsPlayerInRangeOfPoint(playerid,4.0,ServiceInfo[x][sExteriorX],ServiceInfo[x][sExteriorY],ServiceInfo[x][sExteriorZ]))
        {
            inrange = true;
            if(ServiceInfo[x][sOwned] == 0)
            {
                if(PlayerInfo[playerid][pServiceOwner] >= 0) return SendClientMessage(playerid, COLOR_DARKRED, "[SERVER] {FFFFFF}You already own a service.");
                if(GetPlayerCash(playerid) < ServiceInfo[x][sPrice]) return SendClientMessage(playerid, COLOR_DARKRED, "[SERVER] {FFFFFF}You can't afford this service.");
                ServiceInfo[x][sOwned] = 1;
                PlayerInfo[playerid][pServiceOwner] = x;
                PlayerInfo[playerid][pService] = x;
                PlayerInfo[playerid][pSRank] = 6;
                GivePlayerCash(playerid,-ServiceInfo[x][sPrice]);
                new playername[MAX_PLAYER_NAME];
                GetPlayerName(playerid,playername, sizeof(playername));
                strmid(ServiceInfo[x][sOwner],playername,0,strlen(playername),255);
                SendClientMessage(playerid,COLOR_WHITE,"Congratulations on your purchase, contact a admin to set your service.");
                UpdateService(x);
            }
            else SendClientMessage(playerid, COLOR_DARKRED, "[SERVER] {FFFFFF}This service isn't for sale.");
            break;
        }
    }
    if(!inrange) SendClientMessage(playerid, COLOR_DARKRED, "[SERVER] {FFFFFF}You aren't near any service thats for sale.");
    return 1;
}
Reply
#3

It works now, thank you
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)