Raised This Month: $ Target: $400
 0% 

optimize the code ?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
lqlqlq
Senior Member
Join Date: Jan 2008
Old 04-21-2011 , 13:59   optimize the code ?
Reply With Quote #1

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
}
lqlqlq is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 04-21-2011 , 14:12   Re: optimize the code ?
Reply With Quote #2

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.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
lqlqlq
Senior Member
Join Date: Jan 2008
Old 04-21-2011 , 14:15   Re: optimize the code ?
Reply With Quote #3

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?
lqlqlq is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 04-21-2011 , 14:30   Re: optimize the code ?
Reply With Quote #4

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

__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
lqlqlq
Senior Member
Join Date: Jan 2008
Old 04-21-2011 , 14:43   Re: optimize the code ?
Reply With Quote #5

Maybe very little, thanks anyway for the code, and whether it can cause segment fault or not aware?
lqlqlq is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 04-21-2011 , 16:06   Re: optimize the code ?
Reply With Quote #6

Haven't see anything bad in previous code.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod 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 19:55.


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