How to check what a player wrote in a dialog -
Ox1gEN - 15.08.2014
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
Re: How to check what a player wrote in a dialog -
ThePhenix - 15.08.2014
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(playerid, dialogid, response, listitem, inputtext[])
{
return 0;
}
I don't know who made this function, but here it is:
PHP код:
IsNumeric(const string[])
{
for (new i = 0, j = strlen(string); i < j; i++)
{
if (string[i] > '9' || string[i] < '0') return 0;
}
return 1;
}
Re: How to check what a player wrote in a dialog -
Ox1gEN - 15.08.2014
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(playerid, dialogid, response, listitem, inputtext[])
{
return 0;
}
I don't know who made this function, but here it is:
PHP код:
IsNumeric(const string[])
{
for (new i = 0, j = strlen(string); i < j; i++)
{
if (string[i] > '9' || string[i] < '0') return 0;
}
return 1;
}
|
So, bassicly I'm supposed to do:
pawn Код:
if(!IsNumeric(inputtext)) ...... ?
Re: How to check what a player wrote in a dialog -
ThePhenix - 15.08.2014
You could do it like this:
PHP код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == YourDialogID)
{
if(response)
{
if(!IsNumeric(inputtext)) return ShowPlayerDialog(playerid, YourDialogID, DIALOG_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(playerid, YourDialogID, DIALOG_STYLE_INPUT, "Kick", "The ID entered was not valid", "Kick", "");
//the other stuff...
}
}
return 0;
}
IsNumeric(const string[])
{
for (new i = 0, j = strlen(string); i < j; i++)
{
if (string[i] > '9' || string[i] < '0') return 0;
}
return 1;
}
Re: How to check what a player wrote in a dialog -
Ox1gEN - 15.08.2014
Quote:
Originally Posted by ThePhenix
You could do it like this:
PHP код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == YourDialogID)
{
if(response)
{
if(!IsNumeric(inputtext)) return ShowPlayerDialog(playerid, YourDialogID, DIALOG_STYLE_INPUT, "Kick", "The ID entered was not valid", "Kick", "");
new targetid = strval(inputtext);
if(targetid == INVALID_PLAYER_ID) return ShowPlayerDialog(playerid, YourDialogID, DIALOG_STYLE_INPUT, "Kick", "The ID entered was not valid", "Kick", "");
//the other stuff...
}
}
return 0;
}
IsNumeric(const string[])
{
for (new i = 0, j = strlen(string); i < j; i++)
{
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.
Re: How to check what a player wrote in a dialog -
Faisal_khan - 15.08.2014
pawn Код:
if((inputtext) == "Your string")
Re: How to check what a player wrote in a dialog -
Ox1gEN - 15.08.2014
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?
Re: How to check what a player wrote in a dialog -
Stinged - 15.08.2014
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)
Re: How to check what a player wrote in a dialog -
MicroD - 15.08.2014
Код:
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
Re: How to check what a player wrote in a dialog -
Ox1gEN - 15.08.2014
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...