From SA-MP Wiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 08:03, 8 December 2016
OstGot (Talk | contribs)

← Previous diff
Current revision
MultiKill (Talk | contribs)

Line 2: Line 2:
{{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}}
Line 32: Line 34:
} }
</pawn> </pawn>
{{RelatedFunctions}} {{RelatedFunctions}}

Current revision


Gets a player variable as a string.



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

(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.



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 helpful as they relate 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