Property Functions -
dominik523 - 25.10.2014
Property Functions1.0
Introduction
Hey all. I decided to make this include to simplify the usage of properties because they are used differently for different types of data (i.e. setting integers into property goes in different way than setting strings) and I wanted to make my first include. Float values are saved using strings. After getting strings from properties, you don't have to worry about unpacking them.
What is a property and why should I use it?
If you want to share information about players/server between your scripts, among other ways of doing that, you might use properties. Here's an example:
pawn Код:
// ------------------------/ Gamemode code /--------------------------------------------- //
enum pInfo
{
pMoney,
pAdmin,
pSkin
};
new PlayerData[MAX_PLAYERS][pInfo];
public OnPlayerConnect(playerid)
{
LoadPlayerData(playerid);
Property_SetInt("Money", PlayerData[playerid][pMoney]);
Property_SetInt("AdminLevel", PlayerData[playerid][pAdmin]);
Property_SetInt("Skin", PlayerData[playerid][pSkin]);
CallRemoteFunction("TransferData", "d", playerid);
return 1;
}
// ------------------------/ Filterscript code /--------------------------------------------- //
forward public TransferData(playerid);
new AdminLevel[MAX_PLAYERS];
public TransferData(playerid)
{
Property_GetInt("Admin", AdminLevel[playerid]);
// other data
return 1;
}
Functions
Property_SetInt(Name[], Value) - Creates a new property of type integer or changes the existing one.
Property_SetFloat(Name[], Float:Value) - Creates a new property of type float or changes the existing one.
Property_SetString(Name[], Text[]) - Creates a new property of string integer or changes the existing one.
Property_GetInt(Name[], Dest) - Get a value from the property of type integer into the destination variable
Property_GetFloat(Name[], Dest) - Get a value from the property of type float into the destination variable
Property_GetString(Name[], Dest, sizeof(Dest)) - Get a value from the property of type string into the destination variable
Property_ExistInt(Name[]); - Returns true if the property of type integer with that name exists
Property_ExistString(Name[]); - Returns true if the property of type string with that name exists
Property_ExistFloat(Name[]); - Returns true if the property of type float with that name exists
Property_DeleteInt(Name[]); - Deletes the property of type integer with the given name exists
Property_DeleteString(Name[]); - Deletes the property of type string with the given name exists
Property_DeleteFloat(Name[]); - Deletes the property of type float with the given name exists
Download
Pastebin
Solidfiles
I tested this code and I didn't find any bugs. If you have any suggestions, feel free to put them in the comments. Thanks!
Re: Property Functions -
Lordzy - 25.10.2014
It's more like global variables (GVars) that has been already released here, both plugin version and PAWN version using property functions. If this is showing to be used for players, there are PVars which can do that.
Re: Property Functions -
dominik523 - 25.10.2014
Oh well, I haven't checked out GVars plugin.
It can be used for anything.
Re: Property Functions -
Glossy42O - 25.10.2014
Same as ****** said.
Anyways nice.
Re: Property Functions -
dominik523 - 25.10.2014
Quote:
Originally Posted by ******
I'd suggest storing floats as integers with a tag override, instead of as strings. The former will be lossless, but convering to and from strings is likely to be very inaccurate (and slower and larger).
|
Thank you for explaining that to me. I'll try to do what you have said.