public Native_AddDataStruct(Handle:plugin, numParams) { new data[struct_data]; GetNativeArray(1, data, struct_data); data[m_plugin] = plugin;
PushArrayArray(array_Data, data); PrintToServer("[DEBUG] core: key '%s' by plugin ID '%d'", data[m_key], plugin); }
public Native_GetDataStructByName(Handle:plugin, numParams) { new String:key[32]; GetNativeString(1, key, 32); PrintToServer("[DEBUG] core: Looking for a data from '%s'...", key);
new data[struct_data];
for (new i; i < GetArraySize(array_Data); i++) { GetArrayArray(array_Data, i, data);
PrintToServer("[DEBUG] core: is key '%s' equal to '%s' and plugin ID %d equal to '%d'?", data[m_key], key, plugin, data[m_plugin]);
if (data[m_plugin] == plugin && StrEqual(data[m_key], key, true)) { PrintToServer("[DEBUG] core: key '%s' was found!", key); SetNativeArray(2, data, struct_data); return true; } continue; } PrintToServer("[DEBUG] core: raw data was not found!"); return false; }
public Native_GetRawDataStructByName(Handle:plugin, numParams) { new String:key[32]; GetNativeString(1, key, 32);
PrintToServer("[DEBUG] core: Looking for a raw data from '%s'...", key);
new data[struct_data];
for (new i; i < GetArraySize(array_Data); i++) { GetArrayArray(array_Data, i, data);
PrintToServer("[DEBUG] core: is key '%s' equal to '%s'?", data[m_key], key);
if (StrEqual(data[m_key], key, true)) { PrintToServer("[DEBUG] core: key '%s' was found from plugin ID '%d'!", key, data[m_plugin]); SetNativeArray(2, data, struct_data); return true; } } PrintToServer("[DEBUG] core: raw data was not found!"); return false; }
mycore.inc
Spoiler
PHP Code:
#if defined _mycore_included #endinput #endif #define _mycore_included
public Action:mycallback(client, argc) { if (argc != 1) { PrintToServer("wrong arguments for 'plugin1'!"); return Plugin_Handled; }
new String:buffer[32]; GetCmdArg(1, buffer, 32);
new data[struct_data]; if (GetDataStructByName(buffer, data)) { PrintToServer("[DEBUG] plugin1: key '%s' value '%d'.", data[m_key], data[m_value]); } else { PrintToServer("[DEBUG] plugin1: key '%s' do not exist from plugin ID '%d'", buffer, GetMyHandle()); }
return Plugin_Handled; }
public Action:mycallback2(client, argc) { if (argc != 1) { PrintToServer("wrong arguments for 'plugin1_raw'!"); return Plugin_Handled; }
new String:buffer[32]; GetCmdArg(1, buffer, 32);
new data[struct_data]; if (GetRawDataStructByName(buffer, data)) { PrintToServer("[DEBUG] plugin1: key '%s' value %d from plugin ID '%d'.", data[m_key], data[m_value], data[m_plugin]); } else { PrintToServer("[DEBUG] plugin1: key '%s' do not exist at all!", buffer); }
public Action:mycallback(client, argc) { if (argc != 1) { PrintToServer("wrong arguments for 'plugin2'!"); return Plugin_Handled; }
new String:buffer[32]; GetCmdArg(1, buffer, 32);
new data[struct_data]; if (GetDataStructByName(buffer, data)) { PrintToServer("[DEBUG] plugin2: key '%s' value '%d'.", data[m_key], data[m_value]); } else { PrintToServer("[DEBUG] plugin2: key '%s' do not exist from plugin ID '%d'", buffer, GetMyHandle()); }
return Plugin_Handled; }
public Action:mycallback2(client, argc) { if (argc != 1) { PrintToServer("wrong arguments for 'plugin2_raw'!"); return Plugin_Handled; }
new String:buffer[32]; GetCmdArg(1, buffer, 32);
new data[struct_data]; if (GetRawDataStructByName(buffer, data)) { PrintToServer("[DEBUG] plugin2: key '%s' value '%d' from plugin ID '%d'.", data[m_key], data[m_value], data[m_plugin]); } else { PrintToServer("[DEBUG] plugin2: key '%s' do not exist at all!", buffer); }
return Plugin_Handled; }
I did not put all the checks and memory cleanup when one of the plugin unload but I will do it later and also GetRawDataStructByName only return the first one found. I will edit it later.
I have no fucking idea what this does but I converted it to the new syntax for no reason lol.
I prob converted it wrong but here it is
PHP Code:
#include <sourcemod> #include <mycore>
ArrayList array_Data = null;
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max) { array_Data = new ArrayList(struct_data); CreateNative("AddDataStruct", Native_AddDataStruct); CreateNative("GetDataStructByName", Native_GetDataStructByName); CreateNative("GetRawDataStructByName", Native_GetRawDataStructByName); }
public int Native_AddDataStruct(Handle plugin, int numParams) { int data[struct_data]; GetNativeArray(1, data, struct_data); data[m_plugin] = plugin;
array_Data.PushArray(data); //PushArrayArray(array_Data, data); PrintToServer("[DEBUG] core: key '%s' by plugin ID '%d'", data[m_key], plugin); }
public int Native_GetDataStructByName(Handle plugin, int numParams) { char key[32]; GetNativeString(1, key, 32); PrintToServer("[DEBUG] core: Looking for a data from '%s'...", key);
int data[struct_data];
for (int i; i < array_Data.Length; i++) //GetArraySize(array_Data); i++) { array_Data.GetArray(i, data); //GetArrayArray(array_Data, i, data);
PrintToServer("[DEBUG] core: is key '%s' equal to '%s' and plugin ID %d equal to '%d'?", data[m_key], key, plugin, data[m_plugin]);
if (data[m_plugin] == plugin && StrEqual(data[m_key], key, true)) { PrintToServer("[DEBUG] core: key '%s' was found!", key); SetNativeArray(2, data, struct_data); return view_as<int>(true); } continue; } PrintToServer("[DEBUG] core: raw data was not found!"); return view_as<int>(false); }
public int Native_GetRawDataStructByName(Handle plugin, int numParams) { char key[32]; GetNativeString(1, key, 32);
PrintToServer("[DEBUG] core: Looking for a raw data from '%s'...", key);
int data[struct_data];
for (int i; i < array_Data.Length; i++) //(new i; i < GetArraySize(array_Data); i++) { array_Data.GetArray(i, data); //GetArrayArray(array_Data, i, data); PrintToServer("[DEBUG] core: is key '%s' equal to '%s'?", data[m_key], key);
if (StrEqual(data[m_key], key, true)) { PrintToServer("[DEBUG] core: key '%s' was found from plugin ID '%d'!", key, data[m_plugin]); SetNativeArray(2, data, struct_data); return view_as<int>(true); } } PrintToServer("[DEBUG] core: raw data was not found!"); return view_as<int>(false); }
#if defined _mycore_included #endinput #endif #define _mycore_included
// ignore m_plugin this is used by core
enum struct_data { Handle m_plugin, char m_key[32], int m_value };