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 Possible to set an radius to an object?
Neelke Offline
Senior Member

Posts: 668
Threads: 82
Joined: Apr 2013
Reputation: 26
#1
Possible to set an radius to an object?

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?

Derp.
02-27-2015, 10:29 PM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#2
RE: Possible to set an radius to an object?

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.

02-27-2015, 11:40 PM
Find
Neelke Offline
Senior Member

Posts: 668
Threads: 82
Joined: Apr 2013
Reputation: 26
#3
RE: Possible to set an radius to an object?

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.

Derp.
(This post was last modified: 02-27-2015, 11:52 PM by Neelke.)
02-27-2015, 11:50 PM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#4
RE: Possible to set an radius to an object?

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.

02-28-2015, 12:00 AM
Find
Neelke Offline
Senior Member

Posts: 668
Threads: 82
Joined: Apr 2013
Reputation: 26
#5
RE: Possible to set an radius to an object?

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:

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;            
}

Derp.
02-28-2015, 12:02 AM
Find
Daemian Offline
Posting Freak

Posts: 1,129
Threads: 42
Joined: Dec 2012
Reputation: 49
#6
RE: Possible to set an radius to an object?

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.

02-28-2015, 12:05 AM
Find
Neelke Offline
Senior Member

Posts: 668
Threads: 82
Joined: Apr 2013
Reputation: 26
#7
RE: Possible to set an radius to an object?

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

Derp.
02-28-2015, 12:07 AM
Find
Daemian Offline
Posting Freak

Posts: 1,129
Threads: 42
Joined: Dec 2012
Reputation: 49
#8
RE: Possible to set an radius to an object?

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

02-28-2015, 12:07 AM
Find
Neelke Offline
Senior Member

Posts: 668
Threads: 82
Joined: Apr 2013
Reputation: 26
#9
RE: Possible to set an radius to an object?

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.

Derp.
02-28-2015, 12:17 PM
Find




Users browsing this thread: 1 Guest(s)