Entity spawn on player join.

Hello I have been searching for a way to spawn entities when people of a specific rank(vip/superadmin) join the server with no luck. The entity I have wanted to spawn was from this addon http://steamcommunity.com/sharedfiles/filedetails/?id=358253236. Could anyone help me out with this please!?

If you want to have admins spawn with the wings on their back, there are a number of ways to do this. The 2 obvious choices are to spawn the wings as an entity ( func_detail should work ) position them on the character ( if you use LocalToWorld then it handles all of the Rotate Around Axis / math so you only need to know the vector offset that the wings are on the player in addition to the angles… The players feet are 0 0 0 and the head is 0 0 72 or so in Vector. Rotation will likely be 0 0 0, or 0 -90 0, or 0 180 0, or 0 90 0… ie altering the yaw in 90 degree increments ).

After you spawn the entity, and positioned it where it needs to be then you’d parent it to the player… There are some downsides to this method: You’re creating a new entity on the server which is essentially pointless / aesthetics which decreases the number of entities players can spawn. You’re going to run into issues of the wings floating around the map unless done absolutely 100% correct because when the player leaves the known area of a client, the wings “detach” and won’t be able to find the correct location on your screen… Etc…

Method 2: You can use the PostPlayerDraw to draw the wings, on the client, manually by attaching it to a bone or using the LocalToWorld method. The benefit of doing something this way is the server doesn’t need to know about it, the clients can have a setting to block it if they don’t want to see it ( to prevent memory increasing from additional model ), etc…

There are other ways, such as using BoneMerge ( I’ve never used it ), etc…

Now, when a client connects to the server you may encounter some issues ( ie, if that player never came near-enough to the local player / client that will end up seeing the admin, then the client won’t know about the entity, ie it’ll say the admin is a null entity until the player gets close enough to them which is around 5000 units; 4/3 in game units == 1 inch so 16 units in game is 1 foot…

If I completely missed the ball and you just want to spawn entities when the map starts ( but when an admin joins ) simply use OnEntityCreated on the server ( client calls this when a player enters PVS in case you decide on manually managing the wings ).

I think you misunderstand what the addon I linked to is. It is an entity that automatically goes onto a players back no just a prop. I simply need a little script that can spawn it and make a player the owner of it.

Try with:




hook.Add( "PlayerInitialSpawn", "GiveWings", function( _p )

    if( _p:IsAdmin() )
        local _e = ents.Create( "wings_color" );
        _e:SetPos( _p:GetPos() );
        _e:Spawn();
        _e:Activate();
        _e:SetOwner(  _p );
        _e:SetParent( _p );
        _p.Wings = _e;
    end
end );


or this copied from ENT.SpawnFunction:



hook.Add( "PlayerInitialSpawn", "GiveWings", function( _p )
    local ent = scripted_ents.GetStored( "wings_color" );
    ent.t:SpawnFunction( _p, _p:GetEyeTrace() );
end );


Sadly neither worked. In fact the second one caused my server to totally bug out and make people spawn in with the old old gray gordon freeman player models with no sweps.

After some tweaking with your code I got it to work! Thanks a ton!