Amxxprogramer / Fake Forwards.txt
RichieBurundi's picture
Upload 28 files
82d6031 verified
Your plugin has many forwards?
with this example you can create forward like register_forward of fakemeta module.
I know that other way is CreateMultiForward but this can be a another option.
PHP Code:
#include <amxmodx>
enum
{
Fake_Connect = 0,
Fake_Disconnect,
Fake_ChangeName,
Fake_PutInServer
}
new Array:g_fakeforwards_type
new Array:g_fakeforwards_num
public plugin_precache()
{
register_plugin("Fake Forwards", "1.0", "ReymonARG")
g_fakeforwards_num = ArrayCreate(1, 1)
g_fakeforwards_type = ArrayCreate(1, 1)
}
// We need to register the call for the forwards
public plugin_natives()
{
// Librery
register_library("fake_forwards")
// Natives
register_native("register_fakeforward", "_register_event")
register_native("unregister_fakeforward", "_unregister_event")
}
public _register_event(plugin, params)
{
// Are correct the params? return
if( params != 2 )
return -1
static type, g_callout[33], forwards_num
type = get_param(1)
get_string(2, g_callout, 32)
// Here We create the Forward.
switch( type )
{
// So some forwards have diferent out, so we need this to create diferent styles.
case Fake_Connect: forwards_num = CreateOneForward(plugin, g_callout, FP_CELL)
case Fake_Disconnect : forwards_num = CreateOneForward(plugin, g_callout, FP_CELL)
case Fake_ChangeName : forwards_num = CreateOneForward(plugin, g_callout, FP_CELL, FP_STRING)
case Fake_PutInServer : forwards_num = CreateOneForward(plugin, g_callout, FP_CELL)
default: return -1
}
// Can create the forward? Return.
if( forwards_num == -1 )
return -1
// Save the type of the forward and the num.
ArrayPushCell(g_fakeforwards_type, type)
ArrayPushCell(g_fakeforwards_num, forwards_num)
return forwards_num
}
// Well i think that this dont is good, But i will try to better this part.
public _unregister_event(plugin, params)
{
// Its param = 1 ? return.
if( params != 1 )
return -1
static i, fwd_id
fwd_id = get_param(1)
// Found the forward and delete.
for( i = 0; i < ArraySize( g_fakeforwards_num ); i++)
{
if( ArrayGetCell(g_fakeforwards_num, i) == fwd_id )
{
// Delete forward
DestroyForward(fwd_id)
// And items.
ArrayDeleteItem(g_fakeforwards_type, i)
ArrayDeleteItem(g_fakeforwards_num, i)
return 1
}
}
return 0
}
public client_connect(id)
{
static i, null_id
// Well this is the mechanism to exec the forwards.
for( i = 0; i < ArraySize( g_fakeforwards_num ); i++)
{
// If item type is Fake_Connect ?
if( ArrayGetCell(g_fakeforwards_type, i) == Fake_Connect )
{
// Exec the forward.
ExecuteForward(ArrayGetCell(g_fakeforwards_num, i), null_id, id)
}
}
}
public client_disconnect(id)
{
static i, null_id
for( i = 0; i < ArraySize( g_fakeforwards_num ); i++)
{
if( ArrayGetCell(g_fakeforwards_type, i) == Fake_Disconnect )
{
ExecuteForward(ArrayGetCell(g_fakeforwards_num, i), null_id, id)
}
}
}
public client_infochanged(id)
{
static oldname[32], newname[32], i, null_id
get_user_name(id, oldname, 31)
get_user_info(id, "name", newname, 31)
if( !equal(oldname, newname) )
{
for( i = 0; i < ArraySize( g_fakeforwards_num ); i++)
{
if( ArrayGetCell(g_fakeforwards_type, i) == Fake_ChangeName )
{
ExecuteForward(ArrayGetCell(g_fakeforwards_num, i), null_id, id, newname)
}
}
}
}
public client_putinserver(id)
{
static i, null_id
for( i = 0; i < ArraySize( g_fakeforwards_num ); i++)
{
if( ArrayGetCell(g_fakeforwards_type, i) == Fake_PutInServer )
{
ExecuteForward(ArrayGetCell(g_fakeforwards_num, i), null_id, id)
}
}
}
And Example for recibe the forwards.
PHP Code:
#include <amxmodx>
#pragma library fake_forwards
enum Fake_Forwards
{
Fake_Connect = 0,
Fake_Disconnect,
Fake_ChangeName,
Fake_PutInServer
}
native register_fakeforward(Fake_Forwards:type, const out[])
native unregister_fakeforward(fwd_id)
public plugin_init()
{
register_plugin("Forward Recive", "1.0", "ReymonARG")
register_fakeforward(Fake_Connect, "fw_client_connect")
register_fakeforward(Fake_Disconnect, "fw_client_disconnect")
register_fakeforward(Fake_ChangeName, "fw_client_changename")
register_fakeforward(Fake_PutInServer, "fw_client_putinserver")
}
public fw_client_connect(id)
{
server_print("Client %d Connecting", id)
}
public fw_client_disconnect(id)
{
server_print("Client %d Disconnect", id)
}
public fw_client_changename(id, const newname[])
{
server_print("Client %d Change name to %s", id, newname)
}
public fw_client_putinserver(id)
{
server_print("Client %d Connect", id)
}