03.02.2017, 16:56
Hello, so I'm using Y_INI to save and load player/houses/business/etc data.
Recently I "finished" /buyhouse command but players can only buy an already owned house only if the owner of that house if offline.
Is there anyway to let players buy an owned house if the owner of that house is offline?
I'm mostly looking for a way to increase offline owner's cash and set House ID of player's to 0
I tried loading the data with
and increasing player's money with
Here's the full command:
Recently I "finished" /buyhouse command but players can only buy an already owned house only if the owner of that house if offline.
Is there anyway to let players buy an owned house if the owner of that house is offline?
I'm mostly looking for a way to increase offline owner's cash and set House ID of player's to 0
I tried loading the data with
pawn Код:
INI_Int("OnHandMoney", omoney);
pawn Код:
INI_WriteInt(File, "OnHandMoney", omoney + HouseInfo[h][hPrice]);
pawn Код:
CMD:buyhouse(playerid, params[])
{
new string[256],
astring[256],
error[128],
pmoney,
name[MAX_PLAYER_NAME],
Float:pos[3];
pmoney = GetPVarInt(playerid, "money");
GetPlayerName(playerid, name, sizeof(name));
for(new h = 1; h < sizeof(HouseInfo); h++)
{
if(PlayerVar[playerid][HouseID] != 0) return SCM(playerid, COL_ADMIN, "Warning! {FFFFFF}You already own a house!");
pos[0] = HouseInfo[h][hEntranceX];
pos[1] = HouseInfo[h][hEntranceY];
pos[2] = HouseInfo[h][hEntranceZ];
if(IsPlayerInRangeOfPoint(playerid, 5.0, pos[0], pos[1], pos[2])) {
if(HouseInfo[h][hOwned] == 1 && HouseInfo[h][hPrice] != 0) {
for(new i = 0; i < MAX_PLAYERS; i++)
{
new oname[MAX_PLAYER_NAME];
GetPlayerName(i, oname, sizeof(oname));
if(strcmp(oname, HouseInfo[h][hOwner], true) == 0)
{
new pmessage[256];
PlayerVar[i][HouseID] = 0;
new omoney = GetPVarInt(i, "money");
SetPVarInt(i, "money", omoney + HouseInfo[h][hPrice]);
format(pmessage, sizeof(pmessage), "House System: {FFFFFF}Player {FF2400}%s {FFFFFF}has purchased your house for {FF2400}%d${FFFFFF}!", name, HouseInfo[h][hPrice]);
SCM(i, COL_ADMIN, pmessage);
} else {
new path[64];
format(path, sizeof(path), "PlayerAccounts/%s.ini", HouseInfo[h][hOwner]);
if(fexist(path)){
new omoney;
new INI:File = INI_Open(path);
INI_Int("OnHandMoney", omoney);
INI_WriteInt(File, "OnHandMoney", omoney + HouseInfo[h][hPrice]);
INI_WriteInt(File, "HouseID", 0);
INI_Close(File);
}
}
}
}
else if(HouseInfo[h][hOwned] == 1 && HouseInfo[h][hPrice] == 0) return SCM(playerid, COL_ADMIN, "Warning! {FFFFFF}This house is already owned!");
format(error, sizeof(error), "Warning! {FFFFFF}You need {FF2400}%d$ {FFFFFF}more to buy this house!", HouseInfo[h][hPrice]-pmoney);
if(pmoney < HouseInfo[h][hPrice]) return SCM(playerid, COL_ADMIN, error);
SetPVarInt(playerid, "money", pmoney-HouseInfo[h][hPrice]);
format(string, sizeof(string), "Congratulations! {FFFFFF}You have purchased the house with {FF2400}ID %d {FFFFFF}for {FF2400}%d${FFFFFF}!", h, HouseInfo[h][hPrice]);
SCM(playerid, COL_ADMIN, string);
format(astring, sizeof(astring), "House System: {FFFFFF}Player {FF2400}%s {FFFFFF}has purchased the house with {FF2400}ID %d {FFFFFF}for {FF2400}%d$", name, h, HouseInfo[h][hPrice]);
SendToAdmins(astring, COL_ADMIN);
PlayerVar[playerid][HouseID] = h;
HouseInfo[h][hOwned] = 1;
HouseInfo[h][hOwner] = name;
HouseInfo[h][hLocked] = 0;
HouseInfo[h][hPrice] = 0;
UpdateHouse(h);
break;
}
}
return 1;
}