Currently the developers are putting their own money into JC2-MP to keep the servers online.

Please take a few seconds of your time and disable your AdBlock plugin for our website.

Ad revenue is not going to developers, it is used purely for covering our hosting costs.

 

You are also free to donate, which removes all ads from our website!

Patch 0.3 was just released! Full changelog here: https://t.co/4A50m6IKen

3 years ago

Advertisement
December 05, 2019, 08:47:06 pm

Author Topic: World:GetEntitiesInBounds(Vector3, Vector3)  (Read 1612 times)

Perky

  • Newbie
  • *
  • Posts: 10
    • View Profile
World:GetEntitiesInBounds(Vector3, Vector3)
« on: September 06, 2015, 09:47:53 pm »
A lot of scripts do a lot of distance checking, checking how far a player is from a location etc.

With a large amount of players you can end up with thousands of distance checks which is inefficient.

I suggest a some methods such as
world:GetPlayersInBounds(Vector3, Vector3)
world:GetPlayersInSphere(Vector3, radius)
world:GetVehiclesInBounds(Vector3, Vector3)
world:GetVehiclesInSphere(Vector3, radius)

I'm not sure how you've got it setup within jc-mp, but I'm assuming you're using some kind of spatial partitioning, it makes sense to have the API use that then trying to implement our own octree's etc.

SinisterRectus

  • JC2-MP Betatester
  • Sr. Member
  • *****
  • Posts: 451
    • View Profile
Re: World:GetEntitiesInBounds(Vector3, Vector3)
« Reply #1 on: September 07, 2015, 12:39:22 am »
With 0.2.0, all streamable object classes (Player, Vehicle, Checkpoint, StaticObject, and WorldNetworkObject) have the function GetStreamedPlayers(). This at least gives you the option to check players specific to certain areas.

Also remember that for distance checks, there is DistanceSqr(), which is more efficient for comparing distances.

Each streamable object also has a cell accessible with GetCellId().
« Last Edit: September 07, 2015, 12:48:41 am by SinisterRectus »

Perky

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: World:GetEntitiesInBounds(Vector3, Vector3)
« Reply #2 on: September 07, 2015, 01:09:20 am »
Right, but I think it would be useful to at least have a function to get all streamable objects inside a cell.

SinisterRectus

  • JC2-MP Betatester
  • Sr. Member
  • *****
  • Posts: 451
    • View Profile
Re: World:GetEntitiesInBounds(Vector3, Vector3)
« Reply #3 on: September 07, 2015, 02:03:53 am »
Sure, I just wanted to list some options in case the suggestion is not possible or practical.

Philpax

  • Developer
  • Hero Member
  • *****
  • Posts: 563
    • View Profile
Re: World:GetEntitiesInBounds(Vector3, Vector3)
« Reply #4 on: September 07, 2015, 03:38:41 am »
We've been thinking about this; it might be worth adding. Will look into it.