[Tutorial] How to make a teleport menu in dialog
#1

Hello this is my tutorial on how to make a simple (adjustable) teleport menu in dialog. Let's begin.

Download ZCMD and place in your pawno > includes folder. Then add this at the top of your script:
pawn Код:
#include <zcmd>
Under that include we'll define the dialogs ID so we don't forget it, something memorable, we'll go for TPMENU.

pawn Код:
#include <zcmd>

#define TPMENU 1
// Change '1' to whatever dialog ID you want it to be.
Let's start creating the command, we'll begin by scripting the following:

pawn Код:
CMD:teleport(playerid, params[]) // When we type /teleport
{  
    return 1;
}
Having 'return 1;' is very important, it makes sure the command 'exists' so once typed it doesn't give an UNKNOWN COMMAND message to the player.

Now we want it to bring up a dialog list of all the places we want to teleport to, for this we'll use the function 'ShowPlayerDialog'.

pawn Код:
CMD:teleport(playerid, params[])
{
    ShowPlayerDialog(playerid, TPMENU, DIALOG_STYLE_LIST, "Teleport Menu", "Police Department\nGym\nGrove Street\nGlen Park\nLas Venturas\nSan Fierro", "Go", "Exit");
    return 1;
}
What does this mean then? TPMENU is our dialogs ID which we defined earlier, duh! DIALOG_STYLE_LIST is the type of dialog which pops up, in our case a list. "Teleport Menu" is the title of the dialog which shows at the very top of the dialog. "Police Department\nGym\nGrove Street... ETC" is the actual list, '\n' means a new line. "Go" is the left button and finally "Exit" is the right button.

This may help: ShowPlayerDialog(player, dialogid, dialogtype, title, textbody, leftbutton, rightbutton);

Now once we've made it pop up the dialog, we want it to teleport them to the locations we want. Now CNTRL F and type 'OnDialogResponse' then press enter.

pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    return 0;
}
Now we want to say, if they clicked 'Police Department' on dialog TPMENU, then teleport them. So we'll script that now.

pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == TPMENU)
    {
       
    }
    return 0;
}
Now we want to say, if they clicked the button 'Go' or double clicked a place on the list then teleport them.

pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == TPMENU)
    {
        if(response) // Clicked 'Go'
        {
            switch(listitem)
            {

            }
        }
    }
    return 0;
}
'switch(listitem)' switches between the places on the list, this basically means we're scripting about a list menu.

Now we will add the cases, we always begin with 0 NOT 1.

pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == TPMENU)
    {
        if(response) // Clicked 'Go'
        {
            switch(listitem)
            {
                case 0: // PD
                case 1: // Gym
                case 2: // Grove
                case 3: // Glen Park
                case 4: // LV
                case 5: // SF
            }
        }
    }
    return 0;
}
Now we can add the actual coordinates of where we want them to teleport to, we add that right after each case.

pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == TPMENU)
    {
        if(response) // Clicked 'Go'
        {
            switch(listitem)
            {
                case 0: SetPlayerPos(playerid,1530,-1674,14); // PD
                case 1: SetPlayerPos(playerid,2228,-1741, 14); // Gym
                case 2: SetPlayerPos(playerid,2485,1666,14); // Grove
                case 3: SetPlayerPos(playerid,1973,-1195,26); // Glen Park
                case 4: SetPlayerPos(playerid,2067,1320,11); // LV
                case 5: SetPlayerPos(playerid,-2009,164,28); // SF
            }
        }
    }
    return 0;
}
So there, thats it.

I hope I helped and I give permission if you want to copy and use this because either way, I did help you. But rather than copying it I do advise reading through it to learn it yourself.
Reply


Messages In This Thread
How to make a teleport menu in dialog - by jackx3rx - 26.12.2014, 16:10
Re: How to make a teleport menu in dialog - by Tookieson - 26.12.2014, 16:22
Re: How to make a teleport menu in dialog - by Luicy. - 26.12.2014, 19:19
Re: How to make a teleport menu in dialog - by jackx3rx - 26.12.2014, 20:46
Re: How to make a teleport menu in dialog - by Luicy. - 26.12.2014, 20:52
Re: How to make a teleport menu in dialog - by www - 30.12.2014, 22:55
Re: How to make a teleport menu in dialog - by Diti1 - 30.12.2014, 23:29

Forum Jump:


Users browsing this thread: 2 Guest(s)