princess milk
Join Date: Nov 2010
Location: Somewhere in this world
|
12-12-2012
, 15:48
Re: [REQ] Santa Hat: Command to enable and disable
|
#4
|
Although I don't support Christmas stuff, I just want to improve my knowledge about entities ..
Try this
Spoiler
PHP Code:
#include <amxmodx>
#include <fakemeta>
new gHatBit
#define AddToBit(%0) ( gHatBit |= (1<<%0) )
#define RemoveFromBit(%0) ( gHatBit &= ~(1<<%0) )
#define IsInBit(%0) ( gHatBit & (1<<%0) )
#define CreateEntity (engfunc( EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target") ) );
new g_pEnabled
#define ENABLED (get_pcvar_num(g_pEnabled) )
new const MODEL[ ] = "models/santa_hat.mdl";
public plugin_precache( )
{
precache_model( MODEL );
}
public plugin_init( )
{
new const VERSION[ ] = "1.3";
register_plugin( "Santa Hat", VERSION, "xPaw" );
set_pcvar_string( register_cvar( "santa_hat", VERSION, FCVAR_SERVER ), VERSION );
register_clcmd("say /hat", "ToggleHat")
g_pEnabled = register_cvar("hats_enabled", "1")
}
public ToggleHat(id)
{
if(!ENABLED)
return client_print(id, print_chat, "Santa hat is disabled..")
new iEnt
new szClassName[32]; formatex(szClassName, charsmax(szClassName), "santa_hat_%d", id)
if(!IsInBit(id))
{
AddToBit(id)
iEnt = CreateEntity
if(!pev_valid(iEnt))
{
return client_print(id, print_chat, "Couldn't create entity")
}
set_pev(iEnt, pev_classname, szClassName)
engfunc( EngFunc_SetModel, iEnt, MODEL );
set_pev( iEnt, pev_movetype, MOVETYPE_FOLLOW );
set_pev( iEnt, pev_aiment, id );
set_pev( iEnt, pev_owner, id );
client_print(id, print_chat, "YAY! You got your own santa hat ..")
return PLUGIN_HANDLED
}
RemoveFromBit(id)
iEnt = -1
iEnt = engfunc(EngFunc_FindEntityByString, iEnt, "classname", szClassName)
engfunc(EngFunc_RemoveEntity, iEnt)
client_print(id, print_chat, "Your hat has been removed")
return PLUGIN_HANDLED
}
If it didn't work then try this:
Spoiler
PHP Code:
#include <amxmodx>
#include <fakemeta>
new gHatBit
#define AddToBit(%0) ( gHatBit |= (1<<%0) )
#define RemoveFromBit(%0) ( gHatBit &= ~(1<<%0) )
#define IsInBit(%0) ( gHatBit & (1<<%0) )
#define CreateEntity (engfunc( EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target") ) );
new g_pEnabled
#define ENABLED (get_pcvar_num(g_pEnabled) )
new const MODEL[ ] = "models/santa_hat.mdl";
public plugin_precache( )
{
precache_model( MODEL );
}
public plugin_init( )
{
new const VERSION[ ] = "1.3";
register_plugin( "Santa Hat", VERSION, "xPaw" );
set_pcvar_string( register_cvar( "santa_hat", VERSION, FCVAR_SERVER ), VERSION );
register_clcmd("say /hat", "ToggleHat")
g_pEnabled = register_cvar("hats_enabled", "1")
}
public ToggleHat(id)
{
if(!ENABLED)
return client_print(id, print_chat, "Santa hat is disabled..")
new iEnt
new szClassName[32]; formatex(szClassName, charsmax(szClassName), "santa_hat_%d", id)
if(!IsInBit(id))
{
AddToBit(id)
iEnt = CreateEntity
if(!pev_valid(iEnt))
{
return client_print(id, print_chat, "Couldn't create entity")
}
set_pev(iEnt, pev_classname, szClassName)
engfunc( EngFunc_SetModel, iEnt, MODEL );
set_pev( iEnt, pev_movetype, MOVETYPE_FOLLOW );
set_pev( iEnt, pev_aiment, id );
set_pev( iEnt, pev_owner, id );
dllfunc(DLLFunc_Spawn, iEnt);
client_print(id, print_chat, "YAY! You got your own santa hat ..")
return PLUGIN_HANDLED
}
RemoveFromBit(id)
iEnt = -1
iEnt = engfunc(EngFunc_FindEntityByString, iEnt, "classname", szClassName)
engfunc(EngFunc_RemoveEntity, iEnt)
client_print(id, print_chat, "Your hat has been removed")
return PLUGIN_HANDLED
}
__________________
اَشْهَدُ اَنْ لَّآ اِلٰهَ اِلَّا اللہُ وَحْدَه لَا شَرِيْكَ لَه وَ اَشْهَدُ اَنَّ مُحَمَّدًا عَبْدُه وَرَسُوْلُه
No longer active in AMXX. Sorry.
|
|