• ENT:Initialize not being called clientside, only called serverside
    6 replies, posted
I'm having a strange issue here with an anim based custom SENT, which was (I'm assuming) broken by a GUpdate. The entity is created by ents.Create, its position is set, it's spawned, then parented to another entity. During all of that, the Initialize hook is called in the serverside lua file, but not on the clientside lua file for some reason. If anyone can figure out why, I would appreciate the help. Here is a portion of my init.lua file: [lua] AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "shared.lua" ) include('shared.lua') local MODEL = Model( "models/props_c17/light_cagelight02_on.mdl" ) /*--------------------------------------------------------- Name: Initialize ---------------------------------------------------------*/ function ENT:Initialize() self:SetModel( MODEL ) self:SetMoveType( MOVETYPE_NONE ) self:SetSolid( SOLID_NONE ) self:DrawShadow( false ) MsgN("Siren Initialized serverside.") --This message shows up in the server's console end [/lua] The shared.lua file: [lua] ENT.Type = "anim" ENT.Base = "base_anim" ENT.PrintName = "" ENT.Author = "" ENT.Contact = "" ENT.Purpose = "" ENT.Instructions = "" ENT.Spawnable = false ENT.AdminSpawnable = false [/lua] And finally, the cl_init.lua file: [lua] include('shared.lua') function ENT:Initialize() MsgN("Initializing ambulance siren CS...") --Never appears in client or server console --Code setting custom variables in the entity MsgN("Siren entity initialized CS.") --Never appears in client or server console end [/lua] [del][i]Sorry about the lack of syntax highlighting, using [noparse][lua][/noparse] doesn't seem to do it for me :\[/i][/del] Nevermind, syntax highlighting doesn't work in preview mode. I hope it's not the three line comment in init.lua that's making it work :downs:
Initialize is a shared function, have you tried putting [lua]function ENT:Initialize()[/lua] in the shared.lua file, and putting all of what you want in only that function; then remove those functions from cl_init and init?
That'd do the same exact thing as shared is client and server.
@Chessnut I'm not quite sure, because while I was making some SWEPs I had cl_init, init, and shared in my base SWEP folder and I had problems calling Initialize when both cl_init and init had them, so I had to move the function into shared and for some reason it worked just fine there. So my answer above was from past experience.
[QUOTE=tgp1994;36289852]I'm having a strange issue here with an anim based custom SENT, which was (I'm assuming) broken by a GUpdate. The entity is created by ents.Create, its position is set, it's spawned, then parented to another entity. During all of that, the Initialize hook is called in the serverside lua file, but not on the clientside lua file for some reason. If anyone can figure out why, I would appreciate the help. Here is a portion of my init.lua file: [lua] AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "shared.lua" ) include('shared.lua') local MODEL = Model( "models/props_c17/light_cagelight02_on.mdl" ) /*--------------------------------------------------------- Name: Initialize ---------------------------------------------------------*/ function ENT:Initialize() self:SetModel( MODEL ) self:SetMoveType( MOVETYPE_NONE ) self:SetSolid( SOLID_NONE ) self:DrawShadow( false ) MsgN("Siren Initialized serverside.") --This message shows up in the server's console end [/lua] The shared.lua file: [lua] ENT.Type = "anim" ENT.Base = "base_anim" ENT.PrintName = "" ENT.Author = "" ENT.Contact = "" ENT.Purpose = "" ENT.Instructions = "" ENT.Spawnable = false ENT.AdminSpawnable = false [/lua] And finally, the cl_init.lua file: [lua] include('shared.lua') function ENT:Initialize() MsgN("Initializing ambulance siren CS...") --Never appears in client or server console --Code setting custom variables in the entity MsgN("Siren entity initialized CS.") --Never appears in client or server console end [/lua] [del][i]Sorry about the lack of syntax highlighting, using [noparse][lua][/noparse] doesn't seem to do it for me :\[/i][/del] Nevermind, syntax highlighting doesn't work in preview mode. I hope it's not the three line comment in init.lua that's making it work :downs:[/QUOTE] It depends on which file is loaded first. IIRC it's going to the init.lua. To fix just put your Initialize function in your shared file and separate your Server/Client sides with if blocks [lua] function ENT:Initialize() if SERVER then //Serverside Shit here else //Clientside shit here end end [/lua]
when are you spawning the entity? are you spawning it before the client joins the server, make sure to scroll up your console if you are. and just because Initialize() is a shared function doesn't mean you need it to be called both serverside and clientside, you can have it in a clientside script, "shared" means you can have it in all modes.
Thanks for all of the help, guys. The entity is spawning after I've been in the server for awhile. I know it doesn't need to be called on both sides, although (from what I can tell by reading the script), some functions within each initialize function will need to be called on one side in particular. I'm afraid to say that I'm unable to confirm if the solutions work, but I appreciate everyone's input nonetheless. May this help other people with a similar issue!
Sorry, you need to Log In to post a reply to this thread.