CMD:buyhouse(playerid, params[])
{
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);
if(IsPlayerInRangeOfPoint(playerid,5.0, 0.0, 0.0, 0.0))
{// This is to prevent players from buying non-ready houses at the 0,0,0 coordinates
SendClientMessage(playerid, COLOR_WHITE, "You can't purchase houses in this area.");
return 1;
}
for(new h = 0; h < sizeof(HouseInfo); h++)
{
if(IsPlayerInRangeOfPoint(playerid,2.0,HouseInfo[h][hExteriorX], HouseInfo[h][hExteriorY], HouseInfo[h][hExteriorZ]))
{
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]);
SendClientMessage(playerid, COLOR_GRAD5, string);
return 1;
}
if(PlayerInfo[playerid][pHouse] != INVALID_HOUSE_ID)
{
SendClientMessage(playerid, COLOR_GRAD5, "You already own a house.");
return 1;
}
if(PlayerInfo[playerid][pHouse] == INVALID_HOUSE_ID)
{
if(GetPlayerCash(playerid) >= HouseInfo[h][hValue])
{
if(GetPVarInt(playerid, "BuyHouseConfirm") == 0)
{
SetPVarInt(playerid, "BuyHouseConfirm", 1);
SendClientMessage(playerid, COLOR_WHITE, "You're about to buy this house. The money can't be returned once you have bought this house.");
SendClientMessage(playerid, COLOR_WHITE, "If you're sure you want to buy this house, please re-type the command (/buyhouse).");
return 1;
}
DeletePVar(playerid, "BuyHouseConfirm");
PlayerInfo[playerid][pHouse] = h;
HouseInfo[h][hOwned] = 1;
HouseInfo[h][hRentable] = 0;
GetPlayerName(playerid, sendername, sizeof(sendername));
strmid(HouseInfo[h][hOwner], sendername, 0, strlen(sendername), 255);
GivePlayerCash(playerid,-HouseInfo[h][hValue]);
SetPlayerInterior(playerid,HouseInfo[h][hHInteriorWorld]);
if(HouseInfo[h][hCustomInterior] == 1)
{
TogglePlayerControllable(playerid, 0);
for(new o = 0; o < 6; o++)
{
TextDrawShowForPlayer(playerid, ObjectsLoadingTD[o]);
}
SetPVarInt(playerid, "LoadingObjects", 1);
SetTimerEx("SafeLoadObjects", 3000, 0, "d", playerid);
}
format(string, sizeof(string), "* %s has entered their house.", GetPlayerNameEx(playerid));
ProxDetector(25.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
SetPlayerPos(playerid,HouseInfo[h][hInteriorX],HouseInfo[h][hInteriorY],HouseInfo[h][hInteriorZ]);
SetPlayerFacingAngle(playerid,HouseInfo[h][hInteriorA]);
SetCameraBehindPlayer(playerid);
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];
SendClientMessage(playerid, COLOR_WHITE, "Congratulations on your new purchase!");
SendClientMessage(playerid, COLOR_WHITE, "Type /househelp to review the help section!");
SaveHouses();
PlayerInfo[playerid][pInt] = GetPlayerInterior(playerid);
PlayerInfo[playerid][pVW] = GetPlayerVirtualWorld(playerid);
GetPlayerIp(playerid, PlayerInfo[playerid][pIP], 32);
GetPlayerPos(playerid, PlayerInfo[playerid][pPos_x], PlayerInfo[playerid][pPos_y], PlayerInfo[playerid][pPos_z]);
GetPlayerFacingAngle(playerid, PlayerInfo[playerid][pPos_r]);
OnPlayerStatsUpdate(playerid);
PlayerInfo[playerid][pVW] = h+60000;
SetPlayerVirtualWorld(playerid, h+60000);
DestroyPickup(HouseInfo[h][hPickupID]);
HouseInfo[h][hPickupID] = CreatePickup(1273, 23, HouseInfo[h][hExteriorX], HouseInfo[h][hExteriorY], HouseInfo[h][hExteriorZ], -1);
format(string, sizeof(string), "House owner: %s\nLevel: %d\nID: %d",HouseInfo[h][hOwner],HouseInfo[h][hLevel],h);
UpdateDynamic3DTextLabelText(HouseInfo[h][hTextID], COLOR_HOUSEGREEN, string);
new ip[32];
GetPlayerIp(playerid,ip,sizeof(ip));
format(string,sizeof(string),"%s (IP: %s) has bought house ID %d for $%d.",GetPlayerNameEx(playerid),ip,h,HouseInfo[h][hValue]);
Log("logs/house.log", string);
return 1;
}
else
{
SendClientMessage(playerid, COLOR_WHITE, " You don't have the cash for that.");
return 1;
}
if(PlayerInfo[playerid][pHouse] != INVALID_HOUSE_ID && PlayerInfo[playerid][pVIP] <2)
{
SendClientMessage(playerid, COLOR_GRAD5, "You already own a house.");
return 1;
}
pawn Код:
a Level 2 VIP can own two houses |
pawn Код:
|