AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   optimize the code ? (https://forums.alliedmods.net/showthread.php?t=155403)

lqlqlq 04-21-2011 13:59

optimize the code ?
 
Give this code here because I think that because it gets segmentation fault error in my server and I think he needs optimization, what do you think?
Code:

#include <amxmodx>
#include <cstrike>

new const VERSION[] = "1.0"

new gmsgTextMsg

public plugin_init()
{
        register_plugin("3 in 1", VERSION, "Dark_Style")
       
        register_clcmd("radio1", "cmd_block")
        register_clcmd("radio2", "cmd_block")
        register_clcmd("radio3", "cmd_block")
        register_clcmd("chooseteam", "cmd_block")
        register_clcmd("drop", "cmd_block")
       
        gmsgTextMsg = get_user_msgid("TextMsg")
        register_message(get_user_msgid("SendAudio"), "Message_SendAudio")
}

public cmd_block(id)
{
        return PLUGIN_HANDLED
}

public Message_SendAudio(iMsgId, iMsgDest, id)
{
        if(id)
        {
                new szRadioKey[19]
                static const MRAD_FIREINHOLE[] = "%!MRAD_FIREINHOLE"
                get_msg_arg_string(2, szRadioKey, charsmax(szRadioKey))
               
                if(equal(szRadioKey, MRAD_FIREINHOLE))
                {
                        if(get_msg_block(gmsgTextMsg) != BLOCK_SET)
                        {
                                set_msg_block(gmsgTextMsg, BLOCK_ONCE)
                        }
                        return PLUGIN_HANDLED
                }
        }
        return PLUGIN_CONTINUE
}

public client_command(client)
{
        static const szJoinCommand[] = "jointeam"
       
        static szCommand[10]
        read_argv(0, szCommand, 9)
       
        if(equal(szCommand, szJoinCommand)
        && CS_TEAM_T <= cs_get_user_team(client) <= CS_TEAM_CT)
        {
                console_print(client, "That command is blocked on this server")
                return PLUGIN_HANDLED
        }
        return PLUGIN_CONTINUE
}


ConnorMcLeod 04-21-2011 14:12

Re: optimize the code ?
 
You could register jointeam command and you could register event instead of hooking message, then you could filter Grenade sound in the register_event line.
register_message sound was extracted from a plugin i made, but in your case it is not the better solution.

lqlqlq 04-21-2011 14:15

Re: optimize the code ?
 
Connor I not understand anything from scripting will ask you to edit what you judge it necessary, but I hope to perform the functions now.
Could cause segment fault?

ConnorMcLeod 04-21-2011 14:30

Re: optimize the code ?
 
You are in scripting help, assuming you already know few things.

PHP Code:

#include <amxmodx>
#include <cstrike>
#include <fakemeta>
#include <hamsandwich>

#define VERSION "0.0.1"

#define XO_PLAYER 5
#define m_iRadiosLeft 192
#define OFFSET_DEFUSE_PLANT_LoL 193
#define m_iMenuCode 205
const SILENT_RADIO = (1<<0)

#define Team_Select 1

public plugin_init()
{
    
register_plugin("Misc Blocks"VERSION"ConnorMcLeod")
    
    
register_clcmd("radio1""ClCmd_MiscCmdBlock")
    
register_clcmd("radio2""ClCmd_MiscCmdBlock")
    
register_clcmd("radio3""ClCmd_MiscCmdBlock")
    
register_clcmd("chooseteam""ClCmd_MiscCmdBlock")
    
register_clcmd("drop""ClCmd_MiscCmdBlock")
    
register_clcmd("jointeam""ClCmd_JoinTeam")
    
register_clcmd("ignorerad""ClCmd_MiscCmdBlock")
    
register_clcmd("menuselect""ClCmd_MenuSelect")
    
    
RegisterHam(Ham_Spawn"player""CBasePlayer_Spawn_Post"true)
}

public 
CBasePlayer_Spawn_Postid )
{
    if( 
is_user_alive(id) )
    {
        
set_pdata_int(idm_iRadiosLeft0XO_PLAYER)
        
set_pdata_int(idOFFSET_DEFUSE_PLANT_LoLget_pdata_int(idOFFSET_DEFUSE_PLANT_LoLXO_PLAYER) | SILENT_RADIOXO_PLAYER)
    }
}

public 
ClCmd_MiscCmdBlock(id)
{
    return 
PLUGIN_HANDLED
}

public 
ClCmd_JoinTeamid )
{
    return ( 
CS_TEAM_T <= cs_get_user_team(id) <= CS_TEAM_CT )
}

public 
ClCmd_MenuSelectid )
{
    if( 
get_pdata_int(idm_iMenuCodeXO_PLAYER) == Team_Select )
    {
        new 
szArg[3]
        if( 
read_argv(1szArgcharsmax(szArg)) == )
        {
            return (( 
<= str_to_num(szArg) <= ) && ( CS_TEAM_T <= cs_get_user_team(id) <= CS_TEAM_CT ))
        }
    }
    return 
PLUGIN_CONTINUE



lqlqlq 04-21-2011 14:43

Re: optimize the code ?
 
Maybe very little, thanks anyway for the code, and whether it can cause segment fault or not aware?

ConnorMcLeod 04-21-2011 16:06

Re: optimize the code ?
 
Haven't see anything bad in previous code.


All times are GMT -4. The time now is 19:55.

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