Hi there!
This can turn out to be very useful when dealing with nested handles. It prints the content of a trie to the server console.
Code:
stock void DEBUG_PrintMapStructure(Handle nh_map, char[] ns_mapnametoshow, char[] ns_prefix)
{
if (nh_map == INVALID_HANDLE)
{
PrintToServer("%s Invalid map Handle: \"%s\" (0)", ns_prefix, ns_mapnametoshow);
return;
}
Handle nh_snapshot = CreateTrieSnapshot(nh_map);
int ni_size = TrieSnapshotLength(nh_snapshot);
PrintToServer("%s Analyzing Map: \"%s\"", ns_prefix, ns_mapnametoshow);
PrintToServer("%s Size of the Map: %i", ns_prefix, ni_size);
for (int ni_i = 0; ni_i < ni_size; ni_i++)
{
int ni_buffersize = TrieSnapshotKeyBufferSize(nh_snapshot, ni_i);
char[] ns_buffer = new char[ni_buffersize];
GetTrieSnapshotKey(nh_snapshot, ni_i, ns_buffer, ni_buffersize);
int ni_value;
PrintToServer("%s #%i. Key: %s | Value: %s", (GetTrieValue(nh_map, ns_buffer, ni_value) ? ni_value : "--probably an array or a string--"));
}
PrintToServer("%s Finished analyzing Map: \"%s\"", ns_prefix, ns_mapnametoshow);
CloseHandle(nh_snapshot);
}
how I called it: DEBUG_PrintMapStructure(table, "DBTable", "[DBScanner.inc]");
the output
Code:
[DBScanner.inc] Analyzing Map: "DBTable"
[DBScanner.inc] Size of the Map: 6
[DBScanner.inc] #1. Key: rows | Value: 3433
[DBScanner.inc] #2. Key: DBTColumnsName | Value: 97124628
[DBScanner.inc] #3. Key: name | Value: --probably an array or a string--
[DBScanner.inc] #4. Key: column_count | Value: 12
[DBScanner.inc] #5. Key: name__size_ | Value: 12
[DBScanner.inc] #6. Key: DBTColumns | Value: 97059132
[DBScanner.inc] Finished analyzing Map: "DBTable"
And if for some reason the handle is 0
DEBUG_PrintMapStructure(0, "VOID TEST", "[DBScanner.inc]");
Code:
[DBScanner.inc] Invalid map Handle: "VOID TEST" (0)