Entity visibility

McGlaspieMcGlaspie www.team156.com Join Date: 2010-07-26 Member: 73044Members, Super Administrators, Forum Admins, NS2 Developer, NS2 Playtester, Squad Five Blue, Squad Five Silver, Squad Five Gold, Reinforced - Onos, WC 2013 - Gold, Subnautica Playtester
Yo,
Just wanted to ask some of the folks here that have had more experience with NS2 than I have (pertaining to Lua). Is there a simple way to determine if an entity is visible on screen? I don't really care if the entity's model should be visible or not, but rather if the entity is currently visible in a player's camera viewpoint.

Thanks.

Comments

  • yimmasabiyimmasabi Join Date: 2006-11-03 Member: 58318Members
    All entities are visible with objects e.g. red box for the team location but only in Spark Editor. Also Opening doors and hive locations (power grids) are visible in player mode too.

    Only some of them are invisible, why do you need to see them ?
  • McGlaspieMcGlaspie www.team156.com Join Date: 2010-07-26 Member: 73044Members, Super Administrators, Forum Admins, NS2 Developer, NS2 Playtester, Squad Five Blue, Squad Five Silver, Squad Five Gold, Reinforced - Onos, WC 2013 - Gold, Subnautica Playtester
    I'm interested in getting a table of objects that are currently visible to X player. I then want to perform a few actions on those objects based on which team a player is on.
  • McGlaspieMcGlaspie www.team156.com Join Date: 2010-07-26 Member: 73044Members, Super Administrators, Forum Admins, NS2 Developer, NS2 Playtester, Squad Five Blue, Squad Five Silver, Squad Five Gold, Reinforced - Onos, WC 2013 - Gold, Subnautica Playtester
    I've looked through the current Lua code and there isn't anything like what I'm looking for. So, thanks anyways.
  • MCMLXXXIVMCMLXXXIV Join Date: 2010-04-14 Member: 71400Members
    You might be able to use the function that the grenade explosions use to work this out? Not peeked in there yet myself but there may be a hint on how to check for entities in an area.
  • McGlaspieMcGlaspie www.team156.com Join Date: 2010-07-26 Member: 73044Members, Super Administrators, Forum Admins, NS2 Developer, NS2 Playtester, Squad Five Blue, Squad Five Silver, Squad Five Gold, Reinforced - Onos, WC 2013 - Gold, Subnautica Playtester
    edited August 2010
    I had similar thoughts. I found the closest thing to what I'm looking for in the Entity.lua file:

    <div class='codetop'>CODE</div><div class='codemain' style='height:200px;white-space:pre;overflow:auto'>function GetEntitiesInViewFunctor(player, functor)
    local entities = {}
    local startEntity = nil
    local currentEntity = nil

    repeat
    currentEntity = Shared.FindNextEntity(startEntity)
    if currentEntity and currentEntity:isa("ScriptActor") then
    if(functor(currentEntity)) then
    if(player:GetCanSeeEntity(currentEntity)) then
    table.insert(entities, currentEntity)
    end
    end
    end

    startEntity = currentEntity
    until currentEntity == nil

    return entities
    end</div>

    I think it should work with some very minor modifications. Now, I wonder if I can tag this inside of Client.OnPostRender()...we'll find out soon enough.

    Edit: Btw, I realize how potentially slow this could be, and I see it will poll damn near every active entity in the game. That's why I said "with some modifications".
  • fsfodfsfod uk Join Date: 2004-04-09 Member: 27810Members, NS2 Developer, Constellation, NS2 Playtester, Squad Five Blue, Squad Five Silver, Squad Five Gold, Subnautica Playtester, NS2 Community Developer, Pistachionauts
    edited August 2010
    The PostRender hook doesn't exist anymore sadly
  • McGlaspieMcGlaspie www.team156.com Join Date: 2010-07-26 Member: 73044Members, Super Administrators, Forum Admins, NS2 Developer, NS2 Playtester, Squad Five Blue, Squad Five Silver, Squad Five Gold, Reinforced - Onos, WC 2013 - Gold, Subnautica Playtester
    Oh man, I think I'm going to go cry in a corner somewhere. That makes me a sad Panda... *sigh*
    So much for that idea.
Sign In or Register to comment.