How to check what a player wrote in a dialog
#1

So, the title bassicly says everything, I'm currently working a very detailed admin script and I have created
a control panel dialog and what I'd like to know is.
That when an admin presses the Kick a Player option it'll show him a dialog asking for the ID that I already did.
But how do I like get the response from it and check if the ID == INVALID_PLAYER_ID or after that when the
admin is supposed to write the reason etc, do I need to use strcmp? strfind? Well, I don't know.
I'm looking for an answer quick because it's kind of stopping the development of the admin script.
Thanks if anyone helps
Reply
#2

You can do it using an input dialog, and check if the inputtext is numeric, after that you have to strval(inputtext); and finally you can perform a second check to know if the ID entered was valid or not.

PHP код:
http://wiki.sa-mp.com/wiki/ShowPlayerDialog 
PHP код:
public OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
        return 
0;

I don't know who made this function, but here it is:

PHP код:
IsNumeric(const string[])
{
        for (new 
0strlen(string); ji++)
        {
                if (
string[i] > '9' || string[i] < '0') return 0;
        }
        return 
1;

Reply
#3

Quote:
Originally Posted by ThePhenix
Посмотреть сообщение
You can do it using an input dialog, and check if the inputtext is numeric, after this check you can perform a second check to know if the ID entered was valid or not.

PHP код:
http://wiki.sa-mp.com/wiki/ShowPlayerDialog 
PHP код:
public OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
        return 
0;

I don't know who made this function, but here it is:

PHP код:
IsNumeric(const string[])
{
        for (new 
0strlen(string); ji++)
        {
                if (
string[i] > '9' || string[i] < '0') return 0;
        }
        return 
1;

So, bassicly I'm supposed to do:

pawn Код:
if(!IsNumeric(inputtext)) ...... ?
Reply
#4

You could do it like this:
PHP код:
public OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    if(
dialogid == YourDialogID)
    {
        if(
response)
        {
            if(!
IsNumeric(inputtext)) return  ShowPlayerDialog(playeridYourDialogIDDIALOG_STYLE_INPUT"Kick""The ID entered was not valid""Kick""");
            new 
targetid strval(inputtext);//You can kick targetid if it's connected now.
            
if(targetid == INVALID_PLAYER_ID) return ShowPlayerDialog(playeridYourDialogIDDIALOG_STYLE_INPUT"Kick""The ID entered was not valid""Kick""");
            
//the other stuff...
        
}
    }
    return 
0;
}
IsNumeric(const string[])
{
        for (new 
0strlen(string); ji++)
        {
                if (
string[i] > '9' || string[i] < '0') return 0;
        }
        return 
1;

Reply
#5

Quote:
Originally Posted by ThePhenix
Посмотреть сообщение
You could do it like this:
PHP код:
public OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    if(
dialogid == YourDialogID)
    {
        if(
response)
        {
            if(!
IsNumeric(inputtext)) return  ShowPlayerDialog(playeridYourDialogIDDIALOG_STYLE_INPUT"Kick""The ID entered was not valid""Kick""");
            new 
targetid strval(inputtext);
            if(
targetid == INVALID_PLAYER_ID) return ShowPlayerDialog(playeridYourDialogIDDIALOG_STYLE_INPUT"Kick""The ID entered was not valid""Kick""");
            
//the other stuff...
        
}
    }
    return 
0;
}
IsNumeric(const string[])
{
        for (new 
0strlen(string); ji++)
        {
                if (
string[i] > '9' || string[i] < '0') return 0;
        }
        return 
1;

Alright, now I understand this.
Now I have another question:

How do I then check a string? Like after a player writes a string it'll do the command afterwards if all the conditions
are == true then it'll do the command, but how do I check the string and then format it, I only need to know how to
check the string and I think I'm good.
Reply
#6

pawn Код:
if((inputtext) == "Your string")
Reply
#7

Quote:
Originally Posted by Faisal_khan
Посмотреть сообщение
pawn Код:
if((inputtext) == "Your string")
Is it possible to do something like this?

pawn Код:
format(string, sizeof(string), "[KICK]: %s has been kicked by %s Reason: %s", GetName(playerid), IsNumeric(inputtext), inputtext);

SendClientMessageToAll(COLOR_RED, string);
It's possible?
Reply
#8

It isn't, well at least the way your doing it.

You need something called sscanf.
Use sscanf to split inputtext into an id and a string.

Then tell the admin to enter in the dialog this:
ID REASON

(of course replace id with id and the reason with the text)
Reply
#9

Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) 
{ 
	if(dialogid == YourDialogID) 
	{ 
        	if(response) 
        	{ 
			new pID, reason[32], string[144];
            		if(sscanf(inputtext, "us[32]", pID, reason))
			{
				//errorcode
			}
            		else
			{
				format(string, sizeof(string), "[KICK]: %s has been kicked by %s Reason: %s", GetName(pID), GetName(playerid), reason);
				SendClientMessageToAll(COLOR_RED, string);
				Kick(pID);
			}
        	} 
    	} 
}
^ Requires sscanf https://sampforum.blast.hk/showthread.php?tid=120356
Reply
#10

Quote:
Originally Posted by MicroD
Посмотреть сообщение
Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) 
{ 
	if(dialogid == YourDialogID) 
	{ 
        	if(response) 
        	{ 
			new pID, reason[32], string[144];
            		if(sscanf(inputtext, "us[32]", pID, reason))
			{
				//errorcode
			}
            		else
			{
				format(string, sizeof(string), "[KICK]: %s has been kicked by %s Reason: %s", GetName(pID), GetName(playerid), reason);
				SendClientMessageToAll(COLOR_RED, string);
				Kick(pID);
			}
        	} 
    	} 
}
^ Requires sscanf https://sampforum.blast.hk/showthread.php?tid=120356
Quote:
Originally Posted by Stinged
Посмотреть сообщение
It isn't, well at least the way your doing it.

You need something called sscanf.
Use sscanf to split inputtext into an id and a string.

Then tell the admin to enter in the dialog this:
ID REASON

(of course replace id with id and the reason with the text)
I don't think you guys quite get me.

Let me explain it again:

I have a dialog that when a player presses "Kick A Player" it'll create another dialog with input style and then how
do I get what the player wrote in that? Like first after the admin presses 'kick a player' it'll create another dialog asking for ID, how do I get the ID, then it checks if the id is valid or not, then it'll ask for a reason and what you wrote
in those two dialogs will format the message into a client message and kick the player eventually.

I just want to know, HOW TO GET WHAT THE PLAYER WROTE IN THE FIRST DIALOG.
&&& In the SECOND dialog for the reason, that's the only thing I need to know, thanks.

Note: I use sscanf2, DOF2 and zcmd...
Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)