GetPVarString

From SA-MP Wiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 12:02, 25 September 2010
Lesim2005 (Talk | contribs)

← Previous diff
Current revision
MultiKill (Talk | contribs)

Line 1: Line 1:
{{Scripting}} {{Scripting}}
-{{Title}} 
{{Description|Gets a player variable as a string.}} {{Description|Gets a player variable as a string.}}
 +
 +{{Note|Variables aren't reset until after [[OnPlayerDisconnect]] is called, so the values are still accessible in [[OnPlayerDisconnect]].}}
{{Parameters|playerid, varname[], string_return[], len}} {{Parameters|playerid, varname[], string_return[], len}}
-{{Param|playerid|The ID of the player whose player variable you're getting.}}+{{Param|playerid|The ID of the player whose player variable to get.}}
-{{Param|varname|The name of the player variable.}}+{{Param|varname|The name of the player variable, set by [[SetPVarString]].}}
-{{Param|&string_return|The string to store the PVarString in, passed by reference.}}+{{Param|&string_return|The array in which to store the string value in, passed by reference.}}
-{{Param|len|Number of cells the string has been assigned.}}+{{Param|len|The maximum length of the returned string.}}
-{{Returns|This function returns the length of player's PVarString.}}+
 +{{Returns|The length of the string.}}
 +
 +{{Note|If length of string is zero (value not set), string_return text will not be updated or set to anything and will remain with old data, neccesying that you clear the variable to blank value if GetPVarString returns 0 if that behavior is undesired
 +}}
 +
 +'''Example: Save the player's name in a pVar'''
<pawn> <pawn>
public OnPlayerConnect(playerid,reason) public OnPlayerConnect(playerid,reason)
{ {
- new pmsg[128];+ new playerName[MAX_PLAYER_NAME+1];
- GetPVarString(playerid, "msg", pmsg, 128);// Get the msg string from the PVar+ GetPlayerName(playerid, playerName, MAX_PLAYER_NAME);
- printf("Player Message: %s", pmsg);// will print 'Player Message: *message*'+ SetPVarString(playerid, "PlayerName", playerName);
return 1; return 1;
 +}
 +
 +public OnPlayerDeath(playerid, killerid, reason)
 +{
 + new playerName[MAX_PLAYER_NAME+1];
 + GetPVarString(playerid, "PlayerName", playerName, sizeof(playerName));
 +
 + printf("%s died.", playerName);
} }
</pawn> </pawn>
 +
{{RelatedFunctions}} {{RelatedFunctions}}
 +{{SetPVarString}}
{{SetPVarInt}} {{SetPVarInt}}
{{GetPVarInt}} {{GetPVarInt}}
-{{SetPVarString}} 
{{SetPVarFloat}} {{SetPVarFloat}}
{{GetPVarFloat}} {{GetPVarFloat}}

Current revision



Description:

Gets a player variable as a string.


Image:32px-Ambox_warning_orange.png

Note

Variables aren't reset until after OnPlayerDisconnect is called, so the values are still accessible in OnPlayerDisconnect.


Parameters:
(playerid, varname[], string_return[], len)
playeridThe ID of the player whose player variable to get.
varnameThe name of the player variable, set by SetPVarString.
&string_returnThe array in which to store the string value in, passed by reference.
lenThe maximum length of the returned string.


Return Values:

The length of the string.


Image:32px-Ambox_warning_orange.png

Note

If length of string is zero (value not set), string_return text will not be updated or set to anything and will remain with old data, neccesying that you clear the variable to blank value if GetPVarString returns 0 if that behavior is undesired


Example: Save the player's name in a pVar

public OnPlayerConnect(playerid,reason)
{
    new playerName[MAX_PLAYER_NAME+1];
    GetPlayerName(playerid, playerName, MAX_PLAYER_NAME);
    SetPVarString(playerid, "PlayerName", playerName);
    return 1;
}
 
public OnPlayerDeath(playerid, killerid, reason)
{
    new playerName[MAX_PLAYER_NAME+1];
    GetPVarString(playerid, "PlayerName", playerName, sizeof(playerName));
 
    printf("%s died.", playerName);
}


Related Functions

The following functions may be useful, as they are related to this function in one way or another.

  • SetPVarInt: Set an integer for a player variable.
  • GetPVarInt: Get the previously set integer from a player variable.
  • GetPVarFloat: Get the previously set float from a player variable.
Personal tools