diff --git a/scripting/dump_parser.sp b/scripting/dump_parser.sp index e045516..8ce67ac 100644 --- a/scripting/dump_parser.sp +++ b/scripting/dump_parser.sp @@ -39,7 +39,9 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max { CreateNative("GetDumpStringMap", Native_GetDumpStringMap); CreateNative("GetDumpEntityAsList", Native_GetDumpEntityAsList); + CreateNative("GetDumpEntityAsArray", Native_GetDumpEntityAsArray); CreateNative("GetDumpEntityFromID", Native_GetDumpEntityFromID); + CreateNative("GetDumpEntityFromIDAsArray", Native_GetDumpEntityFromIDAsArray); CreateNative("GetDumpEntities", Native_GetDumpEntities); CreateNative("IsDumpReady", Native_IsDumpReady); @@ -483,6 +485,48 @@ public any Native_GetDumpEntityAsList(Handle plugin, int numParams) return list; } +// native bool GetDumpEntityAsArray(int index, any[] entity); +public any Native_GetDumpEntityAsArray(Handle plugin, int numParams) +{ + if(!gB_Ready) + { + //LogError("Native called before dump file has been processed."); + return false; + } + if(gA_Entites.Length < 1 || gSM_EntityList.Size < 1) + { + //LogError("Entity lists are empty."); + return false; + } + + int index = GetNativeCell(1); + int hammer = GetHammerFromIndex(index); + char id[MEMBER_SIZE]; + IntToString(hammer, id, MEMBER_SIZE); + + int position = -1; + if(!gSM_EntityList.GetValue(id, position)) + { + //LogError("Could not find entity with with the index '%i', hammmerid '%i'.", index, hammer); + return false; + } + + if(position >= gA_Entites.Length || position < 0) + { + //LogError( "List position out of range"); + return false; + } + + Entity temp; + gA_Entites.GetArray(position, temp); + + Entity ent; + CloneEntity(temp, ent); + SetNativeArray(2, ent, sizeof(Entity)); + + return true; +} + // native ArrayList GetDumpEntityFromID(int ent); public any Native_GetDumpEntityFromID(Handle plugin, int numParams) { @@ -525,6 +569,47 @@ public any Native_GetDumpEntityFromID(Handle plugin, int numParams) return list; } +// native bool GetDumpEntityFromIDAsArray(int hammerid, any[] entity); +public any Native_GetDumpEntityFromIDAsArray(Handle plugin, int numParams) +{ + if(!gB_Ready) + { + //LogError("Native called before dump file has been processed."); + return false; + } + if(gA_Entites.Length < 1 || gSM_EntityList.Size < 1) + { + //LogError("Entity lists are empty."); + return false; + } + + int hammer = GetNativeCell(1); + char id[MEMBER_SIZE]; + IntToString(hammer, id, MEMBER_SIZE); + + int position = -1; + if(!gSM_EntityList.GetValue(id, position)) + { + //LogError("Could not find entity with that index."); + return false; + } + + if(position >= gA_Entites.Length || position < 0) + { + //LogError("List position out of range"); + return false; + } + + Entity temp; + gA_Entites.GetArray(position, temp); + + Entity ent; + CloneEntity(temp, ent); + + + return true; +} + // native ArrayList GetDumpEntities(); public any Native_GetDumpEntities(Handle plugin, int numParams) { diff --git a/scripting/include/dump_parser.inc b/scripting/include/dump_parser.inc index bafba8d..eff3451 100644 --- a/scripting/include/dump_parser.inc +++ b/scripting/include/dump_parser.inc @@ -148,13 +148,26 @@ forward void OnDumpFileReady(); forward void OnDumpFileProcessed(); /* * -* Retrieves a copy of the 'Entity' enum struct for the given index and places it inside an ArrayList. +* Retrieves a copy of the 'Entity' enum struct, as an any array, for the given entity index. * The ArrayList will not be cleared automatically. * Use the GetDumpEntity stock instead. * * Param: index Entity index. +* Param: entity Entity enum struct as an any array if found. * -* return: ArrayList containing the Entity enum struct if found, INVALID_HANDLE otherwise. +* return: true if successful, false otherwise. +* */ +native bool GetDumpEntityAsArray(int index, any[] entity); + +/* * +* Retrieves a copy of the 'Entity' enum struct for the given entity index and places it inside an ArrayList. +* The ArrayList will not be cleared automatically. +* Use the GetDumpEntity stock instead. +* +* Param: index Entity index. +* Param: entity Entity enum struct as generic any array +* +* return: true if successful, false otherwise. * */ native ArrayList GetDumpEntityAsList(int index); @@ -168,15 +181,7 @@ native ArrayList GetDumpEntityAsList(int index); * */ stock bool GetDumpEntity(int index, Entity ent) { - ArrayList temp = GetDumpEntityAsList(index); - if(temp != INVALID_HANDLE && temp != null) - { - temp.GetArray(0, ent); - delete temp; - return true; - } - delete temp; - return false; + return GetDumpEntityAsArray(index, ent); } /* * @@ -190,6 +195,18 @@ stock bool GetDumpEntity(int index, Entity ent) * */ native ArrayList GetDumpEntityFromID(int hammerid); +/* * +* Retrieves a copy of the 'Entity' enum struct from the given hammer id. +* The ArrayList will not be cleared automatically. +* Use the GetDumpEntity2 stock instead. +* +* Param: hammerid Hammer id of the entity. +* Param: entity Entity enum struct as generic any array +* +* return: true if successful, false otherwise. +* */ +native bool GetDumpEntityFromIDAsArray(int hammerid, any[] entity); + /* * * Retrieves a copy of the 'Entity' enum struct for the given hammer id. * @@ -200,15 +217,7 @@ native ArrayList GetDumpEntityFromID(int hammerid); * */ stock bool GetDumpEntity2(int hammerid, Entity ent) { - ArrayList temp = GetDumpEntityFromID(hammerid); - if(temp != INVALID_HANDLE && temp != null) - { - temp.GetArray(0, ent); - delete temp; - return true; - } - delete temp; - return false + return GetDumpEntityFromIDAsArray(hammerid, ent); } /* * @@ -497,7 +506,9 @@ public void __pl_output_dump_parser_SetNTVOptional() { MarkNativeAsOptional("GetDumpStringMap"); MarkNativeAsOptional("GetDumpEntityAsList"); + MarkNativeAsOptional("GetDumpEntityAsArray"); MarkNativeAsOptional("GetDumpEntityFromID"); + MarkNativeAsOptional("GetDumpEntityFromIDAsArray"); MarkNativeAsOptional("GetDumpEntities"); MarkNativeAsOptional("IsDumpReady"); }