Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Script Help Entity's Location / Distance to Entity
Apjjm Offline
Is easy to say

Posts: 496
Threads: 18
Joined: Apr 2011
Reputation: 52
#10
RE: Entity's Location / Distance to Entity

Replace the Entity Within Range callback section with the following:
///////////////////////////////
//+ 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
///////////////////////////////

You then have access to two new functions:
string GetBaseFromRangeCallback(string &in asChild)
float GetMaxRangeFromRangeCallback(string &in asChild)
These will let you get params from the callback "asChild" parameter without any string operations.

Edit:
Alternative solution using string parsing:
Spoiler below!

change how the attach name is formed into:
string attachName = "RANGECB_"+"$"+asBase+"$"+asEntity+"$"+range;
Add the following stringSplitting function:
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:
stringSplit(asChild,"$")

(This post was last modified: 09-04-2012, 06:11 PM by Apjjm.)
09-04-2012, 06:08 PM
Find


Messages In This Thread
RE: Entity's Location / Distance to Entity - by Apjjm - 09-04-2012, 06:08 PM



Users browsing this thread: 1 Guest(s)