Name from dialog
#1

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?
Reply
#2

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

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;
}
Reply
#4

Also i can use

new pID = GetPlayerIdFromName(strlen(inputtext));

ANd then use if(IsPlayerConnected(pID))

or not?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)