Door system for my RP Gamemode

Hey guys.
I am currently trying to make a door system for my gamemode, but unsure how to make it.
My first goal is getting the doors numbered, meaning everytime server restarts door 1, will be door 1, and door 2 will be door 2.
Should i do it client sided or Server sided? tnx for the help :stuck_out_tongue:

InitPostEntity; ensure no entities spawn before that.

Then, you can set it up one of 3 ways. A) Either use a server-side only command for getting the map-creation id for each door of each map and listing them. The pro to this is that the number will never change, even if you spawn things before InitPostEntity. The con is you’ll have a lot more data to network to the client, especially if you want to draw text on the door.

B) Generate an EntIndex which will always be the same regardless of max-players ( max players affects the EntIndex ); Make a “hashing” function to generate an id that will always be the same, and a “mapping” function to resolve the true EntIndex ( taking max-players into consideration ) based off the stored Generated EntIndex. The pro is that you don’t have to network anything and it can be stored in Lua. This is the method I use; the con is that you need to ensure you generate the correct id and that it is done on an empty map / blank-slate meaning NO entities were spawned before InitPostEntity or it will not be accurate.

C) Grab all doors in the map, assign your 1, 2, 3, etc to each door; the loop should go the same each time so the doors should be labeled the same each time. You’ll still need to network the id, or do something else for drawing on the doors, etc.

Well seems like B is the best option, but what do you mean by generate an EntIndex?

Recent Post:

To generate an ID that will never change ( regardless of max-players from 1-128, as long as no entities are spawned before InitPostEntity ) you’d use this:

local _id = ( ( self:EntIndex( ) + 128 ) - game.MaxPlayers( ) );

To map that to a useable EntIndex ( for Entity( x ) ):

local _index = _id - ( 128 - game.MaxPlayers( );

Turning it into a “Tutorial”…

So, go through the map and use a trace.Entity:GetID( ) to grab the unchanging id and make your data-sets using that id.

When looking at the object and you want to access the data-set ( it is easiest if you use the ID as the key in the table ) do the same thing: trace.Entity:GetID( )…

IF you want to get an Entity from a generated GetID use

local _ent = EntityFromGetID( _id );

– It will return either a valid entity or NULL ( empty entity )…

If you want to grab an EntIndex from a generated ID, use:

local _index = EntIndexFromGetID( _id );

which can then be used within Entity( _index ); to get the entity if it exists.

Hopefully this helps.

You can also use entity:MapCreationID() and to get the entity, you can use ents.GetMapCreatedEntity(id).

Yeah, I listed those along with the pros / cons… Pros being it’ll never change meaning you don’t need to worry about spawning entities before InitPostEntity. Con being for each door, or entity, you want to map to the client for specific info such as property name, color etc, you’d need to network the data to map the entity index to the table key / map creation id.