Problem with /buyprop
#1

pawn Код:
CMD:buyprop(playerid,params[])
{
    if(pInfo[playerid][pHouse] == 1) return SendClientMessage(playerid,COLOR_GREY,"You cannot buy more than one house.");
    for(new i = 1; i < MAX_HOUSES; i++)
    {
        if(IsPlayerInRangeOfPoint(playerid,2,HouseInfo[i][hX],HouseInfo[i][hY],HouseInfo[i][hZ]))
        {
            if(!HouseInfo[i][hX]) continue;
            if(GetPlayerMoney(playerid) >= HouseInfo[i][hPrice])
            {
                if(strcmp(HouseInfo[i][hOwner],"",false))
                {
                    format(HouseInfo[i][hOwner],24,"%s",pName(playerid));
                    pInfo[playerid][pHouse] = 1;
                    format(string,sizeof(string),"You've successfully bought this house.");
                    DestroyDynamicPickup(HouseInfo[i][hPickup]);
                    GivePlayerMoney(playerid,-HouseInfo[i][hPrice]);
                    format(string,sizeof(string),"Owner: %s",HouseInfo[i][hOwner]);
                    HouseInfo[i][hText] = CreateDynamic3DTextLabel(string, 0xFFFFFFFF, HouseInfo[i][hX],HouseInfo[i][hY],HouseInfo[i][hZ], 50, INVALID_PLAYER_ID,INVALID_VEHICLE_ID, 0, -1,0);
                    HouseInfo[i][hPickup] = CreateDynamicPickup(1272,1,HouseInfo[i][hX],HouseInfo[i][hY],HouseInfo[i][hZ],-1,0,-1,50.0);

                }
            }
            else return SendClientMessage(playerid,COLOR_GREY,"You don't have enough money.");
        }
        else return SendClientMessage(playerid,COLOR_GREY,"You're nowhere close to a house.");
    }
    return 1;
}
For some reason this command always returns "You're nowhere close to a house even though I am on the house pickup. Does someone knows the solution.
Reply
#2

try print HouseInfo[i][hX] , HouseInfo[i][hY] and HouseInfo[i][hZ]

They are probably not loaded properly.
Reply
#3

Tried already and they're fine.
Reply
#4

I've read your code again and (maybe) found the problem,

Your code was designed to send this message on the first house.

Therefore i modified your code abit,

pawn Код:
CMD:buyprop(playerid,params[])
{
    new bool:pnearhousecheck = false;
    if(pInfo[playerid][pHouse] == 1) return SendClientMessage(playerid,COLOR_GREY,"You cannot buy more than one house.");
    for(new i = 1; i < MAX_HOUSES; i++)
    {
        if(IsPlayerInRangeOfPoint(playerid,2,HouseInfo[i][hX],HouseInfo[i][hY],HouseInfo[i][hZ]))
        {
            //if(!HouseInfo[i][hX]) continue; // no need, what if the house position was in negative?
            if(GetPlayerMoney(playerid) >= HouseInfo[i][hPrice])
            {
                if(!strcmp(HouseInfo[i][hOwner],"",false)) // i guess it shouldn't be if(strcmp(HouseInfo[i][hOwner],"",false)) ?
                {
                    format(HouseInfo[i][hOwner],24,"%s",pName(playerid));
                    pInfo[playerid][pHouse] = 1;
                    SendClientMessage(playerid, -1, "You've successfully bought this house.");
                    //format(string,sizeof(string),"You've successfully bought this house."); // Why not just use SendClientMessage? ^
                    DestroyDynamicPickup(HouseInfo[i][hPickup]);
                    GivePlayerMoney(playerid,-HouseInfo[i][hPrice]);
                    format(string,sizeof(string),"Owner: %s",HouseInfo[i][hOwner]);
                    HouseInfo[i][hText] = CreateDynamic3DTextLabel(string, 0xFFFFFFFF, HouseInfo[i][hX],HouseInfo[i][hY],HouseInfo[i][hZ], 50, INVALID_PLAYER_ID,INVALID_VEHICLE_ID, 0, -1,0);
                    HouseInfo[i][hPickup] = CreateDynamicPickup(1272,1,HouseInfo[i][hX],HouseInfo[i][hY],HouseInfo[i][hZ],-1,0,-1,50.0);

                }
                else return SendClientMessage(playerid, COLOR_GREY, "House Bought already."); // a SendClientMessage from me
            }
            else return SendClientMessage(playerid,COLOR_GREY,"You don't have enough money.");
           
            pnearhousecheck = true;
           
            break;
        }
    }
   
    if(!pnearhousecheck)
        SendClientMessage(playerid,COLOR_GREY,"You're nowhere close to a house.");
    return 1;
}
Also please read the comments beside each line.
Reply
#5

That was so helpful. Thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)