Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define TABLE_PROP "PROPRIEDADES"
- #define ID_PROP "ID"
- #define NOME_PROP "NOME"
- #define CUSTO_PROP "PROP COMPRA"
- #define VENDA_PROP "PROP VENDA"
- #define VALOR_LUCRO_PROP "PROP LUCRO"
- #define LUCRO_PROP "LUCRO"
- #define DONO_PROP "DONO"
- #define POSX_PROP "POS X"
- #define POSY_PROP "POS Y"
- #define POSZ_PROP "POS Z"
- #define MAX_PROPS 100
- #define TEMPO_LUCRO 1
- #define DEBUG_PROP true
- new
- MySQL_Connection;
- new
- pInfoPropName[MAX_PROPS][20],
- pInfoPropCusto[MAX_PROPS],
- pInfoPropVenda[MAX_PROPS],
- pInfoPropLucro_[MAX_PROPS],
- pInfoPropLucro[MAX_PROPS],
- pInfoPropTempoLucro[MAX_PROPS],
- pInfoPropDono[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],
- GetPropLucro;
- 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, \
- `"NOME_PROP"` VARCHAR(20) NOT NULL DEFAULT 'N/A', \
- `"CUSTO_PROP"` INT(10) NOT NULL DEFAULT '0', \
- `"VENDA_PROP"` INT(10) NOT NULL DEFAULT '0', \
- `"VALOR_LUCRO_PROP"` INT(10) NOT NULL DEFAULT '0', \
- `"LUCRO_PROP"` INT(10) NOT NULL DEFAULT '0', \
- `"DONO_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("\nCONEXÃO 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\nNome: %s\nDono: %s\nPreço: R$ %i,00\nLucro: R$ %i,00", ID_Prop, Name_Prop, Owner_Prop, Price_Buy_Prop, Lucre_Prop);
- else format(Format_Label, sizeof Format_Label, "ID: %i\nNome: %s\nDono: %s\nLucro: R$ 0,00 (Gerando)", 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"`, \
- `"NOME_PROP"`, \
- `"CUSTO_PROP"`, \
- `"VENDA_PROP"`, \
- `"VALOR_LUCRO_PROP"`, \
- `"LUCRO_PROP"`, \
- `"DONO_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);
- pInfoPropCusto[ID_Prop] = Price_Buy_Prop;
- pInfoPropVenda[ID_Prop] = Price_Sell_Prop;
- pInfoPropLucro_[ID_Prop] = Lucre_Prop;
- pInfoPropLucro[ID_Prop] = 0;
- strcat((pInfoPropDono[ID_Prop][0] = '\0', pInfoPropDono[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 | Nome: %s | Custo: R$ %i,00 | Venda: R$ %i,00 | Lucro: 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';
- pInfoPropCusto[ID_Prop] = 0;
- pInfoPropVenda[ID_Prop] = 0;
- pInfoPropTempoLucro[ID_Prop] = 0;
- pInfoPropLucro_[ID_Prop] = 0;
- pInfoPropLucro[ID_Prop] = 0;
- pInfoPropDono[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;
- pInfoPropTempoLucro[ID_Prop] = TEMPO_LUCRO * 60 + gettime();
- strcat((pInfoPropDono[ID_Prop][0] = '\0', pInfoPropDono[ID_Prop]), Owner_Prop);
- format(Format_Label, sizeof Format_Label, "ID: %i\nNome: %s\nDono: %s\nLucro: R$ %i,00 (Gerando)", ID_Prop, pInfoPropName[ID_Prop], pInfoPropDono[ID_Prop], pInfoPropLucro[ID_Prop]);
- Update3DTextLabelText(pInfoLabelProp[ID_Prop], -1, Format_Label);
- mysql_format(MySQL_Connection, Format_MySQL, sizeof Format_MySQL, "UPDATE `"TABLE_PROP"` SET `"DONO_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;
- pInfoPropDono[ID_Prop] = "N/A";
- pInfoPropLucro[ID_Prop] = 0;
- mysql_format(MySQL_Connection, Format_MySQL, sizeof Format_MySQL, "UPDATE `"TABLE_PROP"` SET `"DONO_PROP"` = 'N/A', `"LUCRO_PROP"` = '0' WHERE `"ID_PROP"` = '%i'", ID_Prop);
- mysql_query(MySQL_Connection, Format_MySQL, false);
- format(Format_Label, sizeof Format_Label, "ID: %i\nNome: %s\nDono: %s\nPreço: R$ %i,00\nLucro: R$ %i,00", ID_Prop, pInfoPropName[ID_Prop], pInfoPropDono[ID_Prop], pInfoPropCusto[ID_Prop], pInfoPropLucro_[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", pInfoPropCusto[ID_Prop]);
- #endif
- return pInfoPropCusto[ID_Prop];
- }
- stock GetPropSellVal(ID_Prop)
- {
- if(pInfoPropIdCheck[ID_Prop] == false) return false;
- #if DEBUG_PROP == true
- printf("GetPropSellVal: R$ %i,00", pInfoPropVenda[ID_Prop]);
- #endif
- return pInfoPropVenda[ID_Prop];
- }
- stock GetPropLucreVal(ID_Prop)
- {
- if(pInfoPropIdCheck[ID_Prop] == false) return false;
- GetPropLucro = EOS;
- GetPropLucro = pInfoPropLucro[ID_Prop];
- pInfoPropLucro[ID_Prop] = 0;
- format(Format_Label, sizeof Format_Label, "ID: %i\nNome: %s\nDono: %s\nLucro: R$ %i,00 (Gerando)", ID_Prop, pInfoPropName[ID_Prop], pInfoPropDono[ID_Prop], pInfoPropLucro[ID_Prop]);
- Update3DTextLabelText(pInfoLabelProp[ID_Prop], -1, Format_Label);
- mysql_format(MySQL_Connection, Format_MySQL, sizeof Format_MySQL, "UPDATE `"TABLE_PROP"` SET `"LUCRO_PROP"` = '0' WHERE `"ID_PROP"` = '%i'", ID_Prop);
- mysql_query(MySQL_Connection, Format_MySQL, false);
- #if DEBUG_PROP == true
- printf("GetPropLucreVal: R$ %i,00", pInfoPropLucro[ID_Prop]);
- #endif
- return GetPropLucro;
- }
- stock GetPlayerProps(playerid, Owner_Prop[])
- {
- new String[128];
- for(new p = 0; p < MAX_PROPS; p ++)
- {
- if(pInfoPropIdCheck[p] == false) continue;
- if(strcmp(pInfoPropDono[p], Owner_Prop, false) == 0)
- {
- format(String, sizeof String, "Dono: %s | Propriedade: %s - ID: %i", pInfoPropDono[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____________________________PROPERTY_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, NOME_PROP, pInfoPropName[GetID]);
- cache_get_field_content(p, DONO_PROP, pInfoPropDono[GetID]);
- pInfoPropCusto[GetID] = cache_get_field_content_int(p, CUSTO_PROP);
- pInfoPropVenda[GetID] = cache_get_field_content_int(p, VENDA_PROP);
- pInfoPropLucro_[GetID] = cache_get_field_content_int(p, VALOR_LUCRO_PROP);
- pInfoPropLucro[GetID] = cache_get_field_content_int(p, LUCRO_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;
- pInfoPropTempoLucro[GetID] = TEMPO_LUCRO * 60 + gettime();
- if(strcmp("N/A", pInfoPropDono[GetID], true) == 0) format(Format_Label, sizeof Format_Label, "ID: %i\nNome: %s\nDono: %s\nPreço: R$ %i,00\nLucro: R$ %i,00", GetID, pInfoPropName[GetID], pInfoPropDono[GetID], pInfoPropCusto[GetID], pInfoPropLucro_[GetID]);
- else format(Format_Label, sizeof Format_Label, "ID: %i\nNome: %s\nDono: %s\nLucro: R$ %i,00", GetID, pInfoPropName[GetID], pInfoPropDono[GetID], pInfoPropLucro[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 | Nome: %s | Dono: %s | Custo: %i | Venda: %i | Lucro: %i", GetID, pInfoPropName[GetID], pInfoPropDono[GetID], pInfoPropCusto[GetID], pInfoPropVenda[GetID], pInfoPropLucro[GetID]);
- #endif
- }
- SetTimer("LucroProp", 1000, true);
- #if DEBUG_PROP == true
- printf("\n%i propriedades carregadas.\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 | Perto: %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", pInfoPropDono[ID_Prop], false) == 0) CheckOwner = true;
- else CheckOwner = false;
- #if DEBUG_PROP == true
- printf("CheckOwnerProp: %s | Existe: %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, pInfoPropDono[ID_Prop], false) == 0) PlayerIsOwner = true;
- else PlayerIsOwner = false;
- #if DEBUG_PROP == true
- printf("PlayerIsOwnerProp: %s | Owner: %s | É Owner: %i", pInfoPropName[ID_Prop], Owner_Prop, PlayerIsOwner);
- #endif
- return PlayerIsOwner;
- }
- stock bool:PropIdExists(ID_Prop)
- {
- new bool:PropExiste;
- for(new p = 0; p < MAX_PROPS; p ++)
- {
- if(pInfoPropIdCheck[p] == false) continue;
- if(pInfoPropIdCheck[ID_Prop] == true)
- {
- PropExiste = true;
- break;
- }
- else PropExiste = false;
- }
- #if DEBUG_PROP == true
- printf("PropExists: %s | Existe: %i", pInfoPropName[ID_Prop], PropExiste);
- #endif
- return PropExiste;
- }
- stock bool:PropNameExists(Name_Prop[])
- {
- new bool:PropExiste;
- for(new p = 0; p < MAX_PROPS; p ++)
- {
- if(pInfoPropIdCheck[p] == false) continue;
- if(strcmp(Name_Prop, pInfoPropName[p], true) == 0)
- {
- PropExiste = true;
- break;
- }
- else PropExiste = false;
- }
- #if DEBUG_PROP == true
- printf("PropNameExists: %s | Existe: %i", Name_Prop, PropExiste);
- #endif
- return PropExiste;
- }
- forward LucroProp();
- public LucroProp()
- {
- for(new p = 0; p < MAX_PROPS; p ++)
- {
- if(pInfoPropIdCheck[p] == false) continue;
- if(strcmp("N/A", pInfoPropDono[p], true) == 0) continue;
- if(pInfoPropTempoLucro[p] < gettime())
- {
- pInfoPropTempoLucro[p] = TEMPO_LUCRO * 60 + gettime();
- pInfoPropLucro[p] += pInfoPropLucro_[p];
- format(Format_Label, sizeof Format_Label, "ID: %i\nNome: %s\nDono: %s\nLucro: R$ %i,00", p, pInfoPropName[p], pInfoPropDono[p], pInfoPropLucro[p]);
- Update3DTextLabelText(pInfoLabelProp[p], -1, Format_Label);
- mysql_format(MySQL_Connection, Format_MySQL, sizeof Format_MySQL, "UPDATE `"TABLE_PROP"` SET `"LUCRO_PROP"` = '%i' WHERE `"ID_PROP"` = '%i'", pInfoPropLucro[p], p);
- mysql_query(MySQL_Connection, Format_MySQL, false);
- }
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement