Raised This Month: $32 Target: $400
 8% 

Creating a Donation Menu that executes commands, error related to a variable


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
keyboard1333
Senior Member
Join Date: Aug 2013
Old 08-24-2013 , 05:15   Creating a Donation Menu that executes commands, error related to a variable
Reply With Quote #1

Hey Everyone!
First time posting here, so I apologise if I've screwed anything up in advance.

I'm working to create a Simple Donator's Menu. You open the menu, choose a command and the server executes that command on you.

Here is my current code (not working):

PHP Code:
public OnPluginStart()
{
 
RegConsoleCmd("sm_donator"Menu_Test1);
 
LoadTranslations("common.phrases");
}
 
public 
MenuHandler1(Handle:menuMenuAction:actionparam1param2)
{
 
/* If an option was selected, tell the client about the item. */
 
if (action == MenuAction_Select)
 {
  new 
String:info[32];
  new 
String:steamid[20] = GetSteamAccountID(param1true);
  new 
bool:found GetMenuItem(menuparam2infosizeof(info));
  
//PrintToChat(param1, "%s %s", info, steamid);
  //ClientCommand(param1, "%s", info); 
  
ConsoleCommand(param1"%s #%s"infosteamid); 
 }
 
/* If the menu was cancelled, print a message to the server about it. */
 
else if (action == MenuAction_Cancel)
 {
  
//PrintToServer("Client %d's menu was cancelled.  Reason: %d", param1, param2);
 
}
 
/* If the menu has ended, destroy it */
 
else if (action == MenuAction_End)
 {
  
CloseHandle(menu);
 }
}
 
public 
Action:Menu_Test1(clientargs)
{
 new 
Handle:menu CreateMenu(MenuHandler1);
 
SetMenuTitle(menu"Donator Menu");
 
AddMenuItem(menu"sm_robot""Evil Trail");
 
AddMenuItem(menu"sm_eviltrail""Evil Trail");
 
AddMenuItem(menu"sm_evilglow""Evil Glow");
 
 
SetMenuExitButton(menufalse);
 
DisplayMenu(menuclient20);
 
 return 
Plugin_Handled;

I've got three plugins (robot, eviltrail, evilglow) used to test it with.


The issues:
I get an error while compiling.
PHP Code:
new String:steamid[20] = GetSteamAccountID(param1true); 
PHP Code:
donator.sp(14) : error 008must be a constant expression assumed zero 
I've also got a warning saying
PHP Code:
donator.sp(14): warning 204symbol is assigned a value that is never used"found" 
Any help with those issues would be greatly appreciated!
keyboard1333 is offline
Drixevel
AlliedModders Donor
Join Date: Sep 2009
Location: Somewhere headbangin'
Old 08-24-2013 , 05:43   Re: Creating a Donation Menu that executes commands, error related to a variable
Reply With Quote #2

Code:
OnPluginStart()
{
    LoadTranslations("common.phrases");
    RegAdminCmd("sm_donator", DonorMenu, ADMFLAG_RESERVATION);
}

public Action:DonorMenu(client, args)
{
    if (!client)
    {
        ReplyToCommand(client, "%t","Command is in-game only");
        return Plugin_Handled;
    }
    ShowMenu(client);
    return Plugin_Handled;
}

ShowMenu(client)
{
    new Handle:menu = CreateMenu(MenuHandler);
    SetMenuExitBackButton(menu, false);

    SetMenuTitle(menu, "Donor Menu");

    AddMenuItem(menu, "1", "Evil Beam");
    AddMenuItem(menu, "2", "Evil Glow");
    AddMenuItem(menu, "3", "Robot");

    DisplayMenu(menu, client, 30);
}

public MenuHandler(Handle:menu, MenuAction:action, client, param2)
{
    switch (action)
    {
    case MenuAction_Select:
        {
            switch (param2)    //You can also use ServerCommand to do it directly without the client typing the command themselves.
            {
            case 0:
                {
                    FakeClientCommandEx(client, "say /eviltrail");
                    //ServerCommand("sm_robot #%d", GetClientUserId(client));    <-- Example of server command instead of fake client command.
                }
            case 1:
                {
                    FakeClientCommandEx(client, "say /evilglow");
                }
            case 2:
                {
                    FakeClientCommandEx(client, "say /robot");
                }
            }
        }
    case MenuAction_End:
        {
            CloseHandle(menu);
        }
    }
}
Assuming you know how to add includes, checks, you know what to do with it, etc. You can work off this.

- Jack

Last edited by Drixevel; 08-24-2013 at 06:49.
Drixevel is offline
Doodil
Senior Member
Join Date: Mar 2012
Old 08-24-2013 , 06:12   Re: Creating a Donation Menu that executes commands, error related to a variable
Reply With Quote #3

Quote:
Originally Posted by keyboard1333 View Post
The issues:
I get an error while compiling.
PHP Code:
new String:steamid[20] = GetSteamAccountID(param1true); 
PHP Code:
donator.sp(14) : error 008must be a constant expression assumed zero 
GetSteamAccountID does not return a string, you might look for GetClientAuthString if you want to get the Steam-ID or not save it as a string if you think you are using the right function. Sourcemod also doesn't allow for strings to be returned, you have to give the function a (empty) string as a parameter and the size of the stringarray and the function fills the string with information.

Quote:
Originally Posted by keyboard1333 View Post
I've also got a warning saying
PHP Code:
donator.sp(14): warning 204symbol is assigned a value that is never used"found" 
Any help with those issues would be greatly appreciated!
Well, it just means you initialize a variable that you never use. Sourcemod throws a warning because you usually want to use all variables you initialize and this might be an error.
Doodil is offline
keyboard1333
Senior Member
Join Date: Aug 2013
Old 08-24-2013 , 06:22   Re: Creating a Donation Menu that executes commands, error related to a variable
Reply With Quote #4

Jack, first off thankyou for your timely response!
I tested your code but I got a compilation error -
PHP Code:
donator.sp(42) : error 017undefined symbol "client" 
Am I missing something?


And thanks for your response Doodil, that explains my issues!

Last edited by keyboard1333; 08-24-2013 at 06:24.
keyboard1333 is offline
Drixevel
AlliedModders Donor
Join Date: Sep 2009
Location: Somewhere headbangin'
Old 08-24-2013 , 06:47   Re: Creating a Donation Menu that executes commands, error related to a variable
Reply With Quote #5

Quote:
Originally Posted by keyboard1333 View Post
Jack, first off thankyou for your timely response!
I tested your code but I got a compilation error -
PHP Code:
donator.sp(42) : error 017undefined symbol "client" 
Am I missing something?


And thanks for your response Doodil, that explains my issues!
Whoops, replace this:
Code:
public MenuHandler(Handle:menu, MenuAction:action, param1, param2)
with this:
Code:
public MenuHandler(Handle:menu, MenuAction:action, client, param2)
Also, if you want to use the ServerCommand function, use this instead:
Code:
ServerCommand("sm_robot #%d", GetClientUserId(client));
Accidentally skipped a few small things.

- Jack

Last edited by Drixevel; 08-24-2013 at 06:48.
Drixevel is offline
keyboard1333
Senior Member
Join Date: Aug 2013
Old 08-24-2013 , 06:58   Re: Creating a Donation Menu that executes commands, error related to a variable
Reply With Quote #6

Shouldn't
PHP Code:
OnPluginStart() 
be
PHP Code:
public OnPluginStart() 
?

Seems to be working when I changed that.
Thanks heaps!!!
keyboard1333 is offline
Drixevel
AlliedModders Donor
Join Date: Sep 2009
Location: Somewhere headbangin'
Old 08-24-2013 , 07:04   Re: Creating a Donation Menu that executes commands, error related to a variable
Reply With Quote #7

Quote:
Originally Posted by keyboard1333 View Post
Shouldn't
PHP Code:
OnPluginStart() 
be
PHP Code:
public OnPluginStart() 
?

Seems to be working when I changed that.
Thanks heaps!!!
Yes, figured you would.

- Jack
Drixevel is offline
keyboard1333
Senior Member
Join Date: Aug 2013
Old 08-24-2013 , 07:06   Re: Creating a Donation Menu that executes commands, error related to a variable
Reply With Quote #8

Another quick question:
How can I stop the menu from closing (or reopen it) after you choose a command?
keyboard1333 is offline
Drixevel
AlliedModders Donor
Join Date: Sep 2009
Location: Somewhere headbangin'
Old 08-24-2013 , 07:34   Re: Creating a Donation Menu that executes commands, error related to a variable
Reply With Quote #9

Quote:
Originally Posted by keyboard1333 View Post
Another quick question:
How can I stop the menu from closing (or reopen it) after you choose a command?
Code:
DisplayMenu(menu, client, MENU_TIME_FOREVER);
Drixevel is offline
keyboard1333
Senior Member
Join Date: Aug 2013
Old 08-24-2013 , 07:55   Re: Creating a Donation Menu that executes commands, error related to a variable
Reply With Quote #10

The menu still closes after I choose an option.

E.G. "Evil Trail"
Toggles evil trail on me and closes the menu. I'd like it to stay open until you manually close it (by pressing 0).

---
Another quick (and probably slightly more complicated question):
How do I make the text in the menu Toggle.
E.g.
"Turn on Evil Trail"
*turns on*
"Turn off Evil Trail"
*turns off*

And another:
How can I display commands in the menu (adding commands to the menu) based on which flags the admin has?

And one more:
Can anyone link me to a tutorial describing how to use sub menus?
I'd like to add in a bit that has a "Resize" as the menu text that then goes into a sub menu with different sizes.

Last edited by keyboard1333; 08-24-2013 at 08:00.
keyboard1333 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 20:54.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode