Problem with /buyprop -
Tayab - 10.02.2014
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.
Re: Problem with /buyprop -
Kirollos - 10.02.2014
try print HouseInfo[i][hX] , HouseInfo[i][hY] and HouseInfo[i][hZ]
They are probably not loaded properly.
Re: Problem with /buyprop -
Tayab - 10.02.2014
Tried already and they're fine.
Re: Problem with /buyprop -
Kirollos - 10.02.2014
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.
Re: Problem with /buyprop -
Tayab - 10.02.2014
That was so helpful. Thanks!