Raised This Month: $12 Target: $400
 3% 

Menu selected item say client command


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Knate
New Member
Join Date: Aug 2013
Old 08-29-2013 , 08:58   Menu selected item say client command
Reply With Quote #1

Dear Users,
i want to write a simple plugin.

I created a simple menu like here: http://wiki.alliedmods.net/Menu_API_%28SourceMod%29

Now when a user selected an item, the plugin should write a command to console.
But not a simple "printtoconsole".

The command has to send like a client will do.


E.g.

I downloaded this plugin: https://forums.alliedmods.net/showthread.php?p=1803461
But it's very stupid to write a command to get a weapon.

My plugin should show a list of weapons and if the client select an item, the client should get this weapon.


So i need a command that write a command to console and a parameter which client selected the item.




I hope you understand ^^
Knate is offline
Dr. Greg House
Professional Troll,
Part-Time Asshole
Join Date: Jun 2010
Old 08-29-2013 , 09:10   Re: Menu selected item say client command
Reply With Quote #2

"FakeClientCommandEx".

Quote:
Originally Posted by Knate View Post
[...]But it's very stupid to write a command to get a weapon.[...]
Which is why you shouldn't do it.

Last edited by Dr. Greg House; 08-29-2013 at 09:11.
Dr. Greg House is offline
Knate
New Member
Join Date: Aug 2013
Old 08-29-2013 , 09:46   Re: Menu selected item say client command
Reply With Quote #3

Ok thanks, but i need to get the client.

E.g.
FakeClientCommandEx(client, "Test");

But public MenuHandler1(Handle:menu, MenuAction:action, param1, param2) has no client.
Only the client id in param1.

But this does not work.

Or have i need to include something else then sourcemod.inc ?
Knate is offline
Detonator
Junior Member
Join Date: Jun 2012
Old 08-29-2013 , 09:51   Re: Menu selected item say client command
Reply With Quote #4

Posting the code will help us help you.

Last edited by Detonator; 08-29-2013 at 09:51.
Detonator is offline
Knate
New Member
Join Date: Aug 2013
Old 08-29-2013 , 09:56   Re: Menu selected item say client command
Reply With Quote #5

Code:
#include <sourcemod>

public Plugin:myinfo =
{
    name = "GunGiver",
    author = "Knate",
    description = "Shows a menu and give you the selected weapon",
    version = "1.0",
    url = "http://www.sourcemod.net/"
};

public OnPluginStart()
{
    RegConsoleCmd("guns", Menu1);
}

public MenuHandler1(Handle:menu, MenuAction:action, param1, param2)
{
    /* If an option was selected, tell the client about the item. */
    if (action == MenuAction_Select)
    {
        new String:info[32];
        new bool:found = GetMenuItem(menu, param2, info, sizeof(info));
        PrintToConsole(param1, "You selected item: %d (found? %d info: %s)", param2, found, info);
        FakeClientCommandEx(param1, "say Test");
    }
    /* 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:Menu1(client, args)
{
    new Handle:menu = CreateMenu(MenuHandler1);
    SetMenuTitle(menu, "GunGiver 1.0 | Menu");
    AddMenuItem(menu, "AWP", "AWP");
    AddMenuItem(menu, "M4A1", "M4A1");
    SetMenuExitButton(menu, true);
    DisplayMenu(menu, client, 20);
 
    return Plugin_Handled;
}
Knate is offline
Detonator
Junior Member
Join Date: Jun 2012
Old 08-29-2013 , 10:31   Re: Menu selected item say client command
Reply With Quote #6

So what exactly isn't working(everything seems to work for me)?
Detonator is offline
Eden.Campo
Member
Join Date: Mar 2013
Old 08-29-2013 , 10:52   Re: Menu selected item say client command
Reply With Quote #7

Change FakeClientCommand to GivePlayerItem(client, info);
and change the menuitems to the weapon's name
:
AddMenuItem(menu, "weapon_awp", "AWP");
Eden.Campo is offline
Reply


Thread Tools
Display Modes

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 05:56.


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