Does anyone know a way to store Doors based upon a map to SQL? Like when I load the map will using the EntityIndex of that door work to load the data for it that was saved through SQL? I just worry about the door or certain entity being otherwise mistaken for something else.
Some maps' have unique names for the entities/doors, using these unique names is probably the best way to save data for entities.
The name (if it has one) can be retrieved with Entity.GetName
When I was doing something like this I had to use the door's position, as it's the only thing that stood constant through map changes.
>>oubliette<< mentions the custom names for doors, those are entity "tags" stored in the entity list of a map. However, I feel that it is unsafe to rely on such a field, since many mappers can disregard it and leave it blank. You should have files that spawn doors (JSON or something) and a script that removes the default doors inside maps. This will ensure that all doors are made to your standards.
Don't just store door positions, have a list of TableToJSON strings in a file ('data/mydoors' folder) that include x,y,z real values and other stuff like name and model. Every door entry will end up being one line.
As you mentioned, the doors are constant throughout maps and are therefore not being saved/synchronized real-time (apart from their entites in-game). You would be better off saving that stuff in a file. SQL will get messy once you try to change something (since the DB is already made a certain way). That's just my take on it.
If you really want SQL to do the work, you would probably be well off keeping a table var of the door stuff server-side and just send to SQL.
[editline]11th March 2013[/editline]
You could use the server's ent table and just send to SQL from the list (the already suggested method) and use the ENT:GetName()/ENT:SetName() as an identifier (the 'Name' of an entity is the very 'tag' property that we were talking about). Using ent id's as you suggested is risky, since at different circumstances, the order of created ents at map start could very well change.
So anyways, here's an outline of what I was thinking:
[b]Lua server-sided table var of doors[/b]
Key: "door1_bathroom" ; Value: <pointer to ent>
Key: "door2_adminroom" ; Value: <pointer to ent>
Key: "door3_fuckknowswhere" ; Value: <pointer to ent>
When saving to SQL, use a for loop through the table and save the Key as the ID of the door, and do ENT:GetAngles(), ENT:GetPos(), ENT:GetPhysicsProp():FunctionToGetModel(), etc to the value to save the rest of the fields.
OR you could just have a table of Entites as keys with no values (or even the hard-coded ent table itself), and use the ENT:GetName() instead of the original lua-based key that I proposed. If you are using the Source engine ent table, I you have to find by class. But you probably already know that ;)
Sorry, you need to Log In to post a reply to this thread.