Raised This Month: $ Target: $400
 0% 

Help me optimize this !


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
newcomer
Member
Join Date: Aug 2011
Old 06-24-2012 , 02:49   Help me optimize this !
Reply With Quote #1

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");
    }

newcomer is offline
GordonFreeman (RU)
Veteran Member
Join Date: Jan 2010
Location: Uzbekistan
Old 06-24-2012 , 03:02   Re: Help me optimize this !
Reply With Quote #2

using set_task?
set_task(0.1,"fwdPlayerPreThink",client,.flag s="b")
__________________
The functional way is the right way
GordonFreeman (RU) is offline
newcomer
Member
Join Date: Aug 2011
Old 06-24-2012 , 03:09   Re: Help me optimize this !
Reply With Quote #3

please teach me how can do that
newcomer is offline
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 06-24-2012 , 04:24   Re: Help me optimize this !
Reply With Quote #4

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.
Backstabnoob is offline
newcomer
Member
Join Date: Aug 2011
Old 06-24-2012 , 04:39   Re: Help me optimize this !
Reply With Quote #5

can you fix it for me
because I don't know what better make ScreenFade unlimit time on player ...

Last edited by newcomer; 06-24-2012 at 04:41.
newcomer is offline
<VeCo>
Veteran Member
Join Date: Jul 2009
Location: Bulgaria
Old 06-24-2012 , 07:31   Re: Help me optimize this !
Reply With Quote #6

Use FFADE_STAYOUT flag and send the message only once.
__________________
<VeCo> is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-24-2012 , 12:45   Re: Help me optimize this !
Reply With Quote #7

Quote:
Originally Posted by GordonFreeman (RU) View Post
using set_task?
set_task(0.1,"fwdPlayerPreThink",client,.flag s="b")
Absolutely not. That will just make it worse.
__________________
fysiks is offline
GordonFreeman (RU)
Veteran Member
Join Date: Jan 2010
Location: Uzbekistan
Old 06-24-2012 , 22:50   Re: Help me optimize this !
Reply With Quote #8

okay
__________________
The functional way is the right way
GordonFreeman (RU) is offline
newcomer
Member
Join Date: Aug 2011
Old 06-24-2012 , 23:22   Re: Help me optimize this !
Reply With Quote #9

Quote:
Originally Posted by <VeCo> View Post
Use FFADE_STAYOUT flag
I did it, ---> "0x0004"
please teach me how can send once time but it still unlimit time
newcomer is offline
<VeCo>
Veteran Member
Join Date: Jul 2009
Location: Bulgaria
Old 06-25-2012 , 00:40   Re: Help me optimize this !
Reply With Quote #10

Put the fade and HUD code in on(id) function. Don't use PreThink for this.
__________________

Last edited by <VeCo>; 06-25-2012 at 00:40.
<VeCo> 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 06:12.


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