09.03.2013, 18:53
Hey there, first of all - thank you for reading this.
I've made a stock which gets the house ID of the house I am at.
The stock:
And I use the HouseID here:
The /buyhouse works only for the first two houses I try. I mean.. Let's say I've 0 houses on the server.
I used /createhouse and created 5 houses with the IDs of 1, 2, 3, 4 and 5.
I can use /buyhouse at 2 random houses, but when I go to the third it will either return "This house is not for sale" or "You are not at any house"
Any ideas?
I've made a stock which gets the house ID of the house I am at.
The stock:
pawn Код:
stock GetHouseID(playerid)
{
for(new i = 0; i <= MAX_HOUSES; i++)
{
format(file, sizeof(file), "House_%d.ini", i);
if(fexist(file))
{
x = dini_Float(file, "EnterX");
y = dini_Float(file, "EnterY");
z = dini_Float(file, "EnterZ");
if(IsPlayerInRangeOfPoint(playerid, 3.0, x, y, z)) return HouseID = i;
return HouseID = -1;
}
}
return 1;
}
pawn Код:
if (strcmp("/buyhouse", cmdtext, true, 10) == 0)
{
GetHouseID(playerid);
format(file, sizeof(file), "House_%d.ini", HouseID);
x = dini_Float(file, "EnterX");
y = dini_Float(file, "EnterY");
z = dini_Float(file, "EnterZ");
forSale = dini_Get(file, "ForSale");
houseOwned = dini_Get(file, "Owned");
hValue = dini_Get(file, "Price");
if(HouseID == -1) return SendClientMessage(playerid, 0xFFFFFFFF, "ERROR: You are not at any house.");
if(strval(forSale) == 1 && strval(hValue) != INVALID_HOUSE_PRICE)
{
if(strval(houseOwned) == 1)
{
OwnerName = dini_Get(file, "Owner");
GetPlayerName(playerid, name, sizeof(name));
if(strcmp(name, OwnerName) == 0) return SendClientMessage(playerid, 0xFFFFFFFF, "ERROR: You may not buy your own houses");
if(GetPlayerMoney(playerid) >= strval(hValue))
{
GivePlayerMoney(playerid, GetPlayerMoney(playerid)-strval(hValue));
ConvertPlayerName();
GivePlayerMoney(OwnerID, -strval(hValue));
GetPlayerName(playerid, name, sizeof(name));
dini_Set(file, "Owner", name);
dini_IntSet(file, "Price", INVALID_HOUSE_PRICE);
dini_IntSet(file, "ForSale", 0);
dini_IntSet(file, "Pickupid", 1272);
DestroyPickup(housepickup[HouseID]);
housepickup[HouseID] = CreatePickup(1272, 1, x, y, z, 0);
dini_IntSet(file, "Owned", 1);
format(str, sizeof(str), "(Info): %s has bought your house number %d.", name, HouseID);
SendClientMessage(OwnerID, 0xFFFFFFFF, str);
format(stri, sizeof(stri), "(Info): You have successfuly bought house number %d.", HouseID);
SendClientMessage(playerid, 0xFFFFFFFF, stri);
}
else SendClientMessage(playerid, 0xFFFFFFFF, "ERROR: You do not have enough money to perform this command!");
}
else
{
if(GetPlayerMoney(playerid) >= strval(hValue))
{
GivePlayerMoney(playerid, -strval(hValue));
GetPlayerName(playerid, name, sizeof(name));
dini_Set(file, "Owner", name);
dini_IntSet(file, "Price", INVALID_HOUSE_PRICE);
dini_IntSet(file, "ForSale", 0);
dini_IntSet(file, "Pickupid", 1272);
DestroyPickup(housepickup[HouseID]);
housepickup[HouseID] = CreatePickup(1272, 1, x, y, z, 0);
dini_IntSet(file, "Owned", 1);
format(stri, sizeof(stri), "(Info): You have successfuly bought house number %d for %d$.", HouseID, strval(hValue)/100*95);
SendClientMessage(playerid, 0xFFFFFFFF, stri);
}
else SendClientMessage(playerid, 0xFFFFFFFF, "ERROR: You do not have enough money to perform this command!");
}
}
else SendClientMessage(playerid, 0xFFFFFFFF, "ERROR: This house is not for sale!");
return 1;
}
I used /createhouse and created 5 houses with the IDs of 1, 2, 3, 4 and 5.
I can use /buyhouse at 2 random houses, but when I go to the third it will either return "This house is not for sale" or "You are not at any house"
Any ideas?