SA-MP Forums Archive
Name from dialog - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Name from dialog (/showthread.php?tid=390748)



Name from dialog - Larry123 - 07.11.2012

Hello

If i have dialog like this:

Код:
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Enter name", "Enter player name to who you want to give cookie", "Give", "Cancel");
Then how i have to do dialog responde?

How i check if player is online or not and give him cookie and stuff?


Re: Name from dialog - Sinner - 07.11.2012

In your OnDialogResponse() callback
pawn Код:
if(dialogid == 1) {
    if(response) {
        // Process inputtext
    }
}



Re: Name from dialog - Konstantinos - 07.11.2012

Something fast I made, it should work.
Код:
#include <a_samp >
#include <zcmd >

public OnDialogResponse( playerid, dialogid, response, listitem, inputtext[ ] )
{
	if( dialogid == 1 )
    {
        if( response )
        {
			if( GetPlayerIdFromName( inputtext ) != INVALID_PLAYER_ID )
			{
			    // Give hime cookie!
			    return 1;
			}
			else return SendClientMessage( playerid, -1, "Invalid player ID!" );
		}
	}
	return 1;
}

CMD:cookie( playerid, params[ ] )
{
    ShowPlayerDialog( playerid, 1, DIALOG_STYLE_INPUT, "Enter name", "Enter player name to who you want to give cookie", "Give", "Cancel" );
    return 1;
}

stock GetPlayerIdFromName( playername[ ] )
{
	for( new i = 0; i <= GetMaxPlayers( ); i++ )
	{
    	if( IsPlayerConnected( i ) )
  		{
        	new
				playername2[ MAX_PLAYER_NAME ]
			;
            GetPlayerName(i, playername2, sizeof(playername2));
      		if( strcmp( playername2, playername, true, strlen( playername ) ) == 0 )
         	{
            	return i;
          	}
      	}
   	}
	return INVALID_PLAYER_ID;
}



Re: Name from dialog - Larry123 - 07.11.2012

Also i can use

new pID = GetPlayerIdFromName(strlen(inputtext));

ANd then use if(IsPlayerConnected(pID))

or not?