///////////////////////////////
//+ Entity Within Range Callback
///////////////////////////////
//Add a callback for when asEntity is within <maxRange> of asBase (collision callback). asBase must allow attachments.
//Duplicate identical attachments (range+base+entity are identical) behaviour is undefined.
void AddEntityWithinRangeCollideCallback(string &in asBase, string &in asEntity, string &in asCallback, int alStates, float maxRange)
{
float range = GetRangeValCeil(maxRange);
string attachName = "RANGECB_"+asBase+asEntity+range;
AddAttachedPropToProp(asBase,attachName,GetRangeFileName(range),0,0,0,0,0,0);
AddEntityCollideCallback(asEntity,attachName,asCallback,false,alStates);
//Set local vars for getter functions
SetLocalVarString("Base_" + attachName,asBase);
SetLocalVarFloat("Range_" + attachName,maxRange);
}
//Remove a range callback and associated attachments
void RemoveEntityWithinRangeCollideCallback(string &in asBase, string &in asEntity, float maxRange)
{
float range = GetRangeValCeil(maxRange);
string attachName = "RANGECB_"+asBase+asEntity+range;
RemoveEntityCollideCallback(asEntity,attachName);
RemoveAttachedPropFromProp(asBase,attachName);
//Reset Local vars
SetLocalVarString("Base_" + attachName,"");
SetLocalVarFloat("Range_" + attachName,0);
}
//Get the base entity from the range callback
string GetBaseFromRangeCallback(string &in asChild)
{
return GetLocalVarString("Base_" + asChild);
}
//Get the base entity from the range callback
float GetMaxRangeFromRangeCallback(string &in asChild)
{
return GetLocalVarFloat("Range_" + asChild);
}
///////////////////////////////
//- Entity Within Range Callback
///////////////////////////////
string[] stringSplit(string &in asString, string asDelim)
{
string[] output = {""};
//For each character in the input, check against the output.
int s1 = int(asString.length()); int s2 = int(asDelim.length());
int lastMatch = 0;
//Add all but final elements
for(int i=0; i<=s1 - s2; i++)
{
if(StringSub(asString,i,s2) == asDelim)
{
//Add element to output
output[output.length() - 1] = StringSub(asString,lastMatch,i-lastMatch);
output.resize(output.length() + 1);
//Move search along
i += s2;
lastMatch = i;
}
}
//Add lastMatch -> final
output[output.length() - 1] = StringSub(asString,lastMatch,s1 - lastMatch);
return output;
}
You can then manually split asChild into an array using: