text
stringlengths
0
692
register_think(g_Classname,"RoflmaoThink")
}
public RoflmaoThink(Ent)
{
log_amx("ROFLMAO thinks.")
entity_set_float(Ent,EV_FL_nextthink,20.0)
}
Fakemeta:
Code:
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
new g_Classname[] = "roflmao"
public plugin_init()
{
register_plugin("ROFL","1.0","Hawk552")
new Ent = engfunc(EngFunc_CreateNamedEntity,engfunc(EngFunc_AllocString,"info_target"))
set_pev(Ent,pev_classname,g_Classname)
set_pev(Ent,pev_nextthink,20.0)
register_forward(FM_Think,"ForwardThink")
}
public ForwardThink(Ent)
{
static Classname[33]
pev(Ent,pev_classname,Classname,32)
if(!equal(Classname,g_Classname))
return FMRES_IGNORED
log_amx("ROFLMAO thinks.")
set_pev(Ent,pev_nextthink,20.0)
return FMRES_IGNORED
}
This is useful, as said, for escaping the usage of flag "b" on set_task, or executing set_task at the end of the function called.
The final way to escape a set_task is when using cooldowns. For example, you want a player to be able to use a special attack every 30 seconds.
Code:
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
// this is how often you want your players to be able to use your attack
#define ATTACK_COOLDOWN 20.0
new Float:g_LastAttack[33]
// optimization
new Float:g_Cooldown = ATTACK_COOLDOWN
public plugin_init()
{
register_plugin("ROFL","1.0","Hawk552")
register_clcmd("myattack","CmdMyAttack")
}
public CmdMyAttack(id)
{
// to use engine instead, use this:
/* new Float:Time = halflife_time() */
new Float:Time
global_get(glb_time,Time)
if(!is_user_alive(id) || Time - g_Cooldown < g_LastAttack[id])
return
g_LastAttack[id] = Time
// your code here
}