PDA

View Full Version : /cmds in dialogbox


NviDa
30/03/2015, 05:48 PM
I have a few commands like:
/heal
/kill etc.
And I can view all these commands when I do /cmds.But it appears in chatbox.I want to show it in a dialog box.How can I do it ?

CalvinC
30/03/2015, 05:52 PM
Here's an example using ZCMD:
enum
{
DIALOG_CMDS
}

COMMAND:commands(playerid)
{
ShowPlayerDialog(playerid, DIALOG_CMDS, DIALOG_STYLE_MSGBOX, "Title", "text", "Button1", "Button2");
return 1;
}
Source:
http://wiki.sa-mp.com/wiki/ShowPlayerDialog

NviDa
30/03/2015, 05:57 PM
@CalvinC
I know that but I don't wanna have button 1 and 2.Can I just put button 1?
And why do you use enum here?Could you explain the enum part?

Wassimo
30/03/2015, 05:58 PM
// This command lists all commands for normal players (admin-level 0)
COMMAND:cmds(playerid, params[])
{
// Check if the player has logged in
if (APlayerData[playerid][LoggedIn] == true)
{
CommandList_Create(playerid); // Create a list of commands (only the first 4 commands) and show the dialog
}
else
return 0;

// Let the server know that this was a valid command
return 1;
}

CalvinC
30/03/2015, 06:09 PM
Just make the second button contain nothing:
ShowPlayerDialog(playerid, DIALOG_CMDS, DIALOG_STYLE_MSGBOX, "Title", "text", "Button1", "");
Then it wont be displayed.
And i use an enumerator so that the numbers gets assigned automatically, you can use #define as well to define numbers, but using an enumerator is easier and less confusing.

NviDa
30/03/2015, 06:12 PM
Which numbers do you mean?

Sorry..I am not really good @ pawn,just learning..

NoDi522
30/03/2015, 06:20 PM
#include <a_samp>
#define DIALOG_COMMANDS 1 // This is alternative defining. I prefer enums but however..
#include <zcmd> // You have to download zcmd.inc and include it to use this command:

CMD:commands(playerid,params[])
{
ShowPlayerDialog(playerid,DIALOG_COMMANDS,DIALOG_S TYLE_LIST,"Choose your command","- Heal\n- Suicide\n- Deagle\n- You Command","Choose","");
return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch(dialogid)
{
case DIALOG_COMMANDS:
{
if(response)
{
switch(listitem)
{
case 0:
{
SetPlayerHealth(playerid,100); //Healing player
SendClientMessage(playerid,-1,"You have been healed"); // done healing
}
case 1:
{
SetPlayerHealth(playerid,0);
SendClientMessage(playerid,-1,"You did suicide");
}
case 2:
{
GivePlayerWeapon(playerid,24,500);
SendClientMessage(playerid,-1,"We gave you desert eagle");
}
case 3:
{
// Do some other commands
}
}
}
}
}
return 1;
}

Here is an example. Download ZCMD: http://forum.sa-mp.com/showthread.php?t=91354

CalvinC
30/03/2015, 06:34 PM
The dialog ID.
Each dialog has it's own dialogid, to be used in OnDialogResponse (http://wiki.sa-mp.com/wiki/OnDialogResponse) where you can script different functions for different dialog ID's.
Basically some people use
#define DIALOG_CMDS 1
Which makes
ShowPlayerDialog(playerid, 1, ...);
The same as doing
ShowPlayerDialog(playerid, DIALOG_CMDS, ...);
Which is more organised, and less confusing.
However using an enumerator is even less confusing, as it applies the ID's(numbers) automatically.