Raised This Month: $ Target: $400
 0% 

Server Crash due to script


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
CarbonDioxide
Member
Join Date: Apr 2012
Old 03-06-2013 , 16:40   Server Crash due to script
Reply With Quote #1

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
CarbonDioxide is offline
Infernuz
Member
Join Date: May 2011
Old 03-06-2013 , 19:17   Re: Server Crash due to script
Reply With Quote #2

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;

Attached Files
File Type: sma Get Plugin or Get Source (team_block.sma - 510 views - 3.0 KB)

Last edited by Infernuz; 03-06-2013 at 21:13. Reason: fixed plugin to work with vgui, i always make typos -.-
Infernuz is offline
Send a message via ICQ to Infernuz
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 03-07-2013 , 00:27   Re: Server Crash due to script
Reply With Quote #3

Quote:
Originally Posted by CarbonDioxide View Post
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.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
CarbonDioxide
Member
Join Date: Apr 2012
Old 03-07-2013 , 04:43   Re: Server Crash due to script
Reply With Quote #4

Script works with no problem, except that the "auto-select" choice wasn't blocked, but I fixed it.
Thank you for the help!
CarbonDioxide 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 16:09.


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