GetPVarString

From SA-MP Wiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 08:23, 18 January 2014
Smithy (Talk | contribs)

← Previous diff
Revision as of 07:59, 30 November 2014
Threshold (Talk | contribs)

Next diff →
Line 24: Line 24:
{ {
new playerName[MAX_PLAYER_NAME+1]; new playerName[MAX_PLAYER_NAME+1];
- GetPVarString(playerid, "PlayerName", playerName);+ GetPVarString(playerid, "PlayerName", playerName, sizeof(playerName));
printf("%s died.", playerName); printf("%s died.", playerName);

Revision as of 07:59, 30 November 2014



Description:

Gets a player variable as a string.


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.


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