AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help me optimize this ! (https://forums.alliedmods.net/showthread.php?t=188236)

newcomer 06-24-2012 02:49

Help me optimize this !
 
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(PLUGINVERSIONAUTHOR);    
    
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(idprint_chat"Turned ON!");
        
set_task1.0"wel_msg"id""0"b" );
    }
    else
    {
        
client_print(idprint_chat"You're not allow this");        
    }
}

public 
off(id)
{
        
g_iStatus[id] = SPEC_ALLOWED;    
        
client_print(idprint_chat"Turn OFF!");    
        
remove_task(id)
}

public 
fwdPlayerPreThink(client)
{
    if(
is_user_alive(client))
        return 
FMRES_IGNORED;
    
    static 
iTarget;
    
iTarget pev(clientpev_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(255255255, -1.00.306.04.00.10.1);
    
ShowSyncHudMsg(clientg_iHudSync"%s Turned ON",name);    
    
make_ScreenFade(client000x0004000255);             
    return 
FMRES_HANDLED;
    }
    return 
FMRES_IGNORED;
}

make_ScreenFade(clientdurationholdtimeflagsrgba)
{
    
message_begin(MSG_ONEScreenFade_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_hudmessage2552552550.450.00200.021.00.10.2, -);
    
ShowSyncHudMsgidg_iHudSync"Turn ON");
    }



GordonFreeman (RU) 06-24-2012 03:02

Re: Help me optimize this !
 
using set_task?
set_task(0.1,"fwdPlayerPreThink",client,.flag s="b")

newcomer 06-24-2012 03:09

Re: Help me optimize this !
 
please teach me how can do that :)

Backstabnoob 06-24-2012 04:24

Re: Help me optimize this !
 
You are sending ScreenFade message 60 times per second per player. PreThink should ALWAYS be used only when there is no other way. I'm surprised you're not getting an overflow.

newcomer 06-24-2012 04:39

Re: Help me optimize this !
 
can you fix it for me :(
because I don't know what better make ScreenFade unlimit time on player ...

<VeCo> 06-24-2012 07:31

Re: Help me optimize this !
 
Use FFADE_STAYOUT flag and send the message only once.

fysiks 06-24-2012 12:45

Re: Help me optimize this !
 
Quote:

Originally Posted by GordonFreeman (RU) (Post 1734930)
using set_task?
set_task(0.1,"fwdPlayerPreThink",client,.flag s="b")

Absolutely not. That will just make it worse.

GordonFreeman (RU) 06-24-2012 22:50

Re: Help me optimize this !
 
okay

newcomer 06-24-2012 23:22

Re: Help me optimize this !
 
Quote:

Originally Posted by <VeCo> (Post 1735053)
Use FFADE_STAYOUT flag

I did it, ---> "0x0004"
please teach me how can send once time but it still unlimit time

<VeCo> 06-25-2012 00:40

Re: Help me optimize this !
 
Put the fade and HUD code in on(id) function. Don't use PreThink for this.


All times are GMT -4. The time now is 06:12.

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