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.
With the code above you would then do "enableHam()" to enable the forward, "disableHam()" to disable it.
Light version:
Debug version:
Debug version usage output:
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(PLUGIN, VERSION, AUTHOR)
// 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)
{
}
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(PLUGIN, VERSION, AUTHOR)
state unregistered;
}
public enableHam() <unregistered> state (HamHookSpawn = RegisterHam(Ham_Spawn,"player","playerSpawn") ) enabled;
public enableHam() <disabled> state (EnableHamForward(HamHookSpawn)) enabled;
public disableHam() <enabled> state (!DisableHamForward(HamHookSpawn)) disabled;
public enableHam() <> {}
public disableHam() <>{}
public playerSpawn(id)
{
}
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(PLUGIN, VERSION, AUTHOR)
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)
{
}
PHP Code:
] enable
Registering] enable
Already enabled] disable
Disabling] disable
Already disabled] enable
Enabling] enable
Already enabled
0 nhận xét:
Post a Comment