This site is a testing version, but all data is shared with the live forum.


Raised This Month: $ Target: $400
 0% 

Automatons


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 02-18-2009 , 19:13   Automatons
Reply With Quote #1

I was reading the pawn manual when i stepped into a topic called "Automatons". I had studied it in the university so it wasn't news for me.
I've searched the forums to see if there were some known good use to them but just find this:

https://forums.alliedmods.net/showpo...11&postcount=2

Anyway, i have a use for it. It may give you ideas for use them somehow that it can improve plugins performance.

The code below can be used to enable/disable a Ham Forward without if clauses and without need to check if it registered.

Is it an improvement to the "normal" process? I don't know. I guess it is but, is safer to ask anyone that knows how to analyze compiled code.

PHP Code:

#include <amxmodx>
#include <hamsandwich>

#define PLUGIN    "Automaton"
#define AUTHOR    "Albernaz o Carniceiro Demoniaco"
#define VERSION    "1.0"

new HamHook:HamHookSpawn

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)        
    
    
// The start point: unregistered 
    
    
state unregistered;
}

public 
enableHam() <unregistered>
{
    
// If it's unregistered and is wanted to be enabled, it must be registered
    
    
HamHookSpawn RegisterHam(Ham_Spawn,"player","playerSpawn");
    
state enabled;
}

public 
enableHam() <disabled>
{
    
// If it's disabled and is wanted to be enabled, it must be enabled
    
    
EnableHamForward(HamHookSpawn);    
    
state enabled;
}

public 
enableHam() <enabled> {}
public 
disableHam() <unregistered,disabled>{}
/*

The above two line can be:

public enableHam() <> {}
public disableHam() <>{}


*/


public disableHam() <enabled>
{    
    
// If it's enabled and is wanted to be disabled, it must be disabled
    
    
DisableHamForward(HamHookSpawn);    
    
state disabled;
}

public 
playerSpawn(id)
{
    

With the code above you would then do "enableHam()" to enable the forward, "disableHam()" to disable it.


Light version:

PHP Code:
#include <amxmodx>
#include <hamsandwich>

 #define PLUGIN    "Automaton"
#define AUTHOR    "Albernaz o Carniceiro Demoniaco"
#define VERSION    "1.0"

new HamHook:HamHookSpawn

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)                
    
state unregistered;
}

public 
enableHam() <unregisteredstate (HamHookSpawn RegisterHam(Ham_Spawn,"player","playerSpawn") ) enabled;
public 
enableHam() <disabledstate (EnableHamForward(HamHookSpawn)) enabled;
public 
disableHam() <enabledstate (!DisableHamForward(HamHookSpawn)) disabled;
public 
enableHam() <> {}
public 
disableHam() <>{}

public 
playerSpawn(id)
{
    

Debug version:

PHP Code:
#include <amxmodx>
#include <hamsandwich>

 #define PLUGIN    "Automaton"
#define AUTHOR    "Albernaz o Carniceiro Demoniaco"
#define VERSION    "1.0"

new HamHook:HamHookSpawn

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)        
    
    
register_clcmd("enable","enable");
    
register_clcmd("disable","disable");
        
    
state unregistered;
}

public 
enable()
{
    
enableHam()
    return 
PLUGIN_HANDLED;
}

public 
disable()
{
    
disableHam()
    return 
PLUGIN_HANDLED;
}

public 
enableHam() <unregistered>
{
    
HamHookSpawn RegisterHam(Ham_Spawn,"player","playerSpawn");
    
state enabled
    
    server_print
("Registering");
}

public 
enableHam() <disabled>
{
    
EnableHamForward(HamHookSpawn);    
    
state enabled;
    
    
server_print("Enabling");
}

public 
disableHam() <enabled>
{    
    
DisableHamForward(HamHookSpawn);    
    
state disabled;
    
    
server_print("Disabling");
}

public 
enableHam() <> 
{
    
server_print("Already enabled");
}
public 
disableHam() <>
{
    
server_print("Already disabled");
}

public 
playerSpawn(id)
{
    

Debug version usage output:

PHP Code:
enable
Registering
enable 
Already enabled
disable
Disabling
disable 
Already disabled
enable
Enabling
enable 
Already enabled 
__________________

Last edited by joaquimandrade; 02-19-2009 at 07:03. Reason: Code optimization
joaquimandrade is offline
 



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 16:09.


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