How to check if an entity handle is still usable?

SlightSlight Join Date: 2011-06-29 Member: 107082Members
<div class="IPBDescription">To prevent "Attempt to use an object that no longer exists" er</div>Say I get a handle on a player, but that player dies. The handle is no longer usable. How can I check this? In GMod it was entity:IsValid().

Comments

  • 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
    OnEntityChange(oldId, newId) is called on all ScriptActor derived entitys when stuff dies or players change class
  • SlightSlight Join Date: 2011-06-29 Member: 107082Members
    edited July 2011
    So I am to refactor my code to use this method instead of some HandleIsValid(obj) method? I feel like there will be problems with this in the future.

    It seems odd that the player object will be notifying all objects that are interacting with it that it is changing ids.

    There should be a way to get a handle on a player that does not change through deaths and only is destroyed when the client disconnects. Perhaps with a method GetActor() to get the current LiveActor the player controls. There's a lot of problems that require what seem like work arounds rather than alternative design decisions. For one, with no persistent player object, all lua variables tied to the player are lost when the player dies or switches class.

    Thanks for the info nonetheless.
  • PlasmaPlasma Join Date: 2003-04-26 Member: 15855Members, Constellation, Squad Five Blue
    I haven't messed with any NS2 scripting; but could you make a wrapper class that you use to retrieve the Id?

    So you always pass around a CurrentHandle object, which knows to update itself when the ID changes.

    Caller's won't need to know about the underlying ID necessarily changing.

    Alternatively, check out how the current NS2 code handles this problem?
  • 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
    <!--quoteo(post=1858488:date=Jul 7 2011, 05:41 AM:name=Slight)--><div class='quotetop'>QUOTE (Slight @ Jul 7 2011, 05:41 AM) <a href="index.php?act=findpost&pid=1858488"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->There should be a way to get a handle on a player that does not change through deaths and only is destroyed when the client disconnects.<!--QuoteEnd--></div><!--QuoteEEnd-->

    <a href="http://www.unknownworlds.com/ns2/wiki/index.php/Lua/Objects/ServerClient" target="_blank">http://www.unknownworlds.com/ns2/wiki/inde...ts/ServerClient</a>
  • SlightSlight Join Date: 2011-06-29 Member: 107082Members
    <!--quoteo(post=1858496:date=Jul 6 2011, 11:11 PM:name=Plasma)--><div class='quotetop'>QUOTE (Plasma @ Jul 6 2011, 11:11 PM) <a href="index.php?act=findpost&pid=1858496"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->I haven't messed with any NS2 scripting; but could you make a wrapper class that you use to retrieve the Id?

    So you always pass around a CurrentHandle object, which knows to update itself when the ID changes.

    Caller's won't need to know about the underlying ID necessarily changing.

    Alternatively, check out how the current NS2 code handles this problem?<!--QuoteEnd--></div><!--QuoteEEnd-->
    Doing a wrapper class might be possible iff the above hook is called when an entity id goes invalid as well. Otherwise, no its still not feasible.

    I did search the NS2 code quite extensively and checked the function dump as well. No luck. Even NS2 code throws "tried to use invalid object" errors in console every now and then.

    <!--quoteo(post=1858503:date=Jul 6 2011, 11:42 PM:name=fsfod)--><div class='quotetop'>QUOTE (fsfod @ Jul 6 2011, 11:42 PM) <a href="index.php?act=findpost&pid=1858503"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec--><a href="http://www.unknownworlds.com/ns2/wiki/index.php/Lua/Objects/ServerClient" target="_blank">http://www.unknownworlds.com/ns2/wiki/inde...ts/ServerClient</a><!--QuoteEnd--></div><!--QuoteEEnd-->
    Ok cool, but a clientside version would be nice as well.
Sign In or Register to comment.