CMD:buyhouse(playerid, params[])
{
if(IsPlayerInRangeOfPoint(playerid, 100.0, 1109.0, 1537.0, 5.0) && PlayerInfo[playerid][pAdmin] < 2) return SendClientMessage(playerid, COLOR_WHITE, "You cannot use this command in this area!");
new string[128];
new playername[MAX_PLAYER_NAME];
new sendername[MAX_PLAYER_NAME];
new Float:oldposx, Float:oldposy, Float:oldposz;
GetPlayerName(playerid, playername, sizeof(playername));
GetPlayerPos(playerid, oldposx, oldposy, oldposz);
for(new h = 0; h < sizeof(HouseInfo); h++)
{
if(IsPlayerInRangeOfPoint(playerid,2.0,HouseInfo[h][hExteriorX], HouseInfo[h][hExteriorY], HouseInfo[h][hExteriorZ]) )
{
if(PlayerInfo[playerid][pFreezeHouse] == 1)
{
return SendClientMessageEx(playerid, COLOR_WHITE, "ERROR: Your house assets are frozen, you cannot buy a house!");
}
if( HouseInfo[h][hOwned] == 0 )
{
if(PlayerInfo[playerid][pLevel] < HouseInfo[h][hLevel])
{
format(string, sizeof(string), " You must be Level %d to purchase this!", HouseInfo[h][hLevel]);
SendClientMessageEx(playerid, COLOR_GRAD5, string);
return 1;
}
if(PlayerInfo[playerid][pPhousekey] == INVALID_HOUSE_ID)
{
if(GetPlayerCash(playerid) > HouseInfo[h][hValue])
{
PlayerInfo[playerid][pPhousekey] = h;
HouseInfo[h][hOwned] = 1;
GetPlayerName(playerid, sendername, sizeof(sendername));
strmid(HouseInfo[h][hOwner], sendername, 0, strlen(sendername), 255);
GivePlayerCash(playerid,-HouseInfo[h][hValue]);
SetPlayerInterior(playerid,HouseInfo[h][hHInteriorWorld]);
SetPlayerPos(playerid,HouseInfo[h][hInteriorX],HouseInfo[h][hInteriorY],HouseInfo[h][hInteriorZ]);
GameTextForPlayer(playerid, "~w~Welcome Home~n~You can exit at any time by moving to this door and typing /exit.", 5000, 3);
PlayerInfo[playerid][pInt] = HouseInfo[h][hHInteriorWorld];
SendClientMessageEx(playerid, COLOR_WHITE, "Congratulations on your new purchase!");
SendClientMessageEx(playerid, COLOR_WHITE, "Type /help to review the property help section!");
SaveHouse(h);
OnPlayerStatsUpdate(playerid);
PlayerInfo[playerid][pVW] = h+6000;
SetPlayerVirtualWorld(playerid, h+6000);
DestroyDynamicPickup(HouseInfo[h][hPickupID]);
HouseInfo[h][hPickupID] = CreateDynamicPickup(1273, 23, HouseInfo[h][hExteriorX], HouseInfo[h][hExteriorY], HouseInfo[h][hExteriorZ]);
format(string, sizeof(string), "This house is owned by\n %s\nLevel: %d\nID: %d",HouseInfo[h][hOwner],HouseInfo[h][hLevel],h);
UpdateDynamic3DTextLabelText(HouseInfo[h][hTextID], COLOR_GREEN, string);
format(string,sizeof(string),"%s (IP: %s) has bought house ID %d for $%d.",GetPlayerNameEx(playerid),GetPlayerIpEx(playerid),h,HouseInfo[h][hValue]);
Log("logs/house.log", string);
if(HouseInfo[h][hCustomInterior] == 1) Player_StreamPrep(playerid, HouseInfo[h][hInteriorX],HouseInfo[h][hInteriorY],HouseInfo[h][hInteriorZ], FREEZE_TIME);
return 1;
}
else
{
SendClientMessageEx(playerid, COLOR_WHITE, " You don't have the cash for that!");
return 1;
}
}
else if(PlayerInfo[playerid][pPhousekey2] == INVALID_HOUSE_ID)
{
if(GetPlayerCash(playerid) > HouseInfo[h][hValue])
{
PlayerInfo[playerid][pPhousekey2] = h;
HouseInfo[h][hOwned] = 1;
GetPlayerName(playerid, sendername, sizeof(sendername));
strmid(HouseInfo[h][hOwner], sendername, 0, strlen(sendername), 255);
GivePlayerCash(playerid,-HouseInfo[h][hValue]);
SetPlayerInterior(playerid,HouseInfo[h][hHInteriorWorld]);
SetPlayerPos(playerid,HouseInfo[h][hInteriorX],HouseInfo[h][hInteriorY],HouseInfo[h][hInteriorZ]);
GameTextForPlayer(playerid, "~w~Welcome Home~n~You can exit at any time by moving to this door and typing /exit.", 5000, 3);
PlayerInfo[playerid][pInt] = HouseInfo[h][hHInteriorWorld];
SendClientMessageEx(playerid, COLOR_WHITE, "Congratulations on your new purchase!");
SendClientMessageEx(playerid, COLOR_WHITE, "Type /help to review the property help section!");
SaveHouse(h);
OnPlayerStatsUpdate(playerid);
PlayerInfo[playerid][pVW] = h+6000;
SetPlayerVirtualWorld(playerid, h+6000);
DestroyDynamicPickup(HouseInfo[h][hPickupID]);
HouseInfo[h][hPickupID] = CreateDynamicPickup(1273, 23, HouseInfo[h][hExteriorX], HouseInfo[h][hExteriorY], HouseInfo[h][hExteriorZ]);
format(string, sizeof(string), "This house is owned by\n %s\nLevel: %d\nID: %d",HouseInfo[h][hOwner],HouseInfo[h][hLevel],h);
UpdateDynamic3DTextLabelText(HouseInfo[h][hTextID], COLOR_GREEN, string);
format(string,sizeof(string),"%s (IP: %s) has bought house ID %d for $%d.",GetPlayerNameEx(playerid),GetPlayerIpEx(playerid),h,HouseInfo[h][hValue]);
Log("logs/house.log", string);
if(HouseInfo[h][hCustomInterior] == 1) Player_StreamPrep(playerid, HouseInfo[h][hInteriorX],HouseInfo[h][hInteriorY],HouseInfo[h][hInteriorZ], FREEZE_TIME);
return 1;
}
else
{
SendClientMessageEx(playerid, COLOR_WHITE, " You don't have the cash for that!");
return 1;
}
}
}
else
{
SendClientMessageEx( playerid, COLOR_WHITE, "This house is owned." );
}
}
}
return 1;
}
stock LoadHouse(houseid)
{
new string[128];
printf("[LoadHouse] Loading HouseID %d's data from database...", houseid);
format(string, sizeof(string), "SELECT * FROM `houses` WHERE `id`=%d",houseid+1); // Array starts at zero, MySQL starts at one.
mysql_function_query(MainPipeline, string, true, "OnLoadHouse", "i", houseid);
}
forward OnLoadHouse(index);
public OnLoadHouse(index)
{
new string[64];
new rows, fields;
cache_get_data(rows, fields, MainPipeline);
for(new field;field<fields;field++)
{
cache_get_row(index, field, string, MainPipeline);
switch(field)
{
case 0: HouseInfo[index][hSQLId] = strval(string);
case 1: HouseInfo[index][hOwned] = strval(string);
case 2: HouseInfo[index][hLevel] = strval(string);
case 3: HouseInfo[index][hHInteriorWorld] = strval(string);
case 4: format(HouseInfo[index][hDescription], 16, "%s", string);
case 5: format(HouseInfo[index][hOwner], 24, "%s", string);
case 6: HouseInfo[index][hExteriorX] = floatstr(string);
case 7: HouseInfo[index][hExteriorY] = floatstr(string);
case 8: HouseInfo[index][hExteriorZ] = floatstr(string);
case 9: HouseInfo[index][hExteriorR] = floatstr(string);
case 10: HouseInfo[index][hInteriorX] = floatstr(string);
case 11: HouseInfo[index][hInteriorY] = floatstr(string);
case 12: HouseInfo[index][hInteriorZ] = floatstr(string);
case 13: HouseInfo[index][hInteriorR] = floatstr(string);
case 14: HouseInfo[index][hLock] = strval(string);
case 15: HouseInfo[index][hRentable] = strval(string);
case 16: HouseInfo[index][hRentFee] = strval(string);
case 17: HouseInfo[index][hValue] = strval(string);
case 18: HouseInfo[index][hSafeMoney] = strval(string);
case 19: HouseInfo[index][hPot] = strval(string);
case 20: HouseInfo[index][hCrack] = strval(string);
case 21: HouseInfo[index][hMaterials] = strval(string);
case 22: HouseInfo[index][hWeapons][0] = strval(string);
case 23: HouseInfo[index][hWeapons][1] = strval(string);
case 24: HouseInfo[index][hWeapons][2] = strval(string);
case 25: HouseInfo[index][hWeapons][3] = strval(string);
case 26: HouseInfo[index][hWeapons][4] = strval(string);
case 27: HouseInfo[index][hGLUpgrade] = strval(string);
case 28: HouseInfo[index][hPickupID] = strval(string);
case 29: HouseInfo[index][hCustomInterior] = strval(string);
case 30: HouseInfo[index][hCustomExterior] = strval(string);
case 31: HouseInfo[index][hExteriorA] = floatstr(string);
case 32: HouseInfo[index][hInteriorA] = floatstr(string);
case 33: HouseInfo[index][hMailX] = floatstr(string);
case 34: HouseInfo[index][hMailY] = floatstr(string);
case 35: HouseInfo[index][hMailZ] = floatstr(string);
case 36: HouseInfo[index][hMailA] = floatstr(string);
}
}
if(HouseInfo[index][hOwned]) {
if(!HouseInfo[index][hRentable]) format(string, sizeof(string), "This house is owned by\n%s\nLevel: %d\nID: %d",HouseInfo[index][hOwner], HouseInfo[index][hLevel], index);
else format(string, sizeof(string), "This house is owned by\n%s\nRent: $%d\nLevel: %d\nID: %d\nType /rentroom to rent a room", HouseInfo[index][hOwner], HouseInfo[index][hRentFee], HouseInfo[index][hLevel], index);
}
else format(string, sizeof(string), "This house is\n for sale!\n Description: %s\nCost: $%d\n Level: %d\nID: %d\nTo buy this house type /buyhouse",HouseInfo[index][hDescription],HouseInfo[index][hValue],HouseInfo[index][hLevel],index);
HouseInfo[index][hPickupID] = CreateDynamicPickup(1273, 23, HouseInfo[index][hExteriorX], HouseInfo[index][hExteriorY], HouseInfo[index][hExteriorZ]);
HouseInfo[index][hTextID] = CreateDynamic3DTextLabel(string, COLOR_GREEN, HouseInfo[index][hExteriorX], HouseInfo[index][hExteriorY], HouseInfo[index][hExteriorZ]+0.5,10.0, .testlos = 1, .streamdistance = 10.0);
if(HouseInfo[index][hMailX] != 0.0) RenderHouseMailbox(index);
return 1;
}
stock LoadHouses()
{
printf("[LoadHouses] Loading data from database...");
mysql_function_query(MainPipeline, "SELECT * FROM `houses`", true, "OnLoadHouses", "");
}
forward OnLoadHouses();
public OnLoadHouses()
{
new string[512], iIndex;
new rows, fields;
cache_get_data(rows, fields, MainPipeline);
while(iIndex<rows)
{
for(new field;field<fields;field++)
{
cache_get_row(iIndex, field, string, MainPipeline);
switch(field)
{
case 0: HouseInfo[iIndex][hSQLId] = strval(string);
case 1: HouseInfo[iIndex][hOwned] = strval(string);
case 2: HouseInfo[iIndex][hLevel] = strval(string);
case 3: HouseInfo[iIndex][hHInteriorWorld] = strval(string);
case 4: format(HouseInfo[iIndex][hDescription], 16, "%s", string);
case 5: format(HouseInfo[iIndex][hOwner], 24, "%s", string);
case 6: HouseInfo[iIndex][hExteriorX] = floatstr(string);
case 7: HouseInfo[iIndex][hExteriorY] = floatstr(string);
case 8: HouseInfo[iIndex][hExteriorZ] = floatstr(string);
case 9: HouseInfo[iIndex][hExteriorR] = floatstr(string);
case 10: HouseInfo[iIndex][hInteriorX] = floatstr(string);
case 11: HouseInfo[iIndex][hInteriorY] = floatstr(string);
case 12: HouseInfo[iIndex][hInteriorZ] = floatstr(string);
case 13: HouseInfo[iIndex][hInteriorR] = floatstr(string);
case 14: HouseInfo[iIndex][hLock] = strval(string);
case 15: HouseInfo[iIndex][hRentable] = strval(string);
case 16: HouseInfo[iIndex][hRentFee] = strval(string);
case 17: HouseInfo[iIndex][hValue] = strval(string);
case 18: HouseInfo[iIndex][hSafeMoney] = strval(string);
case 19: HouseInfo[iIndex][hPot] = strval(string);
case 20: HouseInfo[iIndex][hCrack] = strval(string);
case 21: HouseInfo[iIndex][hMaterials] = strval(string);
case 22: HouseInfo[iIndex][hWeapons][0] = strval(string);
case 23: HouseInfo[iIndex][hWeapons][1] = strval(string);
case 24: HouseInfo[iIndex][hWeapons][2] = strval(string);
case 25: HouseInfo[iIndex][hWeapons][3] = strval(string);
case 26: HouseInfo[iIndex][hWeapons][4] = strval(string);
case 27: HouseInfo[iIndex][hGLUpgrade] = strval(string);
case 28: HouseInfo[iIndex][hPickupID] = strval(string);
case 29: HouseInfo[iIndex][hCustomInterior] = strval(string);
case 30: HouseInfo[iIndex][hCustomExterior] = strval(string);
case 31: HouseInfo[iIndex][hExteriorA] = floatstr(string);
case 32: HouseInfo[iIndex][hInteriorA] = floatstr(string);
case 33: HouseInfo[iIndex][hMailX] = floatstr(string);
case 34: HouseInfo[iIndex][hMailY] = floatstr(string);
case 35: HouseInfo[iIndex][hMailZ] = floatstr(string);
case 36: HouseInfo[iIndex][hMailA] = floatstr(string);
case 37: HouseInfo[iIndex][hMailType] = strval(string);
}
}
if(HouseInfo[iIndex][hOwned]) {
if(!HouseInfo[iIndex][hRentable]) format(string, sizeof(string), "This house is owned by\n%s\nLevel: %d\nID: %d",HouseInfo[iIndex][hOwner], HouseInfo[iIndex][hLevel], iIndex);
else format(string, sizeof(string), "This house is owned by\n%s\nRent: $%d\nLevel: %d\nID: %d\nType /rentroom to rent a room", HouseInfo[iIndex][hOwner], HouseInfo[iIndex][hRentFee], HouseInfo[iIndex][hLevel], iIndex);
}
else format(string, sizeof(string), "This house is\n for sale!\n Description: %s\nCost: $%d\n Level: %d\nID: %d\nTo buy this house type /buyhouse",HouseInfo[iIndex][hDescription],HouseInfo[iIndex][hValue],HouseInfo[iIndex][hLevel],iIndex);
HouseInfo[iIndex][hPickupID] = CreateDynamicPickup(1273, 23, HouseInfo[iIndex][hExteriorX], HouseInfo[iIndex][hExteriorY], HouseInfo[iIndex][hExteriorZ]);
HouseInfo[iIndex][hTextID] = CreateDynamic3DTextLabel(string, COLOR_GREEN, HouseInfo[iIndex][hExteriorX], HouseInfo[iIndex][hExteriorY], HouseInfo[iIndex][hExteriorZ]+0.5,10.0, .testlos = 1, .streamdistance = 10.0);
RenderHouseMailbox(iIndex);
iIndex++;
}
if(iIndex > 0) printf("[LoadHouses] %d houses rehashed/loaded.", iIndex);
else printf("[LoadHouses] Failed to load any houses.");
return 1;
}
|
Tell what doesnt work??You buy but it doesnt load it after restart??Or its not saved??
|