27.10.2009, 20:16
(
Последний раз редактировалось Daren_Jacobson; 20.07.2011 в 23:03.
)
Respond
parameters broken down:
2 used in inputbox.
3 used in listbox.
We can see from this that msgbox is not that complicated.
Since listbox is the most complicated i will do that last.
from the above post, now the response would be.
Dandy bit of code, but ... what happened?
Well, that's what comments are for.
And we move on.
Inputbox:
You know the drill, commented.
I sure hope you are understanding this, if you are not re-read until you do.
Listbox:
Bugs
There are some known bugs with dialogs (or manipulating any return values), one is if you try to format the string inputtext and the player entered a % (percentage sign) it will restart your server (confirmation needed)
Seif_ has made this fix:
Contributors
Seif_
****** (for immensely helping me understand PAWN)
Joe Staff
$ЂЯĢ
I hope you get it, any questions can be asked in this thread.
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- playerid: the player who responded to the dialog.123
- dialogid: the id of the dialog responded to.123
- response: if button1 was clicked or not.123
- listitem: which item was selected if it was a listbox.3
- inputtext: the string which was entered on an inputbox, or text of listitem selected.23
2 used in inputbox.
3 used in listbox.
We can see from this that msgbox is not that complicated.
Since listbox is the most complicated i will do that last.
pawn Код:
ShowPlayerDialog(playerid, DIALOG_BASE, DIALOG_STYLE_MSGBOX, "WARNING", "Warning, your money has dropped below 100\nwould you like to take out a loan?", "yes", "no");
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if (dialogid == DIALOG_BASE)
{
if (response == 1)
{
PlayerLoan[playerid] += 500;
GivePlayerMoney(playerid, 500);
SendClientMessage(playerid, 0xFFFFFFFF, "You have taken a loan from the bank for $500");
}
else
{
SendClientMessage(playerid, 0xFFFFFFFF, "No loan has been taken.");
}
return 1;
}
return 0;
}
Well, that's what comments are for.
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) //the callback
if (dialogid == DIALOG_BASE) //checks if the dialogid is the one we want (DIALOG_BASE, which is the msgbox)
if (response == 1) //checks if the "Yes" button was pushed
PlayerLoan[playerid] += 500; //sets a variable to show that the player has taken a loan
GivePlayerMoney(playerid, 500); //gives the player the money
SendClientMessage(playerid, 0xFFFFFFFF, "You have taken a loan from the bank for $500"); //shows a message to the player
else // "No" button has been pushed
SendClientMessage(playerid, 0xFFFFFFFF, "No loan has been taken."); //tells the player that he chose to not take a loan
return 1; //returns 1 because we successfully handled it.
return 0; //returns 0 pass it on to other scripts to see if they know what this dialog is.
Inputbox:
pawn Код:
ShowPlayerDialog(playerid, DIALOG_BASE + 1, DIALOG_STYLE_INPUT, "Login", "Welcome back\nInsert password to login", "Login", "Cancel");
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) //the callback
{
if (dialogid == DIALOG_BASE + 1) //checking dialogid
{
if (response == 1) //making sure "Login" was pressed
{
if (!strcmp(inputtext, pPass[playerid])) //checking if it is the players password
{
LoginPlayer(playerid); //calling a function to log him in
}
else //incorrect password
{
ShowPlayerDialog(playerid, dialogid, DIALOG_STYLE_INPUT, "Invalid Password", "Invalid Password, try again", "Login", "Cancel"); //shows another dialog, with the same dialogid.
LogAttempts[playerid]++; //increments a variable to know how many time he has tried to login
if (LogAttempts[playerid] >=2) //is it greater then or equal to 2?
{
SendClientMessage(playerid, 0xFFFFFFFF, "Too many attempts, bye!"); //tells him what is about to happen
SetTimerEx("kicker", 200, 0, "i", playerid); //if you can't figure out what this is, see below
}
}
}
else //pressed "Cancel"
{
SendClientMessage(playerid, 0xFFFFFFFF, "well if you aren't going to login, LEAVE"); //some message
SendClientMessage(playerid, 0xFFFFFFFF, "okay, i will do it for you."); //another
SetTimerEx("kicker", 200, 0, "i", playerid); //a timer that allows the player to see the messages before he is kicked.
}
return 1; //returns 1, it has been handled
}
return 0;
}
Listbox:
pawn Код:
ShowPlayerDialog(playerid, DIALOG_BASE + 2, DIALOG_STYLE_LIST, "Destination", "LSPD\nLVPD\nSFPD\nLS Bank\nLS Airport", "warp", "cancel");
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) //the callback
{
if (dialogid == DIALOG_BASE + 2) //checking dialogid
{
if (response == 1) //warp has been pressed
{
switch (listitem) //a switch, not going to explain it here
{
case 0:SetPlayerPos(playerid, ...); //if (listitem == 0) Set... hey look, I just explained it.
case 1:SetPlayerPos(playerid, ...); //if (listitem == 1) Set...
case 2:SetPlayerPos(playerid, ...);
case 3:SetPlayerPos(playerid, ...);
case 4:SetPlayerPos(playerid, ...);
}
SendClientMessage(playerid, 0xFFFFFFFF, "warped to destination"); //a message to confirm the warp
}
else //pressed cancel
{
SendClientMessage(playerid, 0xFFFFFFFF, "warping canceled"); //confirmation of declination
}
return 1; //returns 1, it has been handled
}
return 0;
}
Bugs
There are some known bugs with dialogs (or manipulating any return values), one is if you try to format the string inputtext and the player entered a % (percentage sign) it will restart your server (confirmation needed)
Seif_ has made this fix:
pawn Код:
for(new s; s < strlen(inputtext); s++)
{
if (inputtext == '%')
{
inputtext = ' ';
}
}
Seif_
****** (for immensely helping me understand PAWN)
Joe Staff
$ЂЯĢ
I hope you get it, any questions can be asked in this thread.