AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Is this would work ? (https://forums.alliedmods.net/showthread.php?t=106002)

DoviuX 10-10-2009 15:09

Is this would work ?
 
PHP Code:

#include <amxmodx>
#include <amxmisc>
#define PLUGIN "Server Info"
#define AUTHOR "DoviuX"
#define VERSION "0.1"
/*================================================================================
 [New Const's]
=================================================================================*/
new const gMotdInfo[] = { "ServerInfo/Motd.wav" }
/*================================================================================
 [Precache]
=================================================================================*/
public plugin_precache() 
{
  
precache_sound(gMotdInfo);
}
/*================================================================================
 [Plugin start]
=================================================================================*/
public plugin_init()
{
        
register_pluginPLUGINVERSIONAUTHOR );
 
register_clcmd("say /ServerInfo""Info")
 
register_clcmd("say_team /ServerInfo""Info")
}
public 
Info(id)
{
 new 
menu menu_create("\yServer Info Menu""menu_handler")
 
 
menu_additem(menu"Admin Prices""1"0)
 
menu_additem(menu"Mod Info""2"0)
 
menu_additem(menu"Info About Server""3"0)
 
 
menu_setprop(menuMPROP_EXITMEXIT_ALL)
 
menu_display(idmenu0)
}
public 
menu_handler(idmenuitem)
{
 if (
item == MENU_EXIT)
 {
  
menu_destroy(menu)
  return 
PLUGIN_HANDLED
 
}
 
 new 
data[6], iName[64]
 new 
accesscallback
 menu_item_getinfo
(menuitemaccessdata5iName63callback)
 
 new 
key str_to_num(data)
 
 switch(
key)
 {
  case 
1
  {
   {
      
show_motd(id"AdminPrices.txt""Prices")
             
client_cmd(0,"spk %s"gMotdInfo)
      return 
PLUGIN_CONTINUE
   

  }
  case 
2
  {
   {
      
show_motd(id"ModInfo.txt""Mod")
             
client_cmd(0,"spk %s"gMotdInfo)
      return 
PLUGIN_CONTINUE
   
}
  }
  case 
3
  {
   {
      
show_motd(id"ServerInfo.txt""Info")
             
client_cmd(0,"spk %s"gMotdInfo)
      return 
PLUGIN_CONTINUE
   
}
  }
 }
 
menu_destroy(menu)
 return 
PLUGIN_HANDLED;



fysiks 10-10-2009 16:09

Re: Is this would work ?
 
Well . . . does it work? If it works then it should work. If it doesn't work then it shouldn't work.

vitorrd 10-10-2009 17:41

Re: Is this would work ?
 
Quote:

Originally Posted by fysiks (Post 957882)
Well . . . does it work? If it works then it should work. If it doesn't work then it shouldn't work.

+Karma, thanks for the precise answer.

DoviuX 10-11-2009 01:41

Re: Is this would work ?
 
Ok it works how can i make that menu wont destroy when i press to show motd ?

shadow.hk 10-11-2009 02:19

Re: Is this would work ?
 
Well some of your code is uneccessary... Like the double parentheses for each 'case' in the menu handler.

PHP Code:

case 3
{
    {
        
show_motd(id"ServerInfo.txt""Info")
        
client_cmd(0,"spk %s"gMotdInfo)
        return 
PLUGIN_CONTINUE;
    }


-->

PHP Code:

case 3
{
    
show_motd(id"ServerInfo.txt""Info")
    
client_cmd(0,"spk %s"gMotdInfo)
    return 
PLUGIN_CONTINUE;


If you want to make it open after they've selected something, then you need to remove the 'return PLUGIN_CONTINUE' from each case and replace 'menu_destroy(menu)' from the end of the function with 'Info(id)'

PHP Code:

switch(key)
{
    case 
1:
    {
        
show_motd(id"AdminPrices.txt""Prices")
        
client_cmd(0,"spk %s"gMotdInfo)
    }
    case 
2:
    {
        
show_motd(id"ModInfo.txt""Mod")
        
client_cmd(0,"spk %s"gMotdInfo)
    }
    case 
3:
    {
        
show_motd(id"ServerInfo.txt""Info")
        
client_cmd(0,"spk %s"gMotdInfo)
    }
}
    
Info(id);
return 
PLUGIN_HANDLED


fysiks 10-11-2009 02:39

Re: Is this would work ?
 
@shadow

Because the menu is created in Info(id) you still need to destroy the menu in the menu handler.

shadow.hk 10-11-2009 02:41

Re: Is this would work ?
 
Quote:

Originally Posted by fysiks (Post 958293)
Because the menu is created in Info(id) you still need to destroy the menu in the menu handler.

So...

PHP Code:

menu_destroy(menu);
Info(id);
return 
PLUGIN_HANDLED

:|

fysiks 10-11-2009 02:42

Re: Is this would work ?
 
Yep.

shadow.hk 10-11-2009 02:52

Re: Is this would work ?
 
Well I wrote up a new version of your plugin with explanations in it. I got the Info(id) wrong so I guess fysiks could correct me if I'm wrong here as well...

PHP Code:

#include <amxmodx>

// This shows how many motd's you have
#define MAX_MOTDS 3

// You don't need the parentheses for this, it's one item
new const g_MotdSound[] = "ServerInfo/Motd.wav";

// This is the MOTD header
new const g_MotdName[MAX_MOTDS][] =
{
    
"Admin Prices",        // 0
    
"Mod Info",        // 1
    
"Server Info"        // 2
};

// This is the MOTD path
new const g_MotdPath[MAX_MOTDS][] =
{
    
"AdminPrices.txt",    // 0
    
"ModInfo.txt",        // 1
    
"ServerInfo.txt"    // 2
};

public 
plugin_precache() 
{
    
precache_sound(g_MotdSound);
}

public 
plugin_init()
{
    
// Usually you don't need to create #define's for this, just enter
    //  it into the register_plugin
    
register_plugin("Server Info""0.1""DoviuX");
    
    
// Personally I would remove the capitals, but it's up to you...
    
register_clcmd("say /ServerInfo",    "InfoMenu");
    
register_clcmd("say_team /ServerInfo",    "InfoMenu");
}

public 
InfoMenu(id)
{
    
// Be a bit more descriptive in your menus & menu_handlers
    //  I know that this would be fairly obvious since there's only
    //   one menu, but it's good practice
    
new menu menu_create("\yServer Info Menu:""InfoMenu_handler");
    
    
menu_additem(menu"Admin Prices",    "1");
    
menu_additem(menu"Mod Info",        "2");
    
menu_additem(menu"Info About Server",    "3");
    
    
menu_setprop(menuMPROP_EXITMEXIT_ALL);
    
    
// If you use PLUGIN_HANDLED at the end of the function then you won't see the command
    //  in chat. (i.e. Someone uses the command /ServerInfo then everyone in the server can
    //   see /ServerInfo in the chat area. If you pass PLUGIN_HANDLED then it'll open
    //    the menu and block it from appearing in chat.
    
menu_display(idmenu0);
    return 
PLUGIN_HANDLED;
}

public 
InfoMenu_handler(idmenuitem)
{
    if( 
item == MENU_EXIT )
    {
        
menu_destroy(menu);
        return 
PLUGIN_HANDLED;
    }
    
    new 
data[6], iName[64];
    new 
Accesscallback;
    
menu_item_getinfo(menuitemAccessdata5iName63callback);
    
    new 
key str_to_num(data) - 1;
    
    
// Do this to simply compact the code, so we don't have to write out each case
    //  since you are using the same functions
    
show_motd(idg_MotdPath[key], g_MotdName[key]);
    
    
// You had client_cmd(0, ...) the 0 would mean that everyone would hear the sound,
    //  which I'm sure you didn't intend to do, so just replace it with id to play it to
    //   that one person who chose the motd
    
client_cmd(id"spk ^"%s^""g_MotdSound);
    
    
// InfoMenu(id) will call the menu again once you've selected an item
    
menu_destroy(menu);
    
InfoMenu(id);
    return 
PLUGIN_HANDLED;




All times are GMT -4. The time now is 22:41.

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