I'm trying to make a tool that spawns a custom entity with a bunch of settings, but I can't figure out how entities are supposed to be structured. So far I have this setup:
[code]
Addon
lua
entities
custom_ent
cl_init.lua
init.lua
shared[/code]
I'm basing this off other addons which add entities, but when trying to spawn one, I get the error "Attempted to create unknown entity type custom_ent!". Also, what am I supposed to add to the Lua files there? What are they used for?
They [B]can[/B] also be simply like this:
Addon/lua/entities/custom_ent.lua
Post what you have inside those files, you most likely have an error in there that is preventing the entity from loading.
init.lua
[code]
ENT.Spawnable = false
function ENT:Initialize()
end
[/code]
cl_init.lua and shared.lua are empty, do they require something before the entity can be used?
Uh yes, first of all, they must not be empty.
Then you must call AddCSLuaFile() on shared.lua and cl_init.lua from init.lua. Then you must include() shared.lua from init.lua and cl_init.lua
It's telling me it can't find "shared.lua" from init.lua when doing
[code]AddCSLuaFile("shared.lua")[/code]
Make sure it is not empty.
It has
[code]
print("HEYO!")
[/code]
in it, which is printed on both server and client.
I dunno, restart the map, if still happens, post full console log and new contents of your files.
cl_init.lua
[code]
include("shared.lua")
[/code]
init.lua
[code]
AddCSLuaFile("shared.lua")
AddCSLuaFile("cl_init.lua")
include("shared.lua")
ENT.Spawnable = false
function ENT:Initialize()
end
[/code]
shared.lua
[code]
print("HEYO!")
[/code]
Full console after doing 'restart' from the console
[code]
SoundEmitter: removing map sound overrides [4 to remove, 0 to restore]
Adding Filesystem Addon 'c:\program files (x86)\steam\steamapps\common\garrysmod\garrysmod\addons\rp'
Dropped Spans from server (Server shutting down)
PREP OK
Error, bad server command lua_error_url ''
Lua JIT is DISABLED!
HEYO!
CModelLoader::Map_IsValid: No such map 'maps/l4d_farm01_hilltop.bsp'
Invalid map 'l4d_farm01_hilltop' included in map cycle file. Ignored.
CModelLoader::Map_IsValid: No such map 'maps/l4d_airport01_greenhouse.bsp'
Invalid map 'l4d_airport01_greenhouse' included in map cycle file. Ignored.
CModelLoader::Map_IsValid: No such map 'maps/l4d_smalltown01_caves.bsp'
Invalid map 'l4d_smalltown01_caves' included in map cycle file. Ignored.
CModelLoader::Map_IsValid: No such map 'maps/l4d_hospital01_apartment.bsp'
Invalid map 'l4d_hospital01_apartment' included in map cycle file. Ignored.
Nav File is wrong or something (1)
Adding Filesystem Addon 'c:\program files (x86)\steam\steamapps\common\garrysmod\garrysmod\addons\rp'
Garry's Mod
http://loading.garrysmod.com/
sandbox
gm_flatgrass
1
76561198024552137
Requesting 1 lua files from the server
clientside lua startup!
Lua JIT is DISABLED!
HEYO!
Compact freed 983040 bytes
Redownloading all lightmaps
[/code]
After trying to spawn the entity
[code]
Attempted to create unknown entity type custom_ent!
[ERROR] addons/rp/lua/weapons/gmod_tool/stools/custom_tool.lua:55: Tried to use a NULL entity!
1. SetModel - [C]:-1
2. LeftClick - addons/rp/lua/weapons/gmod_tool/stools/custom_tool.lua:55
3. unknown - gamemodes/sandbox/entities/weapons/gmod_tool/shared.lua:251
[/code]
Try putting this into shared.lua:[code]
ENT.Base = "base_entity"
ENT.Type = "anim"[/code]
The entities spawn now, but they are invisible. Only the shadow is visible.
Because you didn't set a model or anything.
But I am setting the model to "models/Items/item_item_crate.mdl" before spawning the entity.
[QUOTE=Funley;44362909]But I am setting the model to "models/Items/item_item_crate.mdl" before spawning the entity.[/QUOTE]
I am not telepathic you know, I can't see or know what you are or are not doing.
Try this in cl_init.lua
[code]
function ENT:Draw()
self:DrawModel()
end[/code]
And by the way, you should just look how other addons did it, not asking questions here.
Thanks, it works now :)
Sorry, you need to Log In to post a reply to this thread.