I try write this plugin. All working like what I want. But it make server lag and high ping. I think problem at FM_PlayerPreThink but I don't know how to fix it. Anyone here can help me optimize or teach me better way.
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#define PLUGIN "Testing"
#define VERSION "1.0"
#define AUTHOR "Newcomer"
enum SpecStatus {
SPEC_ALLOWED = 0,
SPEC_FORBIDDEN
};
new SpecStatus:g_iStatus[33] = { SPEC_ALLOWED, ... };
new g_iHudSync;
new ScreenFade;
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR);
register_forward(FM_PlayerPreThink, "fwdPlayerPreThink", 0);
register_clcmd("say on", "on");
register_clcmd("say ", "off");
g_iHudSync = CreateHudSyncObj();
ScreenFade = get_user_msgid("ScreenFade")
}
public client_disconnect(id)
{
remove_task(id)
}
public on(id)
{
if (access(id,ADMIN_IMMUNITY))
{
g_iStatus[id] = SPEC_FORBIDDEN;
client_print(id, print_chat, "Turned ON!");
set_task( 1.0, "wel_msg", id, "", 0, "b" );
}
else
{
client_print(id, print_chat, "You're not allow this");
}
}
public off(id)
{
g_iStatus[id] = SPEC_ALLOWED;
client_print(id, print_chat, "Turn OFF!");
remove_task(id)
}
public fwdPlayerPreThink(client)
{
if(is_user_alive(client))
return FMRES_IGNORED;
static iTarget;
iTarget = pev(client, pev_iuser2);
if(!is_user_alive(iTarget))
return FMRES_IGNORED;
if(g_iStatus[iTarget] != SPEC_ALLOWED && !access(client,ADMIN_IMMUNITY))
{
new name[32]
get_user_name(iTarget,name,31)
set_hudmessage(255, 255, 255, -1.0, 0.3, 0, 6.0, 4.0, 0.1, 0.1);
ShowSyncHudMsg(client, g_iHudSync, "%s Turned ON",name);
make_ScreenFade(client, 0, 0, 0x0004, 0, 0, 0, 255);
return FMRES_HANDLED;
}
return FMRES_IGNORED;
}
make_ScreenFade(client, duration, holdtime, flags, r, g, b, a)
{
message_begin(MSG_ONE, ScreenFade, _, client);
write_short(duration);
write_short(holdtime);
write_short(flags);
write_byte(r);
write_byte(g);
write_byte(b);
write_byte(a);
message_end();
}
public wel_msg(id)
{
if (is_user_alive(id))
{
set_hudmessage( 255, 255, 255, 0.45, 0.002, 0, 0.02, 1.0, 0.1, 0.2, -1 );
ShowSyncHudMsg( id, g_iHudSync, "Turn ON");
}
}