AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Server Crash due to script (https://forums.alliedmods.net/showthread.php?t=210131)

CarbonDioxide 03-06-2013 16:40

Server Crash due to script
 
Hello, I am trying to hook the team join event in order to kill the player and put him in spec if 'lockteams' is '1'. Only problem is when I enable 'lockteams' and spawn HLDS crashes..
My code:
PHP Code:

public plugin_init()
{
    
register_menucmd(register_menuid("CT_Select"1), 511"team_select")
    
register_menucmd(register_menuid("Terrorist_Select"1), 511"team_select")
}

public 
team_select(id)
{
    if(
lockteams == 1)
    {
        
user_kill(id);
        
cs_set_user_team(idCS_TEAM_SPECTATOR);
        
client_print(idprint_chat"Team selection is disabled");
    }


What am I doing wrong :?

Infernuz 03-06-2013 19:17

Re: Server Crash due to script
 
1 Attachment(s)
Dont know, may be many things. Try this instead. Hoppe you'll find it usefull.
Try to understand the code before modifying

https://forums.alliedmods.net/showpo...15&postcount=5
PHP Code:

/*
 * Team hook by Infernus
 * 
 * This plugin will try to block the item selection at original team choose menu. Works with VGUI.
 * 
 * 
 * Credits: Kiske
 */

#include <amxmodx>

new bool:g_lockteams true;
new 
bool:g_debug true;

public 
plugin_init() {
    
register_plugin("Team hook""1.0""Infernus");
    
    
register_clcmd("chooseteam""chooseteam_menu");    // called when user presses m
    
register_clcmd("jointeam""chooseteam_menu");        // called when user joins a team throw console
    
register_menucmd(register_menuid("Team_Select"1), (1<<0)|(1<<1)|(1<<4)|(1<<5), "menucmd_TeamSelect");    
}

/*
 * This event will be called when user types "chooseteam" or "jointeam" in console. Or, presses m in game.
 * 
 *     Accepts:
 *     [integer] id - Players identifier                        (1 to 32)
 * 
 *  returns PLUGIN_HANDLED on succesfull menu block, and PLUGIN_CONTINUE on no menu block.
 */
public chooseteam_menu(id) {
    
    if(
g_debug)
        
server_print("choose_team_enter");

    
// handle vgui
    
new sParam[2], iParam;
    
    
read_argv(1sParam1); 
    
iParam str_to_num(sParam); 
    
    if( 
menu_hook(idiParam) )
        return 
PLUGIN_HANDLED
    
    
if(g_debug)
        
server_print("choose_team_exit");
    
    return 
PLUGIN_CONTINUE;
}

/*
 * This event will be called when user uses menu type ShowMenu
 *
 *     Accepts:
 *     [integer] id - Players identifier (1 to 32)
 *
 *     returns PLUGIN_HANDLED on successful menu block, and PLUGIN_CONTINUE on no menu block.
 */
public menucmd_TeamSelect(idkey) {
    
    if(
g_debug)
        
server_print("team_select_enter");
    
    if(!
is_user_connected(id))
        return 
PLUGIN_HANDLED;

    
// handle menu clicking in showmenu
    
if( menu_hook(idkey+11) )
        return 
PLUGIN_HANDLED
    
    
if(g_debug)
        
server_print("team_select_exit");
    
    return 
PLUGIN_CONTINUE;
}

/*
 * This hooks team select menu.
 * 
 *     Accepts: 
 *     [integer]    id             - Players identificator                    (1 to 32)
 *     [integer]     key         - The menu item, player clicked in game    (1 = TERS, 2 = CTS, 5 = AUTO-SELECT, 6 = SPECTATORS)
 *     [bool]        menu_type      - Vgui or ShowMenu?                     (1 = VGUI, 0 = ShowMenu)
 * 
 *     returns false on no item block, and true on item block.
 */
public bool:menu_hook(idkeymenu_type) {
    
    if(
g_debug) {
        
server_print("menu_hook_enter");
        
client_print(idprint_chat"Clicked key: %d"key);
    }
    
    
//new msgid = menu_type ? get_user_msgid("VGUIMenu") : get_user_msgid("ShowMenu");
    //new msgBlock = get_msg_block(msgid);

    
switch(key) {
        
        case 
1: {
            if(
g_lockteams) {
                
client_print(idprint_center"Team selection is disabled, can't join terrorist force!"); 
                return 
true;
            }
        }
        
        case 
2: {
            if(
g_lockteams) {
                
client_print(idprint_center"Team selection is disabled, can't join CT force!"); 
                return 
true;
            }
        }
        
        case 
5: {
            
//AUTO-SELECT
            
        
}
        
        case 
6: {
            
// SPECTATORS
            //set_msg_block(msgid, BLOCK_SET);
            //engclient_cmd(id, "jointeam", teamStr);
            //set_msg_block(msgid, msgBlock);
        
}
    }

    if(
g_debug)
        
server_print("menu_hook_exit");
        
    return 
false;



ConnorMcLeod 03-07-2013 00:27

Re: Server Crash due to script
 
Quote:

Originally Posted by CarbonDioxide (Post 1907943)
Hello, I am trying to hook the team join event in order to kill the player and put him in spec if 'lockteams' is '1'. Only problem is when I enable 'lockteams' and spawn HLDS crashes..
My code:
PHP Code:

public plugin_init()
{
    
register_menucmd(register_menuid("CT_Select"1), 511"team_select")
    
register_menucmd(register_menuid("Terrorist_Select"1), 511"team_select")
}

public 
team_select(id)
{
    if(
lockteams == 1)
    {
        
user_kill(id);
        
cs_set_user_team(idCS_TEAM_SPECTATOR);
        
client_print(idprint_chat"Team selection is disabled");
    }


What am I doing wrong :?

You have forgotten to block with PLUGIN_HANDLED, also you have forgotten VGUI menus.

CarbonDioxide 03-07-2013 04:43

Re: Server Crash due to script
 
Script works with no problem, except that the "auto-select" choice wasn't blocked, but I fixed it.
Thank you for the help!


All times are GMT -4. The time now is 21:48.

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