• Where do I put custom entity on my server?
    28 replies, posted
Hey, I've created a custom entity and I'm not sure where I put it in my [B]server[/B] files, I've tried garrysmod/lua/entities and the folder name is the entity's name but it does not seem to be loading.
Can you post a picture of the layout of your files and folders. Could you also clarify what you mean by "not loading". Is it not appearing in the spawn menu, or is it not spawning with the map, etc. If you could also post a console log then that might help. The rule of thumb here is the more information you give, the faster it gets solved. You've not given any information other than "I put some files I'm not telling you about here" and "it doesn't work".
It does not seem to be appearing in the entity list, here are the images and console log: [url]https://pastebin.com/x7R95gJN[/url] [url]https://i.imgur.com/6PNtCfo.png[/url] [url]https://i.imgur.com/rDzq62h.png[/url]
Don't put them into the default entities folder. You should go into your 'addons' folder and create a structure like so. [CODE]addons/addonname/lua/entities/entityclassname/ lua files go in here.lua[/CODE] EDIT: A little clarification, that folder is where the default entities that Garry made is at. In that folder, the entity's class name is determined by the lua file's name and all of it is put into one file.
Okay, it still does not seem to show up in the entity menu. Console output: [url]https://pastebin.com/STHk2ppF[/url]
You are still not showing us the code, most likely your entity doesn't have Spawnable field
The entity is spawned by a weapon, and when the script tries to spawn the entity, it doesn't. It was working fine in single player and it does not print any errors
If you are not going to show any code, please avoid to keep asking for help here
Here is the code for the entity: As mentioned before, it is spawned by a weapon. The weapon works fine but does not spawn the entity. Shared.lua: [url]https://i.imgur.com/3Q1piqg.png[/url] Init.lua: [url]https://i.imgur.com/hmVwy7q.png[/url] Cl_Init.lua: [url]https://i.imgur.com/kOCxXCG.png[/url]
[QUOTE=RandomGuy22;52722853]Here is the code for the entity: As mentioned before, it is spawned by a weapon. The weapon works fine but does not spawn the entity. Shared.lua: [url]https://i.imgur.com/3Q1piqg.png[/url] Init.lua: [url]https://i.imgur.com/hmVwy7q.png[/url] Cl_Init.lua: [url]https://i.imgur.com/kOCxXCG.png[/url][/QUOTE] Can we see your weapon code?
Weapon code: [url]https://pastebin.com/ATKpfgZw[/url]
[QUOTE=MelonShooter;52722880]Can we see your weapon code?[/QUOTE] DrawShadow is a function and needs a ':' and not a '.' You don't need to do self.Entity because you can use self which is a reference to the entity. self:DrawModel()
Thanks. The entity still does not spawn however.
Weapons works without it data as primary and base info? I don't think so, can you copy weapon_flachette gun table info into your weapons with your settings and take a look if it works?
I'm sorta new to lua, how would I do that?
Weapons do not work without primary info or at least when you shoot, it shouldn't. It needs info on what ammo does left click shoot, magazine size, default amount of ammo in gun, and whether the gun is automatic or not. Put this up top in your weapon below AddCSLuaFile() and modify as needed. [code]SWEP.Primary.ClipSize = -1 SWEP.Primary.DefaultClip = -1 SWEP.Primary.Automatic = false SWEP.Primary.Ammo = "none"[/code] All of that can be found on the [URL="http://wiki.garrysmod.com/page/Main_Page"]wiki[/URL]. Specifically [URL="http://wiki.garrysmod.com/page/Structures/SWEP"]here[/URL].
Yeah i've done that. [url]https://pastebin.com/ATKpfgZw[/url]
what happens ingame/console if you type ulx ent ent_test
It spawns the entity without any errors: [url]https://i.imgur.com/gvDvF8J.jpg[/url] but does not spawn by the weapon.
Try remove if (!IsValid(ent)) then return end and if (!IsValid( phys ) ) then ent:Remove() return end then see what happens
- snip -
Still does not work.
Whats your console say if you replace the function with this one [url]https://pastebin.com/jUPUfkeh[/url]
It spawns the entity and it prints this: [url]https://i.imgur.com/FV9g3H4.png[/url]
You said it spawns the entity. Is there another problem? If so, show us your serverside console unless it's a singleplayer game.
The entity just floats in the air, no-collided: [url]https://i.imgur.com/9vdjs0X.jpg[/url] I've tried adding self:SetCollisionGroup(COLLISION_GROUP_NONE) and tried self:SetCollisionGroup(COLLISION_GROUP_INTERACTIVE_DEBRIS) in the Initialize() function in the init.lua entity file but this doesnt seem to fix it. Serverside Console: [url]https://pastebin.com/0DLt7rcU[/url]
Maybe it needs to be activated ent:Activate() and confirming if you spawn the entity itself it spawns exactly as you want moves around ect?
Alright let's try to make some sense of whats going on here. Problem #1: Entity failing to spawn ( sv_init [url]https://i.imgur.com/hmVwy7q.png[/url] ) All the functions from physicsinit to drawshadow need to use ":", not ".". Problem #2: Weapon not spawning the entity ( wep.lua [url]https://pastebin.com/ATKpfgZw[/url] ) Swap :SetNextPrimaryFire and :CanPrimaryAttack, so that it checks :CanPrimary first. This is the equivalent of doing something like this; [lua] local nextFire = CurTime()+30 if( nextFire > CurTime() ) then return end [/lua] You don't need to be any good at lua to see what the problem here is.
Thanks.
Sorry, you need to Log In to post a reply to this thread.