Jump to content
RAGE Multiplayer Community

Convert NetHandle to integer C#


echoHU
 Share

Recommended Posts

Hello!

I want to make a function to check an existing player with the same username i am logging in to the server.

public static bool IsPlayerExist( string username )
{
    for ( int i = 0; i < NAPI.Server.GetMaxPlayers(); i++)
    {
        if ( NAPI.Data.GetEntityData(NAPI.Player.GetPlayerFromHandle(i), "player.username") == username )
        {
            return false;
        }
    }
    return true;
}

it says: " cannot convert from 'int' to 'GTANetworkAPI.NetHandle' "

I would be grateful if you could tell me how to convert or make this script in a correct way. :)

Link to comment
Share on other sites

public static IdOrName client ( intrare string ) {
Client tinta = null ;
var tipInput = int . TryParse ( intrare , ieșire var id );
dacă ( tipInput ) {
foreach ( var jucător în NAPI . bazine . GetAllPlayers ()) {
dacă ( jucător . Valoare =! id ) continuă ;
tinta = jucător ;
pauza ;
}
}
altfel {
foreach ( var jucător în NAPI . bazine . GetAllPlayers ()) {
var playerName = player . Nume . ToUpper ();
în cazul în care ( ! playerName . Conține ( intrare . toupper ())) continue ;
tinta = jucător ;
pauza ;
}
}
retur tinta ;
}
 
EX pentru utilizare :
 
[ Comandă ( "test" )]
public void CMD_Test ( client client , player de șir )
{
var target = Funcție . IdOrName ( player );
dacă ( țintă ! = nulă )
{
client . SendChatMessage ( $ "Jucătorul a găsit { target . Name }" );
 
}
altfel
{
client . SendChatMessage ( "Jucătorul nu a găsit!" );
}
 
}
 

This is all you need

Edited by CMHDev
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...