Problem: Including Cl_init in shared or the other way around
5 replies, posted
So, basically what i'm trying to do is to make a Derma button, that if pushed an entity spawn somewhere on the map.
the problem is that derma is only client side, and ents library shared, and when i push the button i get "Tried TO USE A NULL ENTITY.", as if i'm trying to run it client side.
here's the code
#### client_init.lua:
include("shared.lua")
function spawnFrame()
local MyFrame = vgui.Create("DFrame")
MyFrame:SetPos(ScrW()/2, ScrH()/2)
MyFrame:SetSize(500, 400)
MyFrame:SetTitle("Testing derma")
MyFrame:SetVisible(true)
MyFrame:SetDraggable(true)
MyFrame:ShowCloseButton(true)
MyFrame:MakePopup()
MyButton = vgui.Create("DButton")
MyButton:SetParent(MyFrame)
MyButton:SetPos(0,0)
MyButton:SetSize(250,200)
MyButton:SetText("spawn")
MyButton.DoClick = function()
spawnEntity()
end
end
concommand.Add("spawnFrame", spawnFrame)
#### shared.lua
--include("cl_init.lua")
function spawnEntity(Model_File)
local MyEnt = ents.Create("npc_alyx")
MyEnt:SetPos(Vector(0,0,100))
MyEnt:Spawn()
MyEnt:Activate()
end
First off, remove the line "include("cl_init.lua")" (you commented it, but remove it as you will never have to include cl_init.lua).
Secondly: taken from [B][URL="http://wiki.garrysmod.com/?title=Ents.Create"]Ents.Create [IMG]http://wiki.garrysmod.com/favicon.ico[/IMG][/URL][/B]
[quote]
Can be used client-side - only some entities can be created, and those can only be seen by the client - If an entity can't be created client-side you'll get the message "Can't find factory for entity: <classname>" in the console.
[/quote]
I am 99% sure that is the problem. Check the console to be sure.
Create the entity server-sided instead.
I'm sorry if i'm being a pain, but how do i create the entity server side?
[QUOTE=libintia;24640828]I'm sorry if i'm being a pain, but how do i create the entity server side?[/QUOTE]
Make a concommand server-side and make the button call it when clicked.
[QUOTE=ralle105;24641475]Make a concommand server-side and make the button call it when clicked.[/QUOTE]
Ok, thanks.
[editline]05:54AM[/editline]
[QUOTE=iRzilla;24642118]#### client_init.lua:
Do you not mean cl_init.lua?[/QUOTE]
yes, i misspelled it!
Sorry, you need to Log In to post a reply to this thread.