GetPlayerFromName: Difference between revisions

From RAGE Multiplayer Wiki
(Created page with "This method returns a Player param from a given player name, returns '''null''' if the player name does not exist. ==Syntax== <syntaxhighlight lang="C#" >Client NAPI.Player.G...")
 
No edit summary
Line 7: Line 7:
*'''name:''' parameter input should be in '''string''' type.
*'''name:''' parameter input should be in '''string''' type.


'''NOTE:''' This function returns data in '''Client''' type.
'''NOTE:''' This function returns data in '''Player''' type.


==Usage example==
==Usage example==
Line 19: Line 19:
<syntaxhighlight lang="C#" >
<syntaxhighlight lang="C#" >
     string name = "Bob";
     string name = "Bob";
     Client target = NAPI.Player.GetPlayerFromName(name);
     Player target = NAPI.Player.GetPlayerFromName(name);
     bool exists = target != null;
     bool exists = target != null;
     if (exists) NAPI.Player.KickPlayer(target, "Flock you Bob!");
     if (exists) NAPI.Player.KickPlayer(target, "Flock you Bob!");

Revision as of 21:48, 22 December 2022

This method returns a Player param from a given player name, returns null if the player name does not exist.

Syntax

Client NAPI.Player.GetPlayerFromName(string name);

Required Arguments

  • name: parameter input should be in string type.

NOTE: This function returns data in Player type.

Usage example

Check if the name Bob exists.

    bool exists = NAPI.Player.GetPlayerFromName("Bob") != null;
    if(exists) NAPI.Chat.SendChatMessageToAll("BOB EXISTS!!!");

Kick the Player if their name exists.

    string name = "Bob";
    Player target = NAPI.Player.GetPlayerFromName(name);
    bool exists = target != null;
    if (exists) NAPI.Player.KickPlayer(target, "Flock you Bob!");