Last active
July 24, 2023 02:31
-
-
Save assyrianic/c840227319f4d98b079d04c90070b8e6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum { CELL_KEY_SIZE=6 }; | |
stock void PackCellToStr(any key, char buffer[CELL_KEY_SIZE]) { | |
int k = key; | |
buffer[0] = ((k >> (7 * 4)) & 0x7F) | 0x80; | |
buffer[1] = ((k >> (7 * 3)) & 0x7F) | 0x80; | |
buffer[2] = ((k >> (7 * 2)) & 0x7F) | 0x80; | |
buffer[3] = ((k >> (7 * 1)) & 0x7F) | 0x80; | |
buffer[4] = ((k >> (7 * 0)) & 0x7F) | 0x80; | |
buffer[5] = 0x00; | |
} | |
stock char[] GetStrOfPackedCell(any key) { | |
char buffer[CELL_KEY_SIZE]; | |
PackCellToStr(key, buffer); | |
return buffer; | |
} | |
stock any StrToPackCell(const char cell_str[CELL_KEY_SIZE]) { | |
int k = 0; | |
k |= ((cell_str[0] & ~0x80) & 0x7f) << (7 * 4); | |
k |= ((cell_str[1] & ~0x80) & 0x7f) << (7 * 3); | |
k |= ((cell_str[2] & ~0x80) & 0x7f) << (7 * 2); | |
k |= ((cell_str[3] & ~0x80) & 0x7f) << (7 * 1); | |
k |= ((cell_str[4] & ~0x80) & 0x7f) << (7 * 0); | |
return k; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// destroys a StringMap of handle types. | |
/// destroyer => function void(const char[] key, Handle &val); | |
stock void DestroyMapOfHandles(StringMap &strmap, Function destroyer=INVALID_FUNCTION) { | |
if( strmap==null ) { | |
return; | |
} | |
StringMapSnapshot snap = strmap.Snapshot(); | |
if( snap==null ) { | |
return; | |
} | |
int len = snap.Length; | |
for( int i; i < len; i++ ) { | |
int keysize = snap.KeyBufferSize(i) + 1; | |
char[] key = new char[keysize + 1]; | |
snap.GetKey(i, key, keysize); | |
Handle a; strmap.GetValue(key, a); | |
Callable call; call.StartFunction(null, destroyer); | |
call.PushString(key, keysize, _, false); | |
call.PushCellRef(a); | |
call.Finish(); | |
delete a; /// just in case. | |
} | |
delete snap; | |
delete strmap; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stock bool IsInRange(int entity, int target, float dist, bool trace=false) { | |
float entity_pos[3]; GetEntPropVector(entity, Prop_Data, "m_vecAbsOrigin", entity_pos); | |
float target_pos[3]; GetEntPropVector(target, Prop_Data, "m_vecAbsOrigin", target_pos); | |
bool within_range = GetVectorDistance(entity_pos, target_pos, true) <= dist*dist; | |
if( within_range && trace ) { | |
TR_TraceRayFilter(entity_pos, target_pos, MASK_SHOT, RayType_EndPoint, TraceRayDontHitSelf, entity); | |
return TR_GetFraction() > 0.98; | |
} | |
return within_range; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stock bool IsValidPlugin(Handle plugin) { | |
PluginIterator iter = new PluginIterator(); | |
bool res = false; | |
while( iter.Next() && !res ) { | |
res = iter.Plugin == plugin; | |
} | |
delete iter; | |
return res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment