Frictional Games Forum (read-only)
[SCRIPT] Possible to set an radius to an object? - Printable Version

+- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum)
+-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html)
+--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html)
+---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html)
+---- Thread: [SCRIPT] Possible to set an radius to an object? (/thread-29679.html)



Possible to set an radius to an object? - Neelke - 02-27-2015

So I want to set some form of radius system to a monster in one of levels. If the player leaves the radius, the enemy is gonna do some things.

I looked up on the forum and I noticed that Apjjm had made a radius system for an explosive, but sadly I'm not that skillful with scripting, so I didn't understand everything. Does anyone know how can you apply a radius to an object in more explained term?


RE: Possible to set an radius to an object? - Mudbill - 02-27-2015

Now that you can use GetEntityPos and GetPlayerPos it should be relatively simple to make. You can use a timer loop to update the checker. It probably won't need a higher frequency than 1 second update time.

I haven't thought out exactly how this would work, but if you experiment with those functions you might figure something out. Basically, create a variable for the position of the player and the position of the entity (enemy). Do some calculations to determine the difference in those two. If that difference exceeds what radius you need, run your things.


RE: Possible to set an radius to an object? - Neelke - 02-27-2015

I'm probably annoying as all hell here, but without 1.3.

I was thinking tho that I might be able to implement GetEntityPos and GetPlayerPos as custom functions in the script somehow.


RE: Possible to set an radius to an object? - Mudbill - 02-28-2015

How do you not have 1.3?

Doing so otherwise will be tricky. I can't think of how at the top of my head.


RE: Possible to set an radius to an object? - Neelke - 02-28-2015

As I mentioned in the above thread, Apjjm made that work with radius in 1.2. However, I've been looking at his script for a damn long time trying to figure out everything. I've found these two of his custom functions, relating to Pythagoras Theorem:

Code:
const uint32 _SQRTITERATIONS=5; //Maximum number of iterations for sqrt computation
const float  _SQRTDELTA=0.01f; //Margin of error allowable if complete before iteration ceiling

//Determines if two numbers are approximately equal (Differ by no more than epsilon)
bool approx(float &in x, float &in y, float &in epsilon) {
    float delta = x-y;
    return ((delta>0?delta:-delta) <= (epsilon>0?epsilon:-epsilon));
  }

//Sqrt of a number
float sqrt(float &in x) {
  if(x<=0) return 0; //Early out - not valid input.
  uint32 i = 0; float o = x * 0.5f;
  while( i<_SQRTITERATIONS && !approx(o*o,x,_SQRTDELTA) && o != 0)
    { o = 0.5f * (o + x/o); i++; }
  return o;            
}



RE: Possible to set an radius to an object? - Daemian - 02-28-2015

If you can move areas as entities you could have one following your monster and use a collide callback to detect the player coming in/out.


RE: Possible to set an radius to an object? - Neelke - 02-28-2015

Yea, good idea. I could use AddAttachedPropToProp function and stick it to the enemy. Let me try it.


RE: Possible to set an radius to an object? - Daemian - 02-28-2015

Why are you afraid of the new patch? Is not beta anymore.


RE: Possible to set an radius to an object? - Neelke - 02-28-2015

Well I couldn't get it working with the suggestion you brought up, Daemian.

And there are some main reasons I don't want the 1.3 patch. Firstly, my other two mods have not required 1.3, only 1.2 and I want to keep that pattern and not add in some extra content because I need to get one level working with scripts.

Secondly, it still has some flaws here and there, along with the skybox glitch as Mudbill and Fatalist has brought up. I'm using some skyboxes here and there as well, and I don't want the same issue atm.

Maybe I'll add in 1.3 patch when I'm done with my mod, but not right now at least.


But in short, it still doesn't work. I tried attaching a radius detection entity with a collide function applied to it to the enemy, updating it each 0.625 seconds. The entity didn't even spawn.