| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- #include <YSI_Coding\y_hooks>
- #define MAX_OWNED_HOUSES 3
- #define MAX_OWNED_BUSINESSES 2
- new Iterator:OwnedHouse[MAX_PLAYERS]<MAX_PROPERTIES>;
- new Iterator:OwnedBusiness[MAX_PLAYERS]<MAX_PROPERTIES>;
- hook OnGameModeInit()
- {
- Iter_Init(OwnedHouse);
- Iter_Init(OwnedBusiness);
- }
- hook OnPlayerDisconnect(playerid, reason)
- {
- Iter_Clear(OwnedHouse[playerid]);
- Iter_Clear(OwnedBusiness[playerid]);
- }
- hook OnPlayerFirstSpawn(playerid)
- {
- foreach(new i : Property)
- {
- if(Property_GetOwnerSQLID(i) == Character_GetSQLID(playerid))
- {
- if(Iter_Contains(House, i))
- {
- Iter_Add(OwnedHouse[playerid], i);
- }
- else if(Iter_Contains(Business, i))
- {
- Iter_Add(OwnedBusiness[playerid], i);
- }
- }
- }
- }
- hook OnPropertyDeleted(propertyid)
- {
- foreach(new i : Player)
- {
- if(Character_GetSQLID(i) == Property_GetOwnerSQLID(propertyid))
- {
- Iter_Remove(OwnedHouse[i], propertyid);
- Iter_Remove(OwnedBusiness[i], propertyid);
- }
- Iter_Clear(PropertyKey[i]);
- }
- new query[128];
- mysql_format(MySQL_GetHandle(), query, sizeof(query), "DELETE FROM character_keys WHERE type = %d AND subject_id = %d", KEY_PROPERTY, propertyid);
- mysql_tquery(MySQL_GetHandle(), query);
- }
- CMD:buyproperty(playerid, params[])
- {
- new propertyid = GetCurrentProperty(playerid);
- if(propertyid == INVALID_PROPERTY_ID)
- {
- propertyid = GetNearbyProperty(playerid);
- if(propertyid == INVALID_PROPERTY_ID) return SendErrorMessage(playerid, "You need to be at one of the properties to buy it.");
- }
- if(Iter_Contains(OwnedHouse[playerid], propertyid) || Iter_Contains(OwnedBusiness[playerid], propertyid)) return SendErrorMessage(playerid, "You are the owner of this property.");
- if(IsPropertyAnEntrance(propertyid)) return SendErrorMessage(playerid, "You can't buy this property.");
- if(Property_GetOwnerSQLID(propertyid) != 0) return SendErrorMessage(playerid, "This property is not for sale.");
- new price = Property_GetPrice(propertyid);
- if(Player_GetCash(playerid) < price) return SendErrorMessageF(playerid, "You don't have enough money to buy this property, you need $%s.", MoneyFormat(price));
- if(IsPropertyAHouse(propertyid))
- {
- if(Iter_Count(OwnedHouse[playerid]) >= MAX_OWNED_HOUSES) return SendErrorMessageF(playerid, "You can't own more than %d houses.", MAX_OWNED_HOUSES);
- Iter_Add(OwnedHouse[playerid], propertyid);
- SendInfoMessageF(playerid, "You just bought this house (ID %d) for $%s at %s.", propertyid, MoneyFormat(price), Property_GetAddress(propertyid));
- }
- else if(IsPropertyABusiness(propertyid))
- {
- if(Iter_Count(OwnedBusiness[playerid]) >= MAX_OWNED_BUSINESSES) return SendErrorMessageF(playerid, "You can't own more than %d businesses.", MAX_OWNED_BUSINESSES);
- Iter_Add(OwnedBusiness[playerid], propertyid);
- SendInfoMessageF(playerid, "You just bought this business (ID %d) for $%s at %s.", propertyid, MoneyFormat(price), Property_GetAddress(propertyid));
- }
- Key_Give(playerid, KEY_PROPERTY, propertyid);
- Player_GiveCash(playerid, -price, true);
- Property_SetOwnerSQLID(propertyid, Character_GetSQLID(playerid));
- return 1;
- }
- CMD:sellproperty(playerid, params[])
- {
- new propertyid = GetCurrentProperty(playerid);
- if(propertyid == INVALID_PROPERTY_ID)
- {
- propertyid = GetNearbyProperty(playerid);
- if(propertyid == INVALID_PROPERTY_ID) return SendErrorMessage(playerid, "You need to be at one of the properties to sell it.");
- }
- if(Property_GetOwnerSQLID(propertyid) != Character_GetSQLID(playerid)) return SendErrorMessage(playerid, "You are not the owner of this property.");
- Iter_Remove(OwnedHouse[playerid], propertyid);
- Iter_Remove(OwnedBusiness[playerid], propertyid);
- Key_Remove(playerid, KEY_PROPERTY, propertyid);
- new price = Property_GetPrice(propertyid) / 2;
- Player_GiveCash(playerid, price, true);
- Property_SetOwnerSQLID(propertyid, 0);
- SendInfoMessageF(playerid, "You just sold this property (ID %d) for half of the initial price: $%s.", propertyid, MoneyFormat(price));
- return 1;
- }
- stock bool:IsPlayerOwningProperty(playerid, propertyid)
- {
- if(Iter_Contains(OwnedHouse[playerid], propertyid) || Iter_Contains(OwnedBusiness[playerid], propertyid))
- {
- return true;
- }
- return false;
- }
|