Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <zcmd>
- #include <a_mysql>
- #define TABLE_PROP "PROPERTIES"
- #define ID_PROP "ID"
- #define NAME_PROP "NAME"
- #define COST_PROP "PROP COMPRA"
- #define SELL_PROP "PROP Sell"
- #define VALOR_LUCRE_PROP "PROP LUCRE"
- #define LUCRE_PROP "LUCRE"
- #define OWNER_PROP "OWNER"
- #define POSX_PROP "POS X"
- #define POSY_PROP "POS Y"
- #define POSZ_PROP "POS Z"
- #define MAX_PROPS 100
- #define TEMPO_Lucre 1
- #define DEBUG_PROP true
- new
- MySQL_Connection;
- new
- pInfoPropName[MAX_PROPS][20],
- pInfoPropBuyPrice[MAX_PROPS],
- pInfoPropSellPrice[MAX_PROPS],
- pInfoPropLucre_[MAX_PROPS],
- pInfoPropLucre[MAX_PROPS],
- pInfoPropTimeLucre[MAX_PROPS],
- pInfoPropOwner[MAX_PROPS][MAX_PLAYER_NAME],
- Float:pInfoPropPosX[MAX_PROPS],
- Float:pInfoPropPosY[MAX_PROPS],
- Float:pInfoPropPosZ[MAX_PROPS],
- bool:pInfoPropIdCheck[MAX_PROPS];
- new
- pInfoPickupProp[MAX_PROPS],
- Text3D:pInfoLabelProp[MAX_PROPS];
- new
- Format_MySQL[600],
- Format_Label[150],
- GetPropLucre;
- public OnGameModeExit()
- {
- mysql_close(MySQL_Connection);
- #if defined Prop_OnGameModeExit
- return Prop_OnGameModeExit();
- #else
- return 1;
- #endif
- }
- #if defined _ALS_OnGameModeExit
- #undef OnGameModeExit
- #else
- #define _ALS_OnGameModeExit
- #endif
- #define OnGameModeExit Prop_OnGameModeExit
- #if defined Prop_OnGameModeExit
- forward Prop_OnGameModeExit();
- #endif
- stock mysql_prop_connect(const Server_Host[], const Server_User[], const Server_Database[], const Server_Password[])
- {
- MySQL_Connection = mysql_connect(Server_Host, Server_User, Server_Database, Server_Password);
- mysql_format(MySQL_Connection, Format_MySQL, sizeof Format_MySQL, " \
- CREATE TABLE IF NOT EXISTS `"TABLE_PROP"` ( \
- `"ID_PROP"` INT(5) PRIMARY KEY NOT NULL, \
- `"NAME_PROP"` VARCHAR(20) NOT NULL DEFAULT 'N/A', \
- `"COST_PROP"` INT(10) NOT NULL DEFAULT '0', \
- `"SELL_PROP"` INT(10) NOT NULL DEFAULT '0', \
- `"VALOR_LUCRE_PROP"` INT(10) NOT NULL DEFAULT '0', \
- `"LUCRE_PROP"` INT(10) NOT NULL DEFAULT '0', \
- `"OWNER_PROP"` VARCHAR(24) NOT NULL DEFAULT 'N/A', \
- `"POSX_PROP"` FLOAT NOT NULL DEFAULT '0.0', \
- `"POSY_PROP"` FLOAT NOT NULL DEFAULT '0.0', \
- `"POSZ_PROP"` FLOAT NOT NULL DEFAULT '0.0')");
- mysql_query(MySQL_Connection, Format_MySQL);
- #if DEBUG_PROP == true
- printf("\nCONNECTION MYSQL - TABLE: %s\n", TABLE_PROP);
- #endif
- LoadProps();
- return 1;
- }
- stock CreateProp(Name_Prop[], Price_Buy_Prop, Price_Sell_Prop, Lucre_Prop, Owner_Prop[], Float:PosX_Prop, Float:PosY_Prop, Float:PosZ_Prop)
- {
- new ID_Prop;
- for(new p = 0; p < MAX_PROPS; p ++)
- {
- if(pInfoPropIdCheck[p] == false)
- {
- pInfoPropIdCheck[p] = true;
- ID_Prop = p;
- break;
- }
- }
- if(strcmp("N/A", OWNER_PROP, true) == 0) format(Format_Label, sizeof Format_Label, "ID: %i\nName: %s\nOwner: %s\nPrice: R$ %i,00\nLucre: R$ %i,00", ID_Prop, Name_Prop, Owner_Prop, Price_Buy_Prop, Lucre_Prop);
- else format(Format_Label, sizeof Format_Label, "ID: %i\nName: %s\nOwner: %s\nLucre: R$ 0,00 (Generating)", ID_Prop, Name_Prop, Owner_Prop);
- pInfoPickupProp[ID_Prop] = CreatePickup(1210, 1, PosX_Prop, PosY_Prop, PosZ_Prop);
- pInfoLabelProp[ID_Prop] = Create3DTextLabel(Format_Label, -1, PosX_Prop, PosY_Prop, PosZ_Prop + 1, 50.0, 0, 1);
- mysql_format(MySQL_Connection, Format_MySQL, sizeof Format_MySQL, " \
- INSERT INTO `"TABLE_PROP"` ( \
- `"ID_PROP"`, \
- `"NAME_PROP"`, \
- `"COST_PROP"`, \
- `"SELL_PROP"`, \
- `"VALOR_LUCRE_PROP"`, \
- `"LUCRE_PROP"`, \
- `"OWNER_PROP"`, \
- `"POSX_PROP"`, \
- `"POSY_PROP"`, \
- `"POSZ_PROP"`) \
- VALUES ('%i', '%s', '%i', '%i', '%i', '0', '%s', '%f', '%f', '%f')", ID_Prop, Name_Prop, Price_Buy_Prop, Price_Sell_Prop, Lucre_Prop, Owner_Prop, PosX_Prop, PosY_Prop, PosZ_Prop);
- mysql_query(MySQL_Connection, Format_MySQL);
- strcat((pInfoPropName[ID_Prop][0] = '\0', pInfoPropName[ID_Prop]), Name_Prop);
- pInfoPropBuyPrice[ID_Prop] = Price_Buy_Prop;
- pInfoPropSellPrice[ID_Prop] = Price_Sell_Prop;
- pInfoPropLucre_[ID_Prop] = Lucre_Prop;
- pInfoPropLucre[ID_Prop] = 0;
- strcat((pInfoPropOwner[ID_Prop][0] = '\0', pInfoPropOwner[ID_Prop]), OWNER_PROP);
- pInfoPropPosX[ID_Prop] = PosX_Prop;
- pInfoPropPosY[ID_Prop] = PosY_Prop;
- pInfoPropPosZ[ID_Prop] = PosZ_Prop;
- pInfoPropIdCheck[ID_Prop] = true;
- #if DEBUG_PROP == true
- printf("CreateProp: ID: %i | Name: %s | Cost: R$ %i,00 | Sell: R$ %i,00 | Lucre: R$ %i,00 | Owner: %s", ID_Prop, NAME_PROP, Price_Buy_Prop, Price_SELL_PROP, LUCRE_PROP, OWNER_PROP);
- #endif
- return 1;
- }
- stock DeleteProp(ID_Prop)
- {
- if(pInfoPropIdCheck[ID_Prop] == false) return false;
- for(new p = 0; p < MAX_PROPS; p ++)
- {
- if(pInfoPropIdCheck[p] == false) continue;
- if(pInfoPropIdCheck[ID_Prop] == true)
- {
- Delete3DTextLabel(pInfoLabelProp[ID_Prop]);
- DestroyPickup(pInfoPickupProp[ID_Prop]);
- mysql_format(MySQL_Connection, Format_MySQL, sizeof Format_MySQL, "DELETE FROM `"TABLE_PROP"` WHERE `"ID_PROP"` = '%i'", ID_Prop);
- mysql_query(MySQL_Connection, Format_MySQL, false);
- pInfoPropName[ID_Prop][0] = '\0';
- pInfoPropBuyPrice[ID_Prop] = 0;
- pInfoPropSellPrice[ID_Prop] = 0;
- pInfoPropTimeLucre[ID_Prop] = 0;
- pInfoPropLucre_[ID_Prop] = 0;
- pInfoPropLucre[ID_Prop] = 0;
- pInfoPropOwner[ID_Prop][0] = '\0';
- pInfoPropPosX[ID_Prop] = 0;
- pInfoPropPosY[ID_Prop] = 0;
- pInfoPropPosZ[ID_Prop] = 0;
- pInfoPropIdCheck[ID_Prop] = false;
- break;
- }
- }
- #if DEBUG_PROP == true
- printf("DeleteProp: %i", ID_Prop);
- #endif
- return 1;
- }
- stock BuyProp(Owner_Prop[], ID_Prop)
- {
- if(pInfoPropIdCheck[ID_Prop] == false) return false;
- pInfoPropTimeLucre[ID_Prop] = TEMPO_Lucre * 60 + gettime();
- strcat((pInfoPropOwner[ID_Prop][0] = '\0', pInfoPropOwner[ID_Prop]), Owner_Prop);
- format(Format_Label, sizeof Format_Label, "ID: %i\nName: %s\nOwner: %s\nLucre: R$ %i,00 (Generating)", ID_Prop, pInfoPropName[ID_Prop], pInfoPropOwner[ID_Prop], pInfoPropLucre[ID_Prop]);
- Update3DTextLabelText(pInfoLabelProp[ID_Prop], -1, Format_Label);
- mysql_format(MySQL_Connection, Format_MySQL, sizeof Format_MySQL, "UPDATE `"TABLE_PROP"` SET `"OWNER_PROP"` = '%s' WHERE `"ID_PROP"` = '%i'", Owner_Prop, ID_Prop);
- mysql_query(MySQL_Connection, Format_MySQL);
- #if DEBUG_PROP == true
- printf("BuyProp: %s | Owner: %s", pInfoPropName[ID_Prop], Owner_Prop);
- #endif
- return 1;
- }
- stock SellProp(ID_Prop)
- {
- if(pInfoPropIdCheck[ID_Prop] == false) return false;
- pInfoPropOwner[ID_Prop] = "N/A";
- pInfoPropLucre[ID_Prop] = 0;
- mysql_format(MySQL_Connection, Format_MySQL, sizeof Format_MySQL, "UPDATE `"TABLE_PROP"` SET `"OWNER_PROP"` = 'N/A', `"LUCRE_PROP"` = '0' WHERE `"ID_PROP"` = '%i'", ID_Prop);
- mysql_query(MySQL_Connection, Format_MySQL, false);
- format(Format_Label, sizeof Format_Label, "ID: %i\nName: %s\nOwner: %s\nPrice: R$ %i,00\nLucre: R$ %i,00", ID_Prop, pInfoPropName[ID_Prop], pInfoPropOwner[ID_Prop], pInfoPropBuyPrice[ID_Prop], pInfoPropLucre_[ID_Prop]);
- Update3DTextLabelText(pInfoLabelProp[ID_Prop], -1, Format_Label);
- #if DEBUG_PROP == true
- printf("SellProp: %s", pInfoPropName[ID_Prop]);
- #endif
- return 1;
- }
- stock GetPropBuyVal(ID_Prop)
- {
- if(pInfoPropIdCheck[ID_Prop] == false) return false;
- #if DEBUG_PROP == true
- printf("GetPropBuyVal: R$ %i,00", pInfoPropBuyPrice[ID_Prop]);
- #endif
- return pInfoPropBuyPrice[ID_Prop];
- }
- stock GetPropSellVal(ID_Prop)
- {
- if(pInfoPropIdCheck[ID_Prop] == false) return false;
- #if DEBUG_PROP == true
- printf("GetPropSellVal: R$ %i,00", pInfoPropSellPrice[ID_Prop]);
- #endif
- return pInfoPropSellPrice[ID_Prop];
- }
- stock GetPropLucreVal(ID_Prop)
- {
- if(pInfoPropIdCheck[ID_Prop] == false) return false;
- GetPropLucre = EOS;
- GetPropLucre = pInfoPropLucre[ID_Prop];
- pInfoPropLucre[ID_Prop] = 0;
- format(Format_Label, sizeof Format_Label, "ID: %i\nName: %s\nOwner: %s\nLucre: R$ %i,00 (Generating)", ID_Prop, pInfoPropName[ID_Prop], pInfoPropOwner[ID_Prop], pInfoPropLucre[ID_Prop]);
- Update3DTextLabelText(pInfoLabelProp[ID_Prop], -1, Format_Label);
- mysql_format(MySQL_Connection, Format_MySQL, sizeof Format_MySQL, "UPDATE `"TABLE_PROP"` SET `"LUCRE_PROP"` = '0' WHERE `"ID_PROP"` = '%i'", ID_Prop);
- mysql_query(MySQL_Connection, Format_MySQL, false);
- #if DEBUG_PROP == true
- printf("GetPropLucreVal: R$ %i,00", pInfoPropLucre[ID_Prop]);
- #endif
- return GetPropLucre;
- }
- stock GetPlayerProps(playerid, Owner_Prop[])
- {
- new String[128];
- for(new p = 0; p < MAX_PROPS; p ++)
- {
- if(pInfoPropIdCheck[p] == false) continue;
- if(strcmp(pInfoPropOwner[p], Owner_Prop, false) == 0)
- {
- format(String, sizeof String, "Owner: %s | Property: %s - ID: %i", pInfoPropOwner[p], pInfoPropName[p], p);
- SendClientMessage(playerid, -1, String);
- }
- }
- #if DEBUG_PROP == true
- printf("GetPlayerProps: %s", Owner_Prop);
- #endif
- return 1;
- }
- stock LoadProps()
- {
- new GetID;
- mysql_format(MySQL_Connection, Format_MySQL, sizeof Format_MySQL, "SELECT * FROM `"TABLE_PROP"`");
- mysql_query(MySQL_Connection, Format_MySQL);
- if(cache_num_rows())
- {
- printf("\n____________________________PROPERTIES_SYS_BY_F1N4L____________________________");
- for(new p = 0; p < cache_num_rows(); p ++)
- {
- GetID = cache_get_field_content_int(p, ID_PROP);
- cache_get_field_content(p, NAME_PROP, pInfoPropName[GetID]);
- cache_get_field_content(p, OWNER_PROP, pInfoPropOwner[GetID]);
- pInfoPropBuyPrice[GetID] = cache_get_field_content_int(p, COST_PROP);
- pInfoPropSellPrice[GetID] = cache_get_field_content_int(p, SELL_PROP);
- pInfoPropLucre_[GetID] = cache_get_field_content_int(p, VALOR_LUCRE_PROP);
- pInfoPropLucre[GetID] = cache_get_field_content_int(p, LUCRE_PROP);
- pInfoPropPosX[GetID] = cache_get_field_content_float(p, POSX_PROP);
- pInfoPropPosY[GetID] = cache_get_field_content_float(p, POSY_PROP);
- pInfoPropPosZ[GetID] = cache_get_field_content_float(p, POSZ_PROP);
- pInfoPropIdCheck[GetID] = true;
- pInfoPropTimeLucre[GetID] = TEMPO_Lucre * 60 + gettime();
- if(strcmp("N/A", pInfoPropOwner[GetID], true) == 0) format(Format_Label, sizeof Format_Label, "ID: %i\nName: %s\nOwner: %s\nPrice: R$ %i,00\nLucre: R$ %i,00", GetID, pInfoPropName[GetID], pInfoPropOwner[GetID], pInfoPropBuyPrice[GetID], pInfoPropLucre_[GetID]);
- else format(Format_Label, sizeof Format_Label, "ID: %i\nName: %s\nOwner: %s\nLucre: R$ %i,00", GetID, pInfoPropName[GetID], pInfoPropOwner[GetID], pInfoPropLucre[GetID]);
- pInfoPickupProp[GetID] = CreatePickup(1210, 1, pInfoPropPosX[GetID], pInfoPropPosY[GetID], pInfoPropPosZ[GetID]);
- pInfoLabelProp[GetID] = Create3DTextLabel(Format_Label, -1, pInfoPropPosX[GetID], pInfoPropPosY[GetID], pInfoPropPosZ[GetID] + 1, 50.0, 0, 1);
- #if DEBUG_PROP == true
- printf("ID: %i | Name: %s | Owner: %s | Cost: %i | Sell: %i | Lucre: %i", GetID, pInfoPropName[GetID], pInfoPropOwner[GetID], pInfoPropBuyPrice[GetID], pInfoPropSellPrice[GetID], pInfoPropLucre[GetID]);
- #endif
- }
- SetTimer("LucreProp", 1000, true);
- #if DEBUG_PROP == true
- printf("\n%i Properties loaded.\n_____________________________________________________________________________\n", cache_num_rows());
- #endif
- }
- return 1;
- }
- stock bool:IsPlayerInRangeOfProp(playerid, ID_Prop)
- {
- if(pInfoPropIdCheck[ID_Prop] == false) return false;
- new bool:InRange;
- if(IsPlayerInRangeOfPoint(playerid, 5.0, pInfoPropPosX[ID_Prop], pInfoPropPosY[ID_Prop], pInfoPropPosZ[ID_Prop])) InRange = true;
- else InRange = false;
- #if DEBUG_PROP == true
- printf("IsPlayerInRangeOfProp: %s | Playerid: %i | Near: %i", pInfoPropName[ID_Prop], playerid, InRange);
- #endif
- return InRange;
- }
- stock bool:IsEmptyProp(ID_Prop)
- {
- if(pInfoPropIdCheck[ID_Prop] == false) return false;
- new bool:CheckOwner;
- if(strcmp("N/A", pInfoPropOwner[ID_Prop], false) == 0) CheckOwner = true;
- else CheckOwner = false;
- #if DEBUG_PROP == true
- printf("CheckOwnerProp: %s | Exists: %i", pInfoPropName[ID_Prop], CheckOwner);
- #endif
- return CheckOwner;
- }
- stock bool:IsPlayerOwnerProp(Owner_Prop[], ID_Prop)
- {
- if(pInfoPropIdCheck[ID_Prop] == false) return false;
- new bool:PlayerIsOwner;
- if(strcmp(Owner_Prop, pInfoPropOwner[ID_Prop], false) == 0) PlayerIsOwner = true;
- else PlayerIsOwner = false;
- #if DEBUG_PROP == true
- printf("PlayerIsOwnerProp: %s | Owner: %s | is Owner: %i", pInfoPropName[ID_Prop], Owner_Prop, PlayerIsOwner);
- #endif
- return PlayerIsOwner;
- }
- stock bool:PropIdExists(ID_Prop)
- {
- new bool:PropExists;
- for(new p = 0; p < MAX_PROPS; p ++)
- {
- if(pInfoPropIdCheck[p] == false) continue;
- if(pInfoPropIdCheck[ID_Prop] == true)
- {
- PropExists = true;
- break;
- }
- else PropExists = false;
- }
- #if DEBUG_PROP == true
- printf("PropExists: %s | Exists: %i", pInfoPropName[ID_Prop], PropExists);
- #endif
- return PropExists;
- }
- stock bool:PropNameExists(Name_Prop[])
- {
- new bool:PropExists;
- for(new p = 0; p < MAX_PROPS; p ++)
- {
- if(pInfoPropIdCheck[p] == false) continue;
- if(strcmp(Name_Prop, pInfoPropName[p], true) == 0)
- {
- PropExists = true;
- break;
- }
- else PropExists = false;
- }
- #if DEBUG_PROP == true
- printf("PropNameExists: %s | Exists: %i", NAME_PROP, PropExists);
- #endif
- return PropExists;
- }
- forward LucreProp();
- public LucreProp()
- {
- for(new p = 0; p < MAX_PROPS; p ++)
- {
- if(pInfoPropIdCheck[p] == false) continue;
- if(strcmp("N/A", pInfoPropOwner[p], true) == 0) continue;
- if(pInfoPropTimeLucre[p] < gettime())
- {
- pInfoPropTimeLucre[p] = TEMPO_Lucre * 60 + gettime();
- pInfoPropLucre[p] += pInfoPropLucre_[p];
- format(Format_Label, sizeof Format_Label, "ID: %i\nName: %s\nOwner: %s\nLucre: R$ %i,00", p, pInfoPropName[p], pInfoPropOwner[p], pInfoPropLucre[p]);
- Update3DTextLabelText(pInfoLabelProp[p], -1, Format_Label);
- mysql_format(MySQL_Connection, Format_MySQL, sizeof Format_MySQL, "UPDATE `"TABLE_PROP"` SET `"LUCRE_PROP"` = '%i' WHERE `"ID_PROP"` = '%i'", pInfoPropLucre[p], p);
- mysql_query(MySQL_Connection, Format_MySQL, false);
- }
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment