File size: 5,309 Bytes
82d6031
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
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)
}