[SOLVED]SAMP Server Crashes when i select Menu Row
#1

I found a nice Restaurant menu script and i edited it a little.

But when i choose a Menu row named "Exit" my samp server crashes.... i don't know whats the problem so please help me.

Here's the code:

pawn Код:
if(Current == burgermenu)
    {
            new actstring[128];
            new sendername[64];
            new Float:health;
            GetPlayerName(playerid, sendername, sizeof(sendername));
            GetPlayerHealth(playerid, health);

                switch (row)
                {
                    case 0:
                    {
                        format(actstring, sizeof(actstring), "* %s eats a hamburger.", sendername);
                        SafeGivePlayerMoney(playerid, -2);
                        SetPlayerHealth(playerid, health + 20);
                        ShowMenuForPlayer(burgermenu, playerid);
                        TogglePlayerControllable(playerid, 0);
                    }
                    case 1:
                    {
                        format(actstring, sizeof(actstring), "* %s eats a donnut.", sendername);
                        SafeGivePlayerMoney(playerid, -2);
                        SetPlayerHealth(playerid, health + 20);
                        ShowMenuForPlayer(burgermenu, playerid);
                        TogglePlayerControllable(playerid, 0);
                    }
                    case 2:
                    {
                        format(actstring, sizeof(actstring), "* %s eats pizza.", sendername);
                        SafeGivePlayerMoney(playerid, -5);
                        SetPlayerHealth(playerid, health + 80);
                        ShowMenuForPlayer(burgermenu, playerid);
                        TogglePlayerControllable(playerid, 0);
                    }
                    case 3:
                    {
                      format(actstring, sizeof(actstring), "* %s eats french fries.", sendername);
                        SafeGivePlayerMoney(playerid, -1);
                        SetPlayerHealth(playerid, health + 10);
                        ShowMenuForPlayer(burgermenu, playerid);
                        TogglePlayerControllable(playerid, 0);
                    }
                    case 4:
                    {
                        TogglePlayerControllable(playerid, 1);
                        HideMenuForPlayer(burgermenu, playerid);
                    }
                }
                if (GetPlayerMoney(playerid) > 100) SetPlayerHealth(playerid, 100);
                ProxDetector(30.0, playerid, actstring, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
    }
pawn Код:
public CreateFoodMenus()
{
    // Burger Shot
    burgermenu = CreateMenu("Food", 2, 35.0, 140.0, 100.0, 150.0);
    AddMenuItem(burgermenu,0,"Hamburger");
    AddMenuItem(burgermenu,0,"Donnut");
    AddMenuItem(burgermenu,0,"Pizza");
    AddMenuItem(burgermenu,0,"French Fries");
    AddMenuItem(burgermenu,0,"Exit");
    AddMenuItem(burgermenu,1,"$2");
    AddMenuItem(burgermenu,1,"$2");
    AddMenuItem(burgermenu,1,"$5");
    AddMenuItem(burgermenu,1,"$1");
    AddMenuItem(burgermenu,1," ");
    DisableMenuRow(burgermenu, 10);
Thanks for your time and help
Reply
#2

DisableMenuRow(burgermenu, 10);

What does that do?
Reply
#3

You shouldn't have to hide the menu when they select something. It should hide it by itself. Maybe it has something to do with it being called exit. Try changing the name.
Reply
#4

Quote:
Originally Posted by pıʞoɹʎd
DisableMenuRow(burgermenu, 10);

What does that do?
With it or without it, it still crashes

Quote:
Originally Posted by backwardsman97
You shouldn't have to hide the menu when they select something. It should hide it by itself. Maybe it has something to do with it being called exit. Try changing the name.
I tryed changing the name, it's the same..
Reply
#5

Quote:
Originally Posted by Zeromanster
Quote:
Originally Posted by pıʞoɹʎd
DisableMenuRow(burgermenu, 10);

What does that do?
With it or without it, it still crashes

Quote:
Originally Posted by backwardsman97
You shouldn't have to hide the menu when they select something. It should hide it by itself. Maybe it has something to do with it being called exit. Try changing the name.
I tryed changing the name, it's the same..
Then it must be HideMenuForPlayer(burgermenu, playerid);....
remove it.
Reply
#6

Quote:
Originally Posted by OmeRinG
Then it must be HideMenuForPlayer(burgermenu, playerid);....
remove it.
I did, and it's the same
Reply
#7

Bump ?
Reply
#8

Is it anything to do with:

pawn Код:
AddMenuItem(burgermenu,1," ");
Just a wild guess; I know that textdraws seem to hate this. You could try changing the " " to "-" for now or something?
Reply
#9

Quote:
Originally Posted by Benjo
Is it anything to do with:

pawn Код:
AddMenuItem(burgermenu,1," ");
Just a wild guess; I know that textdraws seem to hate this. You could try changing the " " to "-" for now or something?
I did that, but it still crashes my server
Reply
#10

You server (or client) crashes because you are sending an empty (unformatted) string in case you chose the "exit-row"

Look:
Код:
if(Current == burgermenu)
{
  new actstring[128];  //You are defining a new string
  (....)
  switch (row)
  {
    case 0:
	{
      format(actstring, sizeof(actstring), "* %s eats a hamburger.", sendername);
      //You formatted a string. This happens too in case 1, 2 and 3.
    }
    (...)
    case 4:
    {
      TogglePlayerControllable(playerid, 1);
      HideMenuForPlayer(burgermenu, playerid);
      //You don't format the string here
    }
  }
  (....)
  ProxDetector(30.0, playerid, actstring, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
  //And here you send the string to players. A formatted string won't cause problems, but unformatted string, will crash the server.
}
What you should do, is put that ProxDetector-function inside the case 0, 1, 2 and 3 -pieces instead of outside.
So it should be like this:

http://pastebin.com/f103fcdb1
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)