SA-MP Forums Archive
IsPlayerInRangeOfPoint issue - 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 issue (/showthread.php?tid=474326)



IsPlayerInRangeOfPoint issue - TonyII - 07.11.2013

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;
}



Re: IsPlayerInRangeOfPoint issue - Konstantinos - 07.11.2013

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;
}



Re: IsPlayerInRangeOfPoint issue - TonyII - 07.11.2013

It works now, thank you