IntegersWHY PVAR'S?
As I previously said, an integer is any of the natural numbers (positive or negative) or zero... Integers are used alot in Pawno especially with Player Statistics such as Kills, Deaths, Money, Drugs, Ammo, Guns... Obviously, with an Integer we have a function... Which is:
pawn Код:SetPVarInt(playerid,varname[],amount);Down to the explaination... The Variable Name could be anything you want, but for this purpose we'll call it tutorial.Strings
So, now:
Basically, this sets the Variable "Tutorial" to 0, so we can refer back to it at a later date:pawn Код:public OnPlayerConnect(playerid)
{
SetPVarInt(playerid,"Tutorial",0);
return 1;
}
As I just shown, we can use the variable to control anything about the player, which doesn't involve strings or floats, now to change the Tutorial from 0 to 1 to establish that he's completed it.pawn Код:public OnPlayerSpawn(playerid)
{
if(GetPVarInt(playerid,"Tutorial") == 0)
{
SendClientMessage(playerid,WHITE,"Sorry, you have to take the tutorial.");
}
return 1;
}
pawn Код:public OnTutorialComplete(playerid)
{
if(GetPVarInt(playerid,"Tutorial") == 0)
{
SetPVarInt(playerid,"Tutorial",1);
SendClientMessage(playerid,WHITE,"Thank you for completeing the tutorial, you'll now be spawned.");
Spawn(playerid);
}
return 1;
}
Well, as we already know that strings usually refer to words, IP Addresses, and so on... We can firmly say that Strings in this event also refer to those, for example:
pawn Код:SetPVarString(playerid,varname[],string_value[]);Down to the explaination... The Variable Name could be anything you want, but for this purpose we'll call it MarriedTo.Floats
So, now:
As we can tell from the pawn code, it sets the player's MarriedTo stat to "No-one"... Now, let's get to work.pawn Код:public OnPlayerConnect(playerid)
{
SetPVarString(playerid,"MarriedTo","No-one");
return 1;
}
pawn Код:public OnPlayerConnect(playerid)
{
new married[128];
GetPVarString(playerid, "MarriedTo", married,128);
printf("Player Married To: %s", married);// will print 'Player Married To: *MarriedTo*'
return 1;
}
Well, already we know that Floats are usually found in Co-ordinates, Health, Armour and other things which carry a decimal point.
pawn Код:SetPVarFloat(playerid, varname[], Float:float_value);Down to the explaination... As with the other types of PVar's, the varname can be anything you want but for this example, we'll use PosX.DeletePVar
We can now use this to detect the players position and show it.pawn Код:public OnPlayerSpawn(playerid)
{
new Float:PosX,Float:PosY,Float:PosZ;
GetPlayerPos(playerid,PosX,PosY,PosZ);
SetPVarFloat(playerid,"PosX",PosX);
SetPVarFloat(playerid,"PosY",PosY);
SetPVarFloat(playerid,"PosZ",PosZ);
return 1;
}
pawn Код:public OnPlayerLogin(playerid,password[])
{
SetPlayerPos(playerid,GetPVarFloat(playerid,"PosX"),GetPVarFloat(playerid,"PosY"),GetPVarFloat(playerid,"PosZ"));
return 1;
}
Well... This basically says it all, so there's no need for an example... Mainly, this just deletes a variable we've used, so for this we'll say: PosX from the Float Example:
pawn Код:DeletePVar(playerid,varname[]);As I previously said, this is used to delete PVars, so let's use it shall we?GetPVarType
pawn Код:public OnPlayerDisconnect(playerid)
{
DeletePVar(playerid,"PosX");
return 1;
}
This basically gets the type of the PVar and returns it, so for example:
pawn Код:#define PLAYER_VARTYPE_NONE 0
#define PLAYER_VARTYPE_INT 1
#define PLAYER_VARTYPE_STRING 2
#define PLAYER_VARTYPE_FLOAT 3pawn Код:GetPVarType(playerid,varname[]);As I previously said, this is used to detect the type of PVar, so let's use it shall we?
pawn Код:public OnPlayerUpdate(playerid)
{
GetPVarType(playerid,"PosX"); // This would return: PLAYER_VARTYPE_FLOAT (Defined Above)
return 1;
}
As you probably already know, an Integer is a whole number which can be anything from 1-100000000. |
public OnPlayerConnect(playerid)
{
SetPVarInt(playerid,"Tutorial",0);
return 1;
}
I never have used PVar's , but I have question,
Here pawn Код:
like new Tutorial[MAX_PLAYERS]; |
Extremely unusual (in SA-MP forum context, very usual) way to start a tutorial. You say you just are learning about player variables and obviously haven't tested the code posted here, so why do you make a tutorial? You can't be entirely sure everything of it works and the usage of player variables is described very straightforward here and every function linked to the page has good examples and explanations there.
Wrong, look up the integer range (protip: also goes below zero) Also, SetPVarInt is a function, not a callback. I wonder if anyone checks the tutorials to see if they're actually going to be helpful for new coders. |
Originally Posted by ******
Define - integer:
• any of the natural numbers (positive or negative) or zero; "an integer is a number that is not a fraction". |
Originally Posted by ******
Define - Whole Number:
•A whole number doesn't contain a fraction. A whole number is an integer which has 1 or more units and can be positive or negative. |
Originally Posted by Shadow™
I've only started using PVars recently.
|
Originally Posted by Shadow™
by all means feel free to leave a reply with ideas on how I can improve it and if I have made a mistake somewhere.
|
public OnPlayerDisconnect(playerid)
{
DeletePVar(playerid,"PosX");
return 1;
}
// PVar enumeration
#define PLAYER_VARTYPE_NONE 0
#define PLAYER_VARTYPE_INT 1
#define PLAYER_VARTYPE_STRING 2
#define PLAYER_VARTYPE_FLOAT 3
GetPVarType(playerid, "PosX");