[Include] Properties System [MySQL]
#1

Properties System v1.5 (FINAL VERSION) [MySQL R39-4]
* Simple use;
* Lucre generator

* DEBUG On/Off:
Код:
#define DEBUG_PROP true
* MAX PROPERTIES:
Код:
#define MAX_PROPS 100
* TIME FOR LUCRE GENERATE (MINUTES):
Код:
#define TIME_LUCRE 10
* Functions:
* Makes connection with database.
* Parameters: Host, User, Database, Password.
* Must be introduced into: OnGameModeInit or OnFilterScriptInit or main
* Return: 1.
Код:
mysql_prop_connect(const Server_Host[], const Server_User[], const Server_Database[], const Server_Password[])
* Create a property.
* Parameters: Property Name, Purchase Price, Sell Price, Lucre generated, Owner Name Property, Position X, Position Y, Position Z.
* Return: 1.
Код:
CreateProp(Name_Prop[], Price_Buy_Prop, Price_Sell_Prop, Lucre_Prop, Owner_Prop[], Float:PosX_Prop, Float:PosY_Prop, Float:PosZ_Prop)
* Delete a property.
* Parameters: Property ID.
* Return: 1.
Код:
DeleteProp(ID_Prop)
* Buy a property.
* Parameters: Owner Name Property, Property ID.
* Return: 1 if Property exists | 0 if Property not exists.
Код:
BuyProp(Owner_Prop[], ID_Prop)
* Sell a Property.
* Parameters: Property ID.
* Return: 1 if Property exists | 0 if Property not exists.
Код:
SellProp(ID_Prop)
* Get the Purchase Price of Property.
* Parameters: Property ID.
* Return: Purchase Price of Property.
Код:
GetPropBuyVal(ID_Prop)
* Get the Sell price of a property.
* Parameters: Property ID.
* Return: Sale price of Property.
Код:
GetPropSellVal(ID_Prop)
* Get the lucre of a Property.
* Parameters: Property ID.
* Return: Lucre of Property.
Код:
GetPropLucreVal(ID_Prop)
* Get all properties of a determined player.
* Parameters: Player ID that performed the function, Owner name.
* Return: 1 (The properties are shown in playerid screen that performed the function).
Код:
GetPlayerProps(playerid, Owner_Prop[])
* Check whether the player is near of the Property.
* Parameters: Player ID, Property ID.
* Return: true = Player is near to the property | false = Player is far from the property.
Код:
bool:IsPlayerInRangeOfProp(playerid, ID_Prop)
* Check whether the player is the Owner of Certain Property.
* Parameters: Owner Name Property, Property ID.
* Return: true = Player is owner the property | false = Player is not the owner of the property.
Код:
bool:IsPlayerOwnerProp(Owner_Prop[], ID_Prop)
* Checks if a property exists (By name).
* Parameters: Property Name.
* Return: true = Property exists | false = Property does not exist.
Код:
bool:PropNameExists(Name_Prop[])
* Checks if a property exists (By ID).
* Parameters: Property ID.
* Return: true = Property exists | false = Property does not exist.
Код:
bool:PropIdExists(ID_Prop)
* Checks whether the property has an Owner or not.
* Parameters: Property ID.
* Return: true = Have owner | false = Not have owner.
Код:
bool:IsEmptyProp(ID_Prop)
* Loads the properties.
* Parameters: None.
* Return: 1;
Код:
LoadProps()
* Commands:
Код:
CMD:pcreate(playerid, params[])
{
	new PropNome [20] PropBuyPrice, PropSellPrice, PropLucre, PropOwner[MAX_PLAYER_NAME] Float: PosX_Prop, Float: PosY_Prop, Float: PosZ_Prop;

	if(sscanf(params, "iiis[24]s[20]," PropBuyPrice, PropSellPrice, PropLucre, PropOwner, PropNome)) return SendClientMessage(playerid, -1, "/ PCRIAR [&COST] [&SALE] [&LUCRE] [&OWNER(DEFAULT: 'N/A')] [&NAME] ");

	if(PropNameExists(PropNome) == true) return SendClientMessage(playerid, -1, "The name of this property already exists.");

	if(PropBuyPrice < 100 || PropBuyPrice > 99999999) return SendClientMessage(playerid, -1, "The cost of property must be between 100-99999999");
	if(PropSellPrice < 100 || PropSellPrice > PropBuyPrice) return SendClientMessage(playerid, -1, "The sales value of the property must be at least 100 and can not pass the cost value.");

	GetPlayerPos(playerid, PosX_Prop, PosY_Prop, PosZ_Prop);

	CreateProp(PropNome, PropBuyPrice, PropSellPrice, PropLucre, PropOwner, PosX_Prop, PosY_Prop, PosZ_Prop);

	return 1;
}

CMD:pdelete(playerid, params[])
{
	if(isnull(params)) return SendClientMessage(playerid, -1, "/PDELETE [&ID]");

	if(PropIdExists(strval(params)) == false) return SendClientMessage(playerid, -1, "This property does not exist!");

	DeleteProp(strval(params));
	SendClientMessage(playerid, -1, "Excluded property successfully!");

	return 1;
}

CMD:pbuy(playerid, params[])
{
	new Name[MAX_PLAYER_NAME];

	if(isnull(params)) return SendClientMessage(playerid, -1, "/PBUY [&ID]");

	if(PropIdExists(strval(params)) == false) return SendClientMessage(playerid, -1, "This property does not exist!");

	if(IsEmptyProp(strval(params)) == false) return SendClientMessage(playerid, -1, "This property does not belong to you!");

	GetPlayerName(playerid, Name, sizeof Name);

	if(IsPlayerOwnerProp(Name, strval(params)) == true) return SendClientMessage(playerid, -1, "This property already belongs to you!");

	if(IsPlayerInRangeOfProp(playerid, strval(params)) == false) return SendClientMessage(playerid, -1, "You need to be close to the property");

	if(GetPlayerMoney(playerid) < GetPropBuyVal(strval(params))) return SendClientMessage(playerid, -1, "You have no money to buy this property!");

	GivePlayerMoney(playerid, - GetPropBuyVal(strval(params)));

	GetPlayerName(playerid, Name, sizeof Name);

	BuyProp(Name, strval(params));

	SendClientMessage(playerid, -1, "Successfully purchased property");

	return 1;
}

CMD:psell(playerid, params[])
{
	new Name[MAX_PLAYER_NAME];

	if(isnull(params)) return SendClientMessage(playerid, -1, "/ PSELL [&ID]");

	if(PropIdExists(strval(params)) == false) return SendClientMessage(playerid, -1, "This property does not exist.");

	if(IsEmptyProp(strval(params)) == true) return SendClientMessage(playerid, -1, "This property belongs to no one!");

	GetPlayerName(playerid, Name, sizeof Name);

	if(IsPlayerOwnerProp(Name, strval(params)) == false) return SendClientMessage(playerid, -1, "This property does not belong to you!");

	SellProp(strval(params));

	GivePlayerMoney(playerid, GetPropSellVal(strval(params)) + GetPropLucreVal(strval(params)));

	SendClientMessage(playerid, -1, "Successfully sold property!");

	return 1;
}

CMD:showprops(playerid, params[])
{
	if(isnull(params)) return SendClientMessage(playerid, -1, "/SHOWPROPS [&OWNER]");

	GetPlayerProps(playerid, params);
	
	return 1;
}

CMD:getlucre(playerid, params [])
{
	new Name[MAX_PLAYER_NAME];

	if(isnull(params)) return SendClientMessage(playerid, -1, "/GETLUCRE [&ID]");

	if(PropIdExists(strval(params)) == false) return SendClientMessage(playerid, -1, "This property does not exist.");

	if(IsEmptyProp(strval(params)) == true) return SendClientMessage(playerid, -1, "This property belongs to no one!");

	GetPlayerName(playerid, Name, sizeof Name);

	if(IsPlayerOwnerProp(Name, strval(params)) == false) return SendClientMessage(playerid, -1, "This property does not belong to you!");

	if(IsPlayerInRangeOfProp(playerid, strval(params)) == false) return SendClientMessage(playerid, -1, "You need to be close to the property");

	GivePlayerMoney(playerid, GetPropLucreVal(strval(params)));

	SendClientMessage(playerid, -1, "You took all the profit generated by the property.");

	return 1;
}
* Download:
Pastebin

* Credits:
#include a_samp // By SAMP Team
#include zcmd // By Zeex
#include sscanf2 // By Emmet_
#include a_mysql // By BlueG
zPain By some tips.
zSuYaNw For the help in Lucre system.
Script by F1N4L
Reply
#2

awesome include \o/
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)