ents.Create : entity not valid

Hi all, (again)

So i’m still on my gamemode developpement. Actually, i think you know, i’m making an inventory to stock every player props, weapons, ammo, every type of entity in the game.
To do it, i need several steps :

  • Client recieving data from server : Done !
  • Client rendering items in a single DFrame bound to spawn menu key : Done !
  • Server saving data to hard disk : Not began, will need C++ !
  • Table data needs valid entities : ERROR !!

So you understand, the error is in the inventory table, witch contains some entities created by ents.Create but not spawned.
The entities that are created by ents.Create are not valid. They are valids only if you spawn them. Only one problem : these entities are spawned only when the client requests to. So when the server creates entities from the entity class, i get an unusable entity. I can just spawn it and set it position. But i don’t want that until player requests it. I need client to render the not spawned entity in the DModelPanel.

You don’t need a C module to save data. I’d recommend using MySQL or SQLite to save data. Alternatively, you can store in txt files…


Creating a file, using an index file to numerically increment value of next file…

Converting playerpdata SQLite table to MySQL insert queries, incorporates SQLite usage for queries ( there is also a simple means to query data by using GetPData and SetPData on the Player Entity ), saving the queries output to txt…

I’m not asking about saving data. Only thing i know about saving data is that i’ve not the module i need in lua : BufferedReader. I made a bufferedreader to read file line per line in C++, and i can’t see any way to do that in lua.

And i can’t use SQLite : It would need a database per player it’s simply not ok for me.

I’m asking for the ents.Create problem not about saving. I will see for saving later. Because if the client can’t see entities on inventory and server can’t spawn them, so what the saving system has to do ? Nothing. The inventory must works properly before thinking of any data saving system.

Actualy entities won’t render because they are not valid. So can’t use GetModel and GetPrintName

Can we see the entities code or your scripts code to better understand your issue?

Reading a file line by line:
local file = file.Read( “file”, “DATA” )
local filex = string.Explode( "
", file )

Unless of course I’m mistaken.

The issue with that, is that it will read the entire file into memory all at once. Yuri is looking for something that can specify how many lines in the file, which lines to load, etc. The principle is to keep a few lines in memory which are above the viewing window, and a few lines below to make scrolling smooth without “pop-in” while minimizing the amount of memory needed from the entire file-size down to only what is viewable plus a few lines.

I’m pretty sure Yuri is right, I don’t know of anything in Lua, aside from using a module, to only read specific lines from a file.

That’s exactly what I means, i need something that will load in ram only the bits that compose a line.
In c++ I’m reading the file byte per byte and when I reach
byte, I assemblage a char array! and after I pack it as std::string, and I can after manage it or send it to lua. After I finished treating of the line, I switch to the next one, all of that running in loop until byte array got end of file char, then while loop is exiting and every pointers are killed to free ram…

About entity problem,
I’m calling ents.Create(“cstm_pistol_glock”)
And I table.insert it into inventory table. Then clients receives it updates it’s inventory, but when I open inventory, it crashes because the entity that is in the table is null.

Again nobody…
Why nobody has any solution about ents.Create problem ?

because ents.Create HAS no problem… the problem is that your entity doesnt exist

So how can i do to make my inventory working ?

I have no idea… I used this idea that is not working because i need the entity model, entity printname, and every other vars of the entity so i can add it to my inventory.

then you are making your inventory wrong.

ents.Create takes the classname of a SENT or entity included in garrysmod or source. not a weapon or SWEP or anything.

I succeeded ! I just find another way, i don’t know if it’s realy ok, it can be a little bit hacky…

So i used Minecraft Block Id Management. But instead of using a simple array of blocks, i made a complexe matrix that is storing item ids data (entClass, entName, entModel, entType) instead of entities. It is working correctly now…

And the first management command has been implemented : rp_invdrop that is simply dropping or giving an item by retrieving it’s slotID.