ANTICHAT

ANTICHAT (https://forum.antichat.xyz/index.php)
-   С/С++, C#, Rust, Swift, Go, Java, Perl, Ruby (https://forum.antichat.xyz/forumdisplay.php?f=24)
-   -   [mod_sa help] Nick Changer (https://forum.antichat.xyz/showthread.php?t=1301950)

Active[X] 01.08.2013 20:22

Hi, I tried nick changer command and compiling is ok, but when I testing on SAMP server, my game crashed... Why? please can you help me? Here is code

Код:





Код:

void cmd_nick ( char *param )
{
    if ( !strlen( param ) )
    {
        addMessageToChatWindow( "USAGE: /nick " );
        return;
    }
 
    else if ( g_SAMP == NULL )
        return;
 
    else if ( strlen( param )  ALLOWED_PLAYER_NAME_LENGTH )
    {
        addMessageToChatWindow( "USAGE: /nick " );
        return;
    }
 
    setLocalPlayerName( (char *)atoi( param ) );
    restartGame();
    disconnect( 500 );
    cheat_state_text( "Rejoining in %d seconds...", set.rejoin_delay / 1000 );
    cheat_state->_generic.rejoinTick = GetTickCount();
}





init_samp_chat_cmds()

Код:





Код:

addClientCommand( "nick", (char)cmd_nick );




Thanks

25GHz 01.08.2013 22:36

"param" is a "char *" just like "setLocalPlayerName" function argument, so you don't need to convert to int and then to "char *" again.

so, just...

setLocalPlayerName(param);

and the second argument of "addClientCommand" is a int, so you must not convert that void to char, but do it as an int, like this:

addClientCommand("nick", (int)cmd_nick); ;)

Active[X] 01.08.2013 22:44

Thanks :)

Skel 02.08.2013 12:39

void cmd_nick( char *param )

{

setLocalPlayerName(param); //name

disconnect( 1 );//disconect

restartGame();//restart games

cheat_state->_generic.rejoinTick = GetTickCount();

}

25GHz 03.08.2013 07:33

Цитата:

Сообщение от Skel

void cmd_nick( char *param )
{
setLocalPlayerName(param); //name
disconnect( 1 );//disconect
restartGame();//restart games
cheat_state->_generic.rejoinTick = GetTickCount();
}

disconnect( 1 ); will timeout your connection. use 500.

Skel 03.08.2013 11:07

Цитата:

Сообщение от 25GHz

disconnect( 1 ); will timeout your connection. use 500.


i use "1" millisecond :D

25GHz 03.08.2013 18:39

Цитата:

Сообщение от Skel

i use "1" millisecond :D

the value of this function(possibly) isn't about "timing", but the value to push, that represent the function reason, so if you set it to 1, you will not disconnect properly from server, and then, the connection will timeout. ;)

25GHz 05.08.2013 00:15

Цитата:

Сообщение от UnknownPlayer

here, look at this function at sobeit:

http://puu.sh/3TJ20

now look at this function at samp dll:

timing out(losting connection):

http://puu.sh/3TIxH

http://puu.sh/3TICF

leaving:

http://puu.sh/3TISt

so, dec: 500(hex: 0x01F4) will corectly close connection, any other value(default is 0) will timeout the connection. ;)

UnknownPlayer 05.08.2013 11:38

Цитата:

Сообщение от 25GHz

here, look at this function at sobeit:
http://puu.sh/3TJ20

now look at this function at samp dll:

timing out(losting connection):
http://puu.sh/3TIxH
http://puu.sh/3TICF

leaving:
http://puu.sh/3TISt

so, dec: 500(hex: 0x01F4) will corectly close connection, any other value(default is 0) will timeout the connection. ;)

Okey :(


Время: 00:17