[NS2 CreateEntity] How to spawn an entity in Client VM ?

KatzenfleischKatzenfleisch Join Date: 2014-03-21 Member: 194881Members, Squad Five Blue, Squad Five Silver, NS2 Community Developer
edited March 2014 in Modding
Hi,

I am working on mod and I wonder if there is a way to create entity on Client side only ? In my case I would like to spawn an alien entity which can only be seen and killed by one player (without any perturbation in the server side, for all the other player this one is just shooting at nothing).

I was looking in Utility.lua but CreateEntity is only Server. Any idea ?

Also, if it is possible to render an alien visible to a single marine in the team, this could do the job for what I need.

Thanks.

Comments

  • SewlekSewlek The programmer previously known as Schimmel Join Date: 2003-05-13 Member: 16247Members, NS2 Developer, NS2 Playtester, Squad Five Gold, Subnautica Developer
    you have to create the entity on the server and check "function ViewModel:OnGetIsRelevant(player)" for an example. with that function you can limit relevancy to specific player(s) only. you also need to check out the physics group code, so other players wont be able to collide or shoot that entity.
  • KatzenfleischKatzenfleisch Join Date: 2014-03-21 Member: 194881Members, Squad Five Blue, Squad Five Silver, NS2 Community Developer
    edited March 2014
    After hours of tries and code source reading, I am sorry to ask again. (there are 2 maybe 3 files at least who use this function)

    This is what I found on Weapons/ViewModel.lua
    /**
    * ViewModel is the class which handles rendering and animating the view model
    * (i.e. weapon model) for a player. To use this class, create a 'view_model'
    * entity and set its parent to the player that it will belong to. There should
    * be one view model entity per player (the same view model entity is used for
    * all of the weapons).
    */
    ==> CreateEntity(ViewModel.mapName):SetParent(??)

    But i do not understand really how it should work. For me there are 3 elements
    * The ViewModel class (created via CreateEntity)
    * The "client only" element
    * The player

    Should I create a new class from ViewModel, and then call SetParent ? how do I join those 3 elements ?

    Thanks
  • SewlekSewlek The programmer previously known as Schimmel Join Date: 2003-05-13 Member: 16247Members, NS2 Developer, NS2 Playtester, Squad Five Gold, Subnautica Developer
    you create a new

    class "YourClassName" (ScriptActor)

    function YourClassName:OnGetIsRelevant(player)
    return self.forPlayer == player
    end

    function YourClassName:SetTargetPlayer(forPlayer)
    self.forPlayer = forPlayer
    end


    something like this! you dont need to use SetParent, this would attach the entity to the player, im sure you dont want that. also i dont really understand why you want to derive from view model, it has a very different purpose from what you want
  • KatzenfleischKatzenfleisch Join Date: 2014-03-21 Member: 194881Members, Squad Five Blue, Squad Five Silver, NS2 Community Developer
    edited March 2014
    In fact, I do no want to derive from view model, this was some test to try if it would work.
    The major problem I have while overloading the OnGetIsRelevant() (like you suggest) is that it is never called.

    I have tried the following
    function CLASS:OnGetIsRelevant(player)
    Print("Is called")
    self.forPlayer = player
    end

    with CLASS equal to Player (or) Marine (or) Fade. (Marine -> Player -> ScriptActor)
    I will try later to create a complete new class and see if it work.
  • SewlekSewlek The programmer previously known as Schimmel Join Date: 2003-05-13 Member: 16247Members, NS2 Developer, NS2 Playtester, Squad Five Gold, Subnautica Developer
    you need to call
    self:SetPropagate(Entity.Propagate_Callback)
    in OnCreate
  • KatzenfleischKatzenfleisch Join Date: 2014-03-21 Member: 194881Members, Squad Five Blue, Squad Five Silver, NS2 Community Developer
    I will try today and tell you if its ok.
    Thanks.
  • KatzenfleischKatzenfleisch Join Date: 2014-03-21 Member: 194881Members, Squad Five Blue, Squad Five Silver, NS2 Community Developer
    edited March 2014
    It work like a charm, thanks a lot.
Sign In or Register to comment.