• Can't spawn entities on my GMod server?
    6 replies, posted
Hello, I made (For my RP gamemode) a function to spawn NPC's, but it only works when I save a file. The clientside initializes it like it should, but the server doesn't. Any clue? The files contain a function (GM:LoadNPC(Table)), and if you include them they execute that function. The function sets up a NPC and spawns it. The problem is that the server does not call these lines. I posted them everywhere (GM:Initialize, GM:InitPostEntity, GM:PostLoaded) and even outside of the functions. Also in shared.lua it does not work. This is the loop I am using: [code]for _,v in pairs( file.Find("rp_base/gamemode/npc/*.lua", "LUA") ) do AddCSLuaFile( 'npc/' .. v ) include( 'npc/' .. v ) print("Server: " .. v ) end[/code] Thanks in advance, Techdaan.
That line must be on top of shared.lua or something. Make sure shared.lua is included from init.lua.
No results at all, unfortunately; still the NPC's are not loaded until I save a file. I had to include the "sh_npc.lua" at the "shared.lua" though. For some odd reason it would say that GM:LoadNPC( ) was not found. [code]include( 'sh_npc.lua' ) for _,v in pairs( file.Find("rp_base/gamemode/npc/*.lua", "LUA") ) do AddCSLuaFile( 'npc/' .. v ) include( 'npc/' .. v ) print("Server: " .. v ) end [/code]
Could someone please help me? This is the biggest problem I yet encountered. :(
Here: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/includes/file_only_works_on_autorefresh_possible_reasons.lua.html[/url] If it only works on auto-refresh then you're trying to access data that hasn't been initialized yet.
Good point, I read some other files you made and I think I found out why things don't work, now just to find out why npc_vendor does not load on a dedicated server... [editline]6th January 2015[/editline] Could someone explain me why I can use AddCSLuaFile and include outside of GM:InitPostEntity, but not inside( It will return that the file is not found, but it DOES really exist ). This is the only method I can use to load the NPCs :(
Alright. Problem solved, just added another function that does the loading, all parameters of the NPC are stored in a table, then at the GM:InitPostEntity it loops through all those tables and spawns them one by one.
Sorry, you need to Log In to post a reply to this thread.