Raised This Month: $12 Target: $400
 3% 

Need code optimisation, small plugin.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
blackalegator
Member
Join Date: Jan 2010
Old 04-20-2011 , 18:01   Need code optimisation, small plugin.
Reply With Quote #1

All right recently someone on this foru helped me to make a plugin which always kept a building menu up. The problem is that now my server allways prints out error messages:

PHP Code:
Displaying call stack trace for plugin "PanelUP.smx":
L 04/21/2011 01:42:32: [SM]   [0]  Line 53D:\Games\steamapps\common\left 4 dead 2\left4dead2\addons\sourcemod\scripting\PanelUP.sp::Menu_Building()
L 04/21/2011 01:42:32: [SM]   [1]  Line 42D:\Games\steamapps\common\left 4 dead 2\left4dead2\addons\sourcemod\scripting\PanelUP.sp::MenuBuildingHandler()
L 04/21/2011 01:42:32: [SMPlugin encountered error 8Not enough space on the stack 
+ Sometimes my server crashes on map change or suddenly CPU usage goest up to 100 % and I guess that that means it is having memory leaks

PS Ive also got some warnings on compilation. Anyways here is the code.

PHP Code:
#include <sourcemod>

#define PLUGIN_VERSION "1.0"

public Plugin:myinfo =
{
    
name "Panel Up",
    
author "blackalegator",
    
description "Keep the panel up",
    
version "PLUGIN_VERSION",
    
url "",
}

public 
Action:Timer_Name(Handle:timerany:client)
{
    if(!
IsClientConnected(client)) return Plugin_Stop;
    if(
IsPlayerAlive(client))
    {
        
Menu_Building(client);
    }
    return 
Plugin_Continue;
}

public 
OnClientConnected(client)
{
    
CreateTimer(15.0Timer_NameclientTIMER_REPEAT);
}

public 
MenuBuildingHandler(Handle:menuMenuAction:actionclientparam2)
{
    
/* If an option was selected, build. */
    
if (action == MenuAction_Select)
    {
        new 
String:info[128];
        
GetMenuItem(menuparam2infosizeof(info));
        
FakeClientCommand(clientinfo);
        
Menu_Building(client);
    }
    
/* If the menu was cancelled, show menu. */
    
else if (action == MenuAction_Cancel)
    {
        
Menu_Building(client);
    }
    
/* If the menu has ended, show menu */
    
else if (action == MenuAction_End)
    {
        
CloseHandle(menu);
    }
}
 
Menu_Building(client)
{
    new 
Handle:menu CreateMenu(MenuBuildingHandler);
    
SetMenuTitle(menu"Build your barricade!");
    
AddMenuItem(menu"fortspawn_remove""Remove object you are aiming at");
    
AddMenuItem(menu"fortspawn_irondoor""Safe Room Door");
    
AddMenuItem(menu"fortspawn_item d a models/props_unique/airport/temp_barricade.mdl""Temp Fence");
    
AddMenuItem(menu"fortspawn_item d a models/props_junk/wood_crate001a.mdl""Wood Crate");
    
AddMenuItem(menu"fortspawn_item d a models/props_fortifications/concrete_wall001_96_reference.mdl""Concrete Wall");
    
AddMenuItem(menu"fortspawn_item d a models/props_urban/fence_cover001_128.mdl""Fence Cover");
    
AddMenuItem(menu"fortspawn_rotate 45""Rotate 45 degrees");
    
SetMenuExitButton(menufalse);
    
DisplayMenu(menuclient60);
 
return 
Plugin_Handled;

__________________
I am Russian so DONT look at my english
blackalegator is offline
Send a message via Skype™ to blackalegator
ProdigySim
SourceMod Plugin Approver
Join Date: Feb 2010
Old 04-20-2011 , 19:46   Re: Need code optimisation, small plugin.
Reply With Quote #2

I don't know much about menu handling, but the timer has the possibility to double-up if a client leaves and someone else fills his client index spot within 15 seconds. This may be part of your issue on map change--I don't know if that triggers an OnClientConnect, though.


I'd recommend switching your code to use OnClientDisconnect instead of the timer trying to kill itself.

Code:
new Handle:menutimers[MAX_PLAYERS];

public OnClientConnected(client)
{
    menutimers[client] = CreateTimer(....);
}

public OnClientDisconnect(
{
    KillTimer(menutimers[client]);
}
You may also want to add TIMER_FLAG_NO_MAPCHANGE to your timers if it turns out the ClientConnects are being repeated on map start.
ProdigySim is offline
meng
Veteran Member
Join Date: Oct 2005
Location: us
Old 04-20-2011 , 19:52   Re: Need code optimisation, small plugin.
Reply With Quote #3

Maybe, also, for sure, why not, add...

PHP Code:
(GetClientMenu(client) == MenuSource_None
to your timer callback?!?!
__________________
.
[ 1 Dumerils Boa | 1 Cali King ]...
.
I'm a lil' spirituous.
meng is offline
Send a message via Yahoo to meng
Monkeys
Veteran Member
Join Date: Jan 2010
Old 04-20-2011 , 21:37   Re: Need code optimisation, small plugin.
Reply With Quote #4

Instead of using OnClientDisconnect, you're better off simply using userids.
This will help you in the future aswell, as any "long" timer should use userids.
__________________
Get a lid on that zombie,
he's never gonna be alri-i-ight.
Oooh get a lid on that zombie,
or he's gonna feed all night.
Monkeys 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 18:15.


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