PDA

View Full Version : Name from dialog


Larry123
07/11/2012, 07:50 PM
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?

Sinner
07/11/2012, 07:58 PM
In your OnDialogResponse() callback

if(dialogid == 1) {
if(response) {
// Process inputtext
}
}

Konstantinos
07/11/2012, 08:13 PM
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;
}

Larry123
07/11/2012, 08:18 PM
Also i can use

new pID = GetPlayerIdFromName(strlen(inputtext));

ANd then use if(IsPlayerConnected(pID))

or not?