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

Execute a plugin command from a menu.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
duce1nik
New Member
Join Date: Jul 2020
Old 07-04-2020 , 04:46   Execute a plugin command from a menu.
Reply With Quote #1

Hello,

How do I call a plugin command from a menu?

Below is example of what I have but it not working.


public Menu_Callback(Menu menu, MenuAction action, int param1, int param2){
switch (action)
{
case MenuAction_Select:
{
char item[32];
menu.GetItem(param2, item, sizeof(item));
if (StrEqual (item,"option1")){

ServerCommand("sm_strike");

}
else if(StrEqual(item, "option2")){
// Something else.
}
}
case MenuAction_End:
{
delete menu;
}
}
}
duce1nik is offline
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 07-04-2020 , 13:50   Re: Execute a plugin command from a menu.
Reply With Quote #2

Below is an example of what I use on my TF2 Server. The sounds are specific to TF2. Feel free to use/edit to suite your needs.

PHP Code:
#include <sourcemod>
#include <tf2_stocks>

#pragma semicolon 1

#define PLUGIN_VERSION "1.0"

#define CHEER    "/ambient_mp3/bumper_car_cheer3.mp3"
#define BOO        "/passtime/crowd_boo.wav" 

public Plugin:myinfo 
{
    
name "[TF2] Choose Your Prize",
    
author "PC Gamer",
    
description "Allow TF2 Players to Choose a Prize from Menu",
    
version PLUGIN_VERSION,
    
url "www.sourcemod.net"
}

public 
OnPluginStart()
{
    
LoadTranslations("common.phrases.txt");
    
RegAdminCmd("sm_prize"Command_PreprizeADMFLAG_SLAY"Present Prize Menu to Player");    
}

public 
OnMapStart()
{
    
PrecacheSound(CHEER);
    
PrecacheSound(BOO);    
}

public 
Action:Command_Preprize(clientargs)
{
    
decl String:arg1[32];
    if (
args 1)
    {
        
arg1 "@me";
    }
    else 
GetCmdArg(1arg1sizeof(arg1));
    new 
String:target_name[MAX_TARGET_LENGTH];
    new 
target_list[MAXPLAYERS], target_count;
    new 
bool:tn_is_ml;

    if ((
target_count ProcessTargetString(
                    
arg1,
                    
client,
                    
target_list,
                    
MAXPLAYERS,
                    
COMMAND_FILTER_ALIVE|(args COMMAND_FILTER_NO_IMMUNITY 0),
                    
target_name,
                    
sizeof(target_name),
                    
tn_is_ml)) <= 0)
    {
        
ReplyToTargetError(clienttarget_count);
        return 
Plugin_Handled;
    }
    for (new 
0target_counti++)
    {
        if (
IsClientInGame(target_list[i]))    
        {
            
Menu_Prize(target_list[i]);
            
PrintToChat(target_list[i], "Please Pick Your Prize");
        }
    }
    return 
Plugin_Handled;
}

public 
Action:Menu_Prize(client)
{
    new 
Handle:menu CreateMenu(PMenuMenuAction_Select MenuAction_End MenuAction_DisplayItem);
    
SetMenuTitle(menu"Pick Your Prize:");

    
AddMenuItem(menu"1001""Get 5,000 Upgrade Credits for YOU");
    
AddMenuItem(menu"1013""Give 4,000 Upgrade Credits for EVERYONE");    
    
AddMenuItem(menu"1003""Become the OverPowered Golden Knight Giant Robot");
    
AddMenuItem(menu"1012""Become the Magic StarFox");    
    
AddMenuItem(menu"1004""Become the Giant Yeti");
    
AddMenuItem(menu"1005""Become the Horseless Headless Horsemann");
    
AddMenuItem(menu"1014""Get 2 Minutes of Unlimited Ammo");    
    
AddMenuItem(menu"1006""Get a Health Boost, Defense Boost, and Bullet Resistance");
    
AddMenuItem(menu"1007""Get a Crit and Buff Boost");
    
AddMenuItem(menu"1008""Get 10 Fireball Spells");
    
AddMenuItem(menu"1009""Get a Random Powerup");
    
AddMenuItem(menu"1011""No Prize");    
    
DisplayMenu(menuclientMENU_TIME_FOREVER);
}    

public 
PMenu(Handle:menuMenuAction:actionparam1param2)
{
    switch (
action)
    {
    case 
MenuAction_Select:
        {
            
//Note: param1 is client, param2 is item

            
new String:item[64];
            
GetMenuItem(menuparam2itemsizeof(item));

            if (
StrEqual(item"1001"))
            {
                
ServerCommand("sm_addcash #%d 5000"GetClientUserId(param1));
                
PrintToChat(param1"Enjoy 5,000 upgrade credits!");
                
PrintToServer("Gave 5K to %N"param1);
                
EmitSoundToClient(param1CHEER);                
            }
            if (
StrEqual(item"1003"))
            {
                
ServerCommand("sm_begoldenknight #%d"GetClientUserId(param1));
                
PrintToChat(param1"Enjoy being the Overpowered Giant Golden Knight Robot!");
                
PrintToServer("Gave Golden Knight to %N"param1);
                
EmitSoundToClient(param1CHEER);            
            }
            if (
StrEqual(item"1004"))
            {
                
ServerCommand("sm_yeti #%d"GetClientUserId(param1));
                
PrintToChat(param1"Enjoy being a Giant Yeti!");
                
PrintToServer("Gave Yeti to %N"param1);
                
EmitSoundToClient(param1CHEER);            
            }
            if (
StrEqual(item"1005"))
            {
                
ServerCommand("sm_behhh #%d"GetClientUserId(param1));
                
PrintToChat(param1"Enjoy being the Horseless Headless Horsemann");
                
PrintToServer("Gave HHH to %N"param1);
                
EmitSoundToClient(param1CHEER);            
            }
            if (
StrEqual(item"1006"))
            {
                
ServerCommand("sm_addcond #%d 73 5"GetClientUserId(param1)); 
                
ServerCommand("sm_addcond #%d 61 20"GetClientUserId(param1));
                
ServerCommand("sm_addcond #%d 26 20"GetClientUserId(param1));
                
PrintToChat(param1"Enjoy a Health Boost, Defense Boost, and Bullet Resistance!");
                
PrintToServer("Gave Health Defense Bullet Boost to %N"param1);
                
EmitSoundToClient(param1CHEER);            
            }
            if (
StrEqual(item"1007"))
            {
                
ServerCommand("sm_addcond #%d 26 10"GetClientUserId(param1)); 
                
ServerCommand("sm_addcond #%d 29 10"GetClientUserId(param1));
                
ServerCommand("sm_addcond #%d 46 10"GetClientUserId(param1));
                
ServerCommand("sm_addcond #%d 16 10"GetClientUserId(param1));
                
ServerCommand("sm_addcond #%d 6 10"GetClientUserId(param1));
                
PrintToChat(param1"Enjoy a Crit and Buff Boost");
                
PrintToServer("Gave Crit and Buff Boost to %N"param1);
                
EmitSoundToClient(param1CHEER);            
            }            
            if (
StrEqual(item"1008"))
            {
                
ServerCommand("sm_spellbook #%d"GetClientUserId(param1));
                
PrintToChat(param1"Enjoy 10 Fireball Spells!");
                
PrintToServer("Gave Spells to %N"param1);
                
EmitSoundToClient(param1CHEER);            
            }
            else if (
StrEqual(item"1009"))
            {
                
ServerCommand("sm_randompowerup #%d"GetClientUserId(param1));
                
PrintToChat(param1"Enjoy your Random Powerup!");
                
PrintToServer("Gave Powerup to %N"param1);
                
EmitSoundToClient(param1CHEER);            
            }
            else if (
StrEqual(item"1011"))
            {
                
PrintToChat(param1"No Prize for You.");
                
PrintToServer("Gave No Prize to %N"param1);
                
EmitSoundToClient(param1BOO);            
            }
            if (
StrEqual(item"1012"))
            {
                
ServerCommand("sm_bemagicfox #%d"GetClientUserId(param1));
                
PrintToChat(param1"Enjoy being the Magic StarFox!");
                
PrintToServer("Gave Magic StarFox to %N"param1);
                
EmitSoundToClient(param1CHEER);            
            }
            if (
StrEqual(item"1013"))
            {
                
ServerCommand("sm_addcash @all 4000");
                
PrintToChatAll("%N Gave 4,000 upgrade credits to Everyone"param1);
                
PrintToServer("%N Gave 4K to Everyone"param1);
                
EmitSoundToClient(param1CHEER);                
            }
            if (
StrEqual(item"1014"))
            {
                
ServerCommand("sm_aia2 #%d 125"GetClientUserId(param1));
                
PrintToChat(param1"Enjoy 2 Minutes of Unlimited Ammo!");
                
PrintToServer("%N got 2 mins of unlimited ammo"param1);
                
EmitSoundToClient(param1CHEER);                
            }
        }
    }

Here's a second TF2 example. This plugin uses/shares the credits from the Zephyrus store plugin.

PHP Code:
#include <sourcemod>
#include <tf2_stocks>

#pragma semicolon 1

#define PLUGIN_VERSION "1.0"

#define CHEER    "/ambient_mp3/bumper_car_cheer3.mp3"
#define BOO        "/passtime/crowd_boo.wav" 

native Store_SetClientCredits(clientcredits);
native Store_GetClientCredits(client);

public 
Plugin:myinfo 
{
    
name "Shopping Menu With Store Credits",
    
author "PC Gamer",
    
description "Allow Players to buy items from menu using Store credits",
    
version PLUGIN_VERSION,
    
url "www.sourcemod.com"
}

public 
OnPluginStart()
{
    
LoadTranslations("common.phrases.txt");
    
RegConsoleCmd("sm_store2"Command_Preshop"Present Shopping Menu to Player");
    
RegConsoleCmd("sm_shop2"Command_Preshop"Present Shopping Menu to Player");
    
RegAdminCmd("sm_showcredits"Command_ShowCreditsADMFLAG_SLAY"Show Credits");    
}

public 
OnMapStart()
{
    
PrecacheSound(CHEER);
    
PrecacheSound(BOO);    
}

public 
Action:Command_ShowCredits(clientargs)
{
    
decl String:arg1[32];
    if (
args 1)
    {
        
ReplyToCommand(client"[SM] Usage : sm_showcredits <target>");
        return 
Plugin_Handled;
    }
    else 
GetCmdArg(1arg1sizeof(arg1));
    new 
String:target_name[MAX_TARGET_LENGTH];
    new 
target_list[MAXPLAYERS], target_count;
    new 
bool:tn_is_ml;

    if ((
target_count ProcessTargetString(
                    
arg1,
                    
client,
                    
target_list,
                    
MAXPLAYERS,
                    
COMMAND_FILTER_ALIVE|(args COMMAND_FILTER_NO_IMMUNITY 0),
                    
target_name,
                    
sizeof(target_name),
                    
tn_is_ml)) <= 0)
    {
        
ReplyToTargetError(clienttarget_count);
        return 
Plugin_Handled;
    }
    for (new 
0target_counti++)
    {
        if (
IsClientInGame(target_list[i]))    
        {
            
int CreditAmt Store_GetClientCredits(target_list[i]);
            
PrintToChat(client"%N has %d Credits"target_list[i], CreditAmt);
        }
    }
    return 
Plugin_Handled;
}

public 
Action:Command_Preshop(clientargs)
{
    
decl String:arg1[32];
    if (
args 1)
    {
        
arg1 "@me";
    }
    else 
GetCmdArg(1arg1sizeof(arg1));
    new 
String:target_name[MAX_TARGET_LENGTH];
    new 
target_list[MAXPLAYERS], target_count;
    new 
bool:tn_is_ml;

    if ((
target_count ProcessTargetString(
                    
arg1,
                    
client,
                    
target_list,
                    
MAXPLAYERS,
                    
COMMAND_FILTER_ALIVE|(args COMMAND_FILTER_NO_IMMUNITY 0),
                    
target_name,
                    
sizeof(target_name),
                    
tn_is_ml)) <= 0)
    {
        
ReplyToTargetError(clienttarget_count);
        return 
Plugin_Handled;
    }
    for (new 
0target_counti++)
    {
        if (
IsClientInGame(target_list[i]))    
        {
            
Menu_Prize(target_list[i]);
            
PrintToChat(target_list[i], "Please Pick Your Item");
        }
    }
    return 
Plugin_Handled;
}

public 
Action:Menu_Prize(client)
{
    new 
Handle:menu CreateMenu(PMenuMenuAction_Select MenuAction_End MenuAction_DisplayItem);
    
SetMenuTitle(menu"Spend your Store Credits on These Items:");

    
AddMenuItem(menu"1000""View my Store Credits");
    
AddMenuItem(menu"1001""10 Store Credits - Slay All the Bots");
    
AddMenuItem(menu"1006""10 Store Credits - Get Health Boost, Defense Boost, and Bullet Resistance");
    
AddMenuItem(menu"1007""10 Store Credits - Get Crit and Buff Boost");
    
AddMenuItem(menu"1008""10 Store Credits - Get 10 Fireball Spells");    
    
AddMenuItem(menu"1009""10 Store Credits - Get Random Powerup");
    
AddMenuItem(menu"1027""10 Store Credits - Gamble to Win or Lose 10 Credits");    
    
AddMenuItem(menu"1023""10 Store Credits - Give all Players a Random Good RTD Perk");
    
AddMenuItem(menu"1005""10 Store Credits - Become the Horseless Headless Horsemann");
    
AddMenuItem(menu"1030""20 Store Credits - Become An Angry Giant Robot");
    
AddMenuItem(menu"1024""20 Store Credits - Give all Players 10 Fireball Spells");        
    
AddMenuItem(menu"1011""20 Store Credits - Give all Players a Random Gift");    
    
AddMenuItem(menu"1025""20 Store Credits - Remove all Spy Bots");    
    
AddMenuItem(menu"1026""20 Store Credits - Remove all Medic Bots");
    
AddMenuItem(menu"1033""30 Store Credits - Become the Mighty Samurai Warrior");    
    
AddMenuItem(menu"1020""30 Store Credits - Get Homing Projectiles RTD Perk");    
    
AddMenuItem(menu"1003""40 Store Credits - Become an OverPowered Giant Robot");
    
AddMenuItem(menu"1004""40 Store Credits - Become a Giant Yeti");
    
AddMenuItem(menu"1031""40 Store Credits - Become a Giant Ricochet Soldier Robot");
    
AddMenuItem(menu"1032""40 Store Credits - Become a Giant Ricochet Pyro Robot");        
    
AddMenuItem(menu"1013""40 Store Credits - Give Uber Upgrades New Weapons Menu for All Players");    
    
AddMenuItem(menu"1015""50 Store Credits - Get 2 Minutes of Unlimited Ammo");    
    
AddMenuItem(menu"1016""50 Store Credits - Get Power Play Perk");
    
AddMenuItem(menu"1018""50 Store Credits - Gamble to Win or Lose 50 Credits");
    
AddMenuItem(menu"1012""50 Store Credits - Give all Players 50K Cash");        
    
AddMenuItem(menu"1017""60 Store Credits - Give all Players a Mega Cash Gift");
    
AddMenuItem(menu"1019""100 Store Credits - Gamble to Win or Lose 100 Credits");
    
AddMenuItem(menu"1034""300 Store Credits - Become The WolfMann BOSS");    
    
AddMenuItem(menu"1021""500 Store Credits - Become Merasmus the Wizard BOSS");
    
AddMenuItem(menu"1022""500 Store Credits - Become Monoculus BOSS");    
    
AddMenuItem(menu"2000""No Purchase");    
    
DisplayMenu(menuclientMENU_TIME_FOREVER);
}    

public 
PMenu(Handle:menuMenuAction:actionparam1param2)
{
    switch (
action)
    {
    case 
MenuAction_Select:
        {
            
//param1 is client, param2 is item

            
new String:item[64];
            
GetMenuItem(menuparam2itemsizeof(item));

            
int mycredits Store_GetClientCredits(param1);
            
            if (
StrEqual(item"1000"))
            {
                
PrintToChat(param1"You have %d store credits available to spend"mycredits);
            }
            if (
StrEqual(item"1001"))
            {
                if (
mycredits<10)
                {
                    
PrintToChat(param1"You don't have enough store credits available to spend");
                }
                else
                {
                    
Store_SetClientCredits(param1mycredits 10);
                    
ServerCommand("sm_slay @bots");
                    
PrintToChatAll("%N Used !store2 to Slay all the Bots"param1);
                    
PrintToServer("%N Paid to Slay all the Bots"param1);
                    
EmitSoundToClient(param1CHEER);
                }
            }
            if (
StrEqual(item"1003"))
            {
                if (
mycredits<40)
                {
                    
PrintToChat(param1"You don't have enough store credits available to spend");
                }
                else
                {            
                    
Store_SetClientCredits(param1mycredits 40);
                    
ServerCommand("sm_beop #%d"GetClientUserId(param1));
                    
PrintToChat(param1"Enjoy being OverPowered!");
                    
PrintToServer("%N Paid to become OverPowered"param1);
                    
EmitSoundToClient(param1CHEER);
                }
            }
            if (
StrEqual(item"1004"))
            {
                if (
mycredits<40)
                {
                    
PrintToChat(param1"You don't have enough store credits available to spend");
                }
                else
                {
                    
Store_SetClientCredits(param1mycredits 40);
                    
ServerCommand("sm_yeti #%d"GetClientUserId(param1));
                    
PrintToChat(param1"Enjoy being a Giant Yeti!");
                    
PrintToServer("%N Paid to become Yeti"param1);
                    
EmitSoundToClient(param1CHEER);
                }
            }
            if (
StrEqual(item"1005"))
            {
                if (
mycredits<10)
                {
                    
PrintToChat(param1"You don't have enough store credits available to spend");
                }
                else
                {            
                    
Store_SetClientCredits(param1mycredits 10);
                    
ServerCommand("sm_behhh #%d"GetClientUserId(param1));
                    
PrintToChat(param1"Enjoy being the Horseless Headless Horsemann");
                    
PrintToServer("%N Paid to become HHH"param1);
                    
EmitSoundToClient(param1CHEER);
                }
            }
            if (
StrEqual(item"1006"))
            {
                if (
mycredits<10)
                {
                    
PrintToChat(param1"You don't have enough store credits available to spend");
                }
                else
                {            
                    
Store_SetClientCredits(param1mycredits 10);
                    
ServerCommand("sm_addcond #%d 73 5"GetClientUserId(param1)); 
                    
ServerCommand("sm_addcond #%d 61 20"GetClientUserId(param1));
                    
ServerCommand("sm_addcond #%d 26 20"GetClientUserId(param1));
                    
PrintToChat(param1"Enjoy a Health Boost, Defense Boost, and Bullet Resistance!");
                    
PrintToServer("%N Paid for Health Defense Bullet Boost"param1);
                    
EmitSoundToClient(param1CHEER);
                }
            }
            if (
StrEqual(item"1007"))
            {
                if (
mycredits<10)
                {
                    
PrintToChat(param1"You don't have enough store credits available to spend");
                }
                else
                {            
                    
Store_SetClientCredits(param1mycredits 10);            
                    
ServerCommand("sm_addcond #%d 26 10"GetClientUserId(param1)); 
                    
ServerCommand("sm_addcond #%d 29 10"GetClientUserId(param1));
                    
ServerCommand("sm_addcond #%d 46 10"GetClientUserId(param1));
                    
ServerCommand("sm_addcond #%d 16 10"GetClientUserId(param1));
                    
ServerCommand("sm_addcond #%d 6 10"GetClientUserId(param1));
                    
PrintToChat(param1"Enjoy a Crit and Buff Boost");
                    
PrintToServer("%N Paid for Crit and Buff Boost"param1);
                    
EmitSoundToClient(param1CHEER);
                }
            }            
            if (
StrEqual(item"1008"))
            {
                if (
mycredits<10)
                {
                    
PrintToChat(param1"You don't have enough store credits available to spend");
                }
                else
                {            
                    
Store_SetClientCredits(param1mycredits 10);            
                    
ServerCommand("sm_spellbook #%d"GetClientUserId(param1));
                    
PrintToChat(param1"Enjoy 10 Fireball Spells!");
                    
PrintToServer("%N Paid for Spells"param1);
                    
EmitSoundToClient(param1CHEER);
                }
            }
            else if (
StrEqual(item"1009"))
            {
                if (
mycredits<10)
                {
                    
PrintToChat(param1"You don't have enough store credits available to spend");
                }
                else
                {            
                    
Store_SetClientCredits(param1mycredits 10);
                    
ServerCommand("sm_randompowerup #%d"GetClientUserId(param1));
                    
PrintToChat(param1"Enjoy your Random Powerup!");
                    
PrintToServer("%N Paid for Random Powerup"param1);
                    
EmitSoundToClient(param1CHEER);
                }
            }
            else if (
StrEqual(item"1011"))
            {
                if (
mycredits<20)
                {
                    
PrintToChat(param1"You don't have enough store credits available to spend");
                }
                else
                {            
                    
Store_SetClientCredits(param1mycredits 20);            
                    
ServerCommand("sm_randomgift2");
                    
PrintToChatAll("%N Used !store2 to give everyone a Random Gift!!"param1);
                    
PrintToServer("%N Paid for Random Gift"param1);
                    
EmitSoundToClient(param1CHEER);
                }
            }
            else if (
StrEqual(item"1012"))
            {
                if (
mycredits<50)
                {
                    
PrintToChat(param1"You don't have enough store credits available to spend");
                }
                else
                {            
                    
Store_SetClientCredits(param1mycredits 50);            
                    
ServerCommand("exec money");
                    
PrintToChatAll("%N Used !store2 to give everyone a Jackpot!!"param1);
                    
PrintToServer("%N Paid for Jackpot"param1);
                    
EmitSoundToClient(param1CHEER);
                }
            }
            else if (
StrEqual(item"1013"))
            {
                if (
mycredits<40)
                {
                    
PrintToChat(param1"You don't have enough store credits available to spend");
                }
                else
                {            
                    
Store_SetClientCredits(param1mycredits 40);            
                    
ServerCommand("exec newweaponon");
                    
PrintToChatAll("%N Used !store2 to enable Uber Upgrades New Weapons!!"param1);
                    
PrintToServer("%N Paid for New Weapons"param1);
                    
EmitSoundToAll(CHEER);
                }
            }
            else if (
StrEqual(item"1015"))
            {
                if (
mycredits<50)
                {
                    
PrintToChat(param1"You don't have enough store credits available to spend");
                }
                else
                {            
                    
Store_SetClientCredits(param1mycredits 50);            
                    
ServerCommand("sm_aia2 #%d 125"GetClientUserId(param1));
                    
PrintToChat(param1"Enjoy 2 Minutes of Unlimited Ammo!");
                    
PrintToServer("%N Paid for 2 mins of unlimited ammo"param1);
                    
EmitSoundToClient(param1CHEER);
                }
            }
            else if (
StrEqual(item"1016"))
            {
                if (
mycredits<50)
                {
                    
PrintToChat(param1"You don't have enough store credits available to spend");
                }
                else
                {            
                    
Store_SetClientCredits(param1mycredits 50);            
                    
ServerCommand("sm_forcertd #%d powerplay"GetClientUserId(param1));
                    
PrintToChat(param1"Enjoy the PowerPlay perk!");
                    
PrintToServer("%N Paid for PowerPlay"param1);
                    
EmitSoundToClient(param1CHEER);
                }
            }
            else if (
StrEqual(item"1017"))
            {
                if (
mycredits<60)
                {
                    
PrintToChat(param1"You don't have enough store credits available to spend");
                }
                else
                {            
                    
Store_SetClientCredits(param1mycredits 60);            
                    
ServerCommand("exec v6");
                    
PrintToChatAll("%N Used !store2 to give everyone a Mega Gift!!"param1);
                    
PrintToServer("%N Paid for Mega Gift"param1);
                    
EmitSoundToClient(param1CHEER);
                }
            }
            else if (
StrEqual(item"1018"))
            {
                if (
mycredits<50)
                {
                    
PrintToChat(param1"You don't have enough store credits available to spend");
                }
                else
                {            
                    
int MyNumber GetRandomInt(1,100);
                    if(
MyNumber 50)
                    {
                        
PrintToChat(param1"You Just Gambled 50 Credits and you WON 50 Credits!");
                        
Store_SetClientCredits(param1mycredits 50);
                        
PrintToServer("%N Gambled 50 Credits and Won"param1);                        
                        
EmitSoundToClient(param1CHEER);                        
                    } 
                    else
                    {
                        
PrintToChat(param1"You Just Gambled 50 Credits and you LOST 50 Credits!");
                        
Store_SetClientCredits(param1mycredits 50);
                        
PrintToServer("%N Gambled 50 Credits and Lost"param1);                            
                        
EmitSoundToClient(param1BOO);                        
                    }
                }
            }
            else if (
StrEqual(item"1019"))
            {
                if (
mycredits<100)
                {
                    
PrintToChat(param1"You don't have enough store credits available to spend");
                }
                else
                {            
                    
int MyNumber GetRandomInt(1,100);
                    if(
MyNumber 50)
                    {
                        
PrintToChat(param1"You Gambled 100 Credits and you WON 100 Credits!");
                        
Store_SetClientCredits(param1mycredits 100);
                        
PrintToServer("%N Gambled 100 Credits and Won"param1);                        
                        
EmitSoundToClient(param1CHEER);                        
                    } 
                    else
                    {
                        
PrintToChat(param1"You Gambled 100 Credits and you LOST 100 Credits!");
                        
Store_SetClientCredits(param1mycredits 100);
                        
PrintToServer("%N Gambled 100 Credits and Lost"param1);                            
                        
EmitSoundToClient(param1BOO);                        
                    }
                }
            }
            else if (
StrEqual(item"1020"))
            {
                if (
mycredits<30)
                {
                    
PrintToChat(param1"You don't have enough store credits available to spend");
                }
                else
                {            
                    
Store_SetClientCredits(param1mycredits 30);            
                    
ServerCommand("sm_forcertd #%d homingprojectiles"GetClientUserId(param1));
                    
PrintToChat(param1"Enjoy the Homing Projectiles RTD perk!");
                    
PrintToServer("%N Paid for Homing Projectiles RTD perk"param1);
                    
EmitSoundToClient(param1CHEER);
                }
            }
            else if (
StrEqual(item"1021"))
            {
                if (
mycredits<500)
                {
                    
PrintToChat(param1"You don't have enough store credits available to spend");
                }
                else
                {            
                    
Store_SetClientCredits(param1mycredits 500);            
                    
ServerCommand("sm_bewizard #%d"GetClientUserId(param1));
                    
PrintToChat(param1"Enjoy being Merasmus the Wizard!");
                    
PrintToServer("%N Paid for Merasmus Boss"param1);
                    
EmitSoundToClient(param1CHEER);
                }
            }
            else if (
StrEqual(item"1022"))
            {
                if (
mycredits<500)
                {
                    
PrintToChat(param1"You don't have enough store credits available to spend");
                }
                else
                {            
                    
Store_SetClientCredits(param1mycredits 500);            
                    
ServerCommand("sm_bte #%d"GetClientUserId(param1));
                    
PrintToChat(param1"Enjoy being the Monoculus!");
                    
PrintToServer("%N Paid for Monoculus Boss"param1);
                    
EmitSoundToClient(param1CHEER);
                }
            }
            else if (
StrEqual(item"1023"))
            {
                if (
mycredits<10)
                {
                    
PrintToChat(param1"You don't have enough store credits available to spend");
                }
                else
                {            
                    
Store_SetClientCredits(param1mycredits 10);            
                    
ServerCommand("sm_forcertd @humans good"GetClientUserId(param1));
                    
PrintToChatAll("%N Used !store2 to give all Players a Random Good Perk!"param1);
                    
PrintToServer("%N Paid for Good Perk for Players"param1);
                    
EmitSoundToClient(param1CHEER);
                }
            }            
            else if (
StrEqual(item"2000"))
            {
                
PrintToChat(param1"No Prize for You.");
                
PrintToServer("Gave Spells to %N"param1);
                
EmitSoundToClient(param1BOO);            
            }
            if (
StrEqual(item"1024"))
            {
                if (
mycredits<20)
                {
                    
PrintToChat(param1"You don't have enough store credits available to spend");
                }
                else
                {            
                    
Store_SetClientCredits(param1mycredits 20);            
                    
ServerCommand("sm_spellbook @humans");
                    
PrintToChatAll("%N Used !store2 to give all Players 10 Fireball Spells!"param1);
                    
PrintToServer("%N Paid for 10 Fireball Spells for all Players"param1);
                    
EmitSoundToClient(param1CHEER);
                }
            }
            if (
StrEqual(item"1025"))
            {
                if (
mycredits<20)
                {
                    
PrintToChat(param1"You don't have enough store credits available to spend");
                }
                else
                {            
                    
Store_SetClientCredits(param1mycredits 20);            
                    
ServerCommand("exec nospybots");
                    
PrintToChatAll("%N Used !store2 to Remove all Spy Bots"param1);
                    
PrintToServer("%N Paid to Remove Spy Bots"param1);
                    
EmitSoundToClient(param1CHEER);
                }
            }
            if (
StrEqual(item"1026"))
            {
                if (
mycredits<20)
                {
                    
PrintToChat(param1"You don't have enough store credits available to spend");
                }
                else
                {            
                    
Store_SetClientCredits(param1mycredits 20);            
                    
ServerCommand("exec nomedicbots");
                    
PrintToChatAll("%N Used !store2 to Remove all Medic Bots"param1);
                    
PrintToServer("%N Paid to Remove Medic Bots"param1);
                    
EmitSoundToClient(param1CHEER);
                }
            }
            else if (
StrEqual(item"1027"))
            {
                if (
mycredits<10)
                {
                    
PrintToChat(param1"You don't have enough store credits available to spend");
                }
                else
                {            
                    
int MyNumber GetRandomInt(1,100);
                    if(
MyNumber 50)
                    {
                        
PrintToChat(param1"You Just Gambled 10 Credits and you WON 10 Credits!");
                        
Store_SetClientCredits(param1mycredits 10);
                        
PrintToServer("%N Gambled 10 Credits and Won"param1);                        
                        
EmitSoundToClient(param1CHEER);                        
                    } 
                    else
                    {
                        
PrintToChat(param1"You Just Gambled 10 Credits and you LOST 10 Credits!");
                        
Store_SetClientCredits(param1mycredits 10);
                        
PrintToServer("%N Gambled 10 Credits and Lost"param1);                            
                        
EmitSoundToClient(param1BOO);                        
                    }
                }
            }
            else if (
StrEqual(item"1030"))
            {
                if (
mycredits<20)
                {
                    
PrintToChat(param1"You don't have enough store credits available to spend");
                }
                else
                {            
                    
Store_SetClientCredits(param1mycredits 20);            
                    
ServerCommand("sm_beangryrobot #%d"GetClientUserId(param1));
                    
PrintToChat(param1"Enjoy being the Angry Robot!");
                    
PrintToServer("%N Paid for Angry Robot"param1);
                    
EmitSoundToClient(param1CHEER);
                }
            }
            else if (
StrEqual(item"1031"))
            {
                if (
mycredits<40)
                {
                    
PrintToChat(param1"You don't have enough store credits available to spend");
                }
                else
                {            
                    
Store_SetClientCredits(param1mycredits 40);            
                    
ServerCommand("sm_bericochet #%d"GetClientUserId(param1));
                    
PrintToChat(param1"Enjoy being the Giant Ricochet Soldier Robot!");
                    
PrintToServer("%N Paid for Giant Ricochet Soldier Robot"param1);
                    
EmitSoundToClient(param1CHEER);
                }                
            }
            else if (
StrEqual(item"1032"))
            {
                if (
mycredits<40)
                {
                    
PrintToChat(param1"You don't have enough store credits available to spend");
                }
                else
                {            
                    
Store_SetClientCredits(param1mycredits 40);            
                    
ServerCommand("sm_bericochetpyro #%d"GetClientUserId(param1));
                    
PrintToChat(param1"Enjoy being the Giant Ricochet Pyro Robot!");
                    
PrintToServer("%N Paid for Giant Ricochet Pyro Robot"param1);
                    
EmitSoundToClient(param1CHEER);
                }                
            }
            else if (
StrEqual(item"1033"))
            {
                if (
mycredits<20)
                {
                    
PrintToChat(param1"You don't have enough store credits available to spend");
                }
                else
                {            
                    
Store_SetClientCredits(param1mycredits 20);            
                    
ServerCommand("sm_besam #%d"GetClientUserId(param1));
                    
PrintToChat(param1"Enjoy being the Mighty Samurai Warrior!");
                    
PrintToServer("%N Paid for the Mighty Samurai Warrior"param1);
                    
EmitSoundToClient(param1CHEER);
                }                
            }
            else if (
StrEqual(item"1034"))
            {
                if (
mycredits<500)
                {
                    
PrintToChat(param1"You don't have enough store credits available to spend");
                }
                else
                {            
                    
Store_SetClientCredits(param1mycredits 500);            
                    
ServerCommand("sm_bewolfman #%d"GetClientUserId(param1));
                    
PrintToChat(param1"Enjoy being the WolfMann BOSS!");
                    
PrintToServer("%N Paid for WolMann Boss"param1);
                    
EmitSoundToClient(param1CHEER);
                }
            }
            else if (
StrEqual(item"1035"))
            {
                if (
mycredits<300)
                {
                    
PrintToChat(param1"You don't have enough store credits available to spend");
                }
                else
                {            
                    
Store_SetClientCredits(param1mycredits 300);            
                    
ServerCommand("sm_beskeletonking #%d"GetClientUserId(param1));
                    
PrintToChat(param1"Enjoy being the Skeleton King BOSS!");
                    
PrintToServer("%N Paid for Skeleton King Boss"param1);
                    
EmitSoundToClient(param1CHEER);
                }
            }            
        }
    }


Last edited by PC Gamer; 07-04-2020 at 14:46.
PC Gamer is offline
duce1nik
New Member
Join Date: Jul 2020
Old 07-05-2020 , 03:17   Re: Execute a plugin command from a menu.
Reply With Quote #3

PC Gamer,

Thank you for your reply.

It still not working for me.

My goal is to create a menu and call command for plugin that I installed.

For example, I installed F-18 Airstrike ( https://forums.alliedmods.net/showthread.php?t=187567 ). If I typed sm_strike in the console it will bring up the Air Strike Menu. I would like to call the same command from the my own menu instead of typing it console.


I confirmed the if statement is getting hit becuase ServerCommand("sm_slap Player1"); work in that statement, but ServerCommand("sm_strike"); is not working.


Please see code below.

PHP Code:


public PMenu(Handle:menuMenuAction:actionparam1param2)
{
switch (
action)
    {
    case 
MenuAction_Select:
        {
            new 
String:item[64];
            
GetMenuItem(menuparam2itemsizeof(item));
            if (
StrEqual(item,"Option1"))
            {
                
//this DO NOT work when call from the menu
                
ServerCommand("sm_strike");
                
                
//This work when call from the menu.
                
ServerCommand("sm_slap Player1");
            }
            
        }
        case 
MenuAction_End:
        {
            
delete menu;
        }
    }


duce1nik is offline
Cruze
Veteran Member
Join Date: May 2017
Old 07-05-2020 , 04:33   Re: Execute a plugin command from a menu.
Reply With Quote #4

Maybe because in sm_strike, there's a condition given like:
Code:
if(!client)
return Plugin_Handled;
__________________
Taking paid private requests! Add me on steam/discord!
AlliedModders Releases | Github | Private Plugins | PayPal | Steam | My Discord Server
Cruze is offline
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 07-05-2020 , 15:32   Re: Execute a plugin command from a menu.
Reply With Quote #5

If you need the player to issue the sm_strike command and the player has access to it you could use the FakeClientCommand like this:

PHP Code:
            if (StrEqual(item,"Option1"))
            {
                
//this works when called from the menu
                
FakeClientCommand(param1"sm_strike");
                
                
//This also works when called from the menu.
                
ServerCommand("sm_slap Player1");
            } 
PC Gamer is offline
duce1nik
New Member
Join Date: Jul 2020
Old 07-06-2020 , 00:00   Re: Execute a plugin command from a menu.
Reply With Quote #6

Cruze - Thank you for your reply.

PC Gamer- FakeClientCommand() worked. Thanks you.
duce1nik 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 19:12.


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