echoHU

Convert NetHandle to integer C#

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. :)

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.