How to build a menu with options for player
#1

I was wondering how to build a menu popup box with 4 options for the player - the player can press one from the list and click 'OK'. I've seen this done and tried it myself but never quite got the hang of the code required.

For example,

When the player enters the checkpoint at the SF Airport (-1410.3000488281, -299.10000610352, 14.10000038147) a command can be done (e.g. /fly) and the player is presented with a menu and able to pick one of the choices (LS,AA,SF,LV) to 'fly' to.

I found this helpful but wasn't able to adapt it to suit my needs or get it working.

Here's what I've got so far:

At the top
Код:
new Menu:airportmenu;
new Menu:CurrentMenu = GetPlayerMenu(playerid);
OnGameModeInit():
Код:
	airportmenu = CreateMenu("Airportmenu", 2, 200.0, 100.0, 150.0, 150.0);
	
	AddMenuItem(airportmenu, 0, "LS");
	AddMenuItem(airportmenu, 0, "LV");
	AddMenuItem(airportmenu, 0, "SF");
	AddMenuItem(airportmenu, 0, "AA");
	
	AddMenuItem(airportmenu, 1, "$2500");
	AddMenuItem(airportmenu, 1, "$3000");
	AddMenuItem(airportmenu, 1, "$3500");
	AddMenuItem(airportmenu, 1, "$400");
Код:
	if(CurrentMenu == airportmenu)
{
    switch(row)
    {
        case 0: //Los Santos
        {
            SetPlayerPos(playerid, 1685.8000488281, -2240, 13.5);
            SetPlayerInterior(playerid, 0);
            TakePlayerMoney(playerid, 2500);
            SendClientMessage(playerid, COLOR_RED, "You have boarded a flight to Los Santos International Airport.");
        }
        case 1: //Las Venturas
        {
            SetPlayerPos(playerid, 1687.8000488281, 1448, 10.800000190735);
            SetPlayerInterior(playerid, 0);
            TakePlayerMoney(playerid, 3000);
            SendClientMessage(playerid, COLOR_RED, "You have boarded a flight to Las Venturas Airport.");
        }
        case 2: //San Fierro
        {
            SetPlayerPos(playerid, -1410.3000488281, -299.10000610352, 14.10000038147);
            SetPlayerInterior(playerid, 0);
            TakePlayerMoney(playerid, 3500);
            SendClientMessage(playerid, COLOR_RED, "You have boarded a flight to San Fierro Airport.");
        }
        case 3: //Abandoned Airport
        {
            SetPlayerPos(playerid, 421, 2531.3000488281, 16.60000038147);
            SetPlayerInterior(playerid, 0);
            TakePlayerMoney(playerid, 400);
            SendClientMessage(playerid, COLOR_RED, "You have boarded a flight to Bone County Abandoned Airport.");
        }
    }
}
OnPlayerCommandText
Код:
if(strcmp(cmdtext, "/fly", true) == 0)
{
    ShowMenuForPlayer(airportmenu,playerid);
    return 1;
}
Reply
#2

In a quick glance everything looks fine, what is exactly the issue? is the menu not showing or working right?
Reply
#3

When I compile I get:

Код:
Pawn Compiler library has stopped working
Windows can check online for a solution to the problem.
.....
It doesn't compile. Perhaps it's something else.
Reply
#4

Quote:
Originally Posted by Arg
Посмотреть сообщение
When I compile I get:

Код:
Pawn Compiler library has stopped working
Windows can check online for a solution to the problem.
.....
It doesn't compile. Perhaps it's something else.
I think this is the problem:
pawn Код:
new Menu:CurrentMenu = GetPlayerMenu(playerid);
it shouldnt have that GetPlayerMenu function as it wouldnt work outisde of a callback.

fix:
pawn Код:
new Menu:CurrentMenu;
Hehe shouldve noticed before.
Reply
#5

This should work...


new Menu:CurrentMenu;
Reply
#6

Thank you Edix and Paul1990

I've changed it and now I am able to compile the code but there are still errors:

Код:
C:\Users\C\Desktop\SAMP\TEST SERVER\filterscripts\ts_airports.pwn(29) : error 017: undefined symbol "row"
C:\Users\C\Desktop\SAMP\TEST SERVER\filterscripts\ts_airports.pwn(33) : error 017: undefined symbol "playerid"
C:\Users\C\Desktop\SAMP\TEST SERVER\filterscripts\ts_airports.pwn(34) : error 017: undefined symbol "playerid"
C:\Users\C\Desktop\SAMP\TEST SERVER\filterscripts\ts_airports.pwn(35) : error 017: undefined symbol "playerid"
C:\Users\C\Desktop\SAMP\TEST SERVER\filterscripts\ts_airports.pwn(39) : error 017: undefined symbol "playerid"
C:\Users\C\Desktop\SAMP\TEST SERVER\filterscripts\ts_airports.pwn(40) : error 017: undefined symbol "playerid"
C:\Users\C\Desktop\SAMP\TEST SERVER\filterscripts\ts_airports.pwn(41) : error 017: undefined symbol "playerid"
C:\Users\C\Desktop\SAMP\TEST SERVER\filterscripts\ts_airports.pwn(45) : error 017: undefined symbol "playerid"
C:\Users\C\Desktop\SAMP\TEST SERVER\filterscripts\ts_airports.pwn(46) : error 017: undefined symbol "playerid"
C:\Users\C\Desktop\SAMP\TEST SERVER\filterscripts\ts_airports.pwn(47) : error 017: undefined symbol "playerid"
C:\Users\C\Desktop\SAMP\TEST SERVER\filterscripts\ts_airports.pwn(51) : error 017: undefined symbol "playerid"
C:\Users\C\Desktop\SAMP\TEST SERVER\filterscripts\ts_airports.pwn(52) : error 017: undefined symbol "playerid"
C:\Users\C\Desktop\SAMP\TEST SERVER\filterscripts\ts_airports.pwn(53) : error 017: undefined symbol "playerid"
Line 29
Код:
    switch(row)
Line 33
Код:
           SetPlayerPos(playerid, 1685.8000488281, -2240, 13.5);
Reply
#7

pawn Код:
if(CurrentMenu == airportmenu)
{
    switch(row)
    {
        case 0: //Los Santos
        {
            SetPlayerPos(playerid, 1685.8000488281, -2240, 13.5);
            SetPlayerInterior(playerid, 0);
            TakePlayerMoney(playerid, 2500);
            SendClientMessage(playerid, COLOR_RED, "You have boarded a flight to Los Santos International Airport.");
        }
        case 1: //Las Venturas
        {
            SetPlayerPos(playerid, 1687.8000488281, 1448, 10.800000190735);
            SetPlayerInterior(playerid, 0);
            TakePlayerMoney(playerid, 3000);
            SendClientMessage(playerid, COLOR_RED, "You have boarded a flight to Las Venturas Airport.");
        }
        case 2: //San Fierro
        {
            SetPlayerPos(playerid, -1410.3000488281, -299.10000610352, 14.10000038147);
            SetPlayerInterior(playerid, 0);
            TakePlayerMoney(playerid, 3500);
            SendClientMessage(playerid, COLOR_RED, "You have boarded a flight to San Fierro Airport.");
        }
        case 3: //Abandoned Airport
        {
            SetPlayerPos(playerid, 421, 2531.3000488281, 16.60000038147);
            SetPlayerInterior(playerid, 0);
            TakePlayerMoney(playerid, 400);
            SendClientMessage(playerid, COLOR_RED, "You have boarded a flight to Bone County Abandoned Airport.");
        }
    }
}
Is this under the OnPlayerSelectedMenuRow callback? if not then thats your problem and if you dont have such callback just copy this one (just remove the if and switch part and replace with urs):
https://sampwiki.blast.hk/wiki/OnPlayerSelectedMenuRow
Reply
#8

That was my problem Edix - now I've managed to fix it and get it working. Thanks
Reply
#9

You should round out those floats as well...

1410.3000488281 should just be 1410.3
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)