I have an NPC that I'm making for my server, here is the code so far
init_npc_info.lua
[CODE]local model = "models/player/Group01/Male_0" .. math.random( 1, 9 ) .. ".mdl"
local classname = "npc_info"
local ShouldSetOwner = true
-------------------------------
AddCSLuaFile( "cl_npc_info.lua" )
AddCSLuaFile( "sh_npc_info.lua" )
include( 'sh_npc_info.lua' )
-------------------------------
--------------------
-- Spawn Function --
--------------------
function ENT:SpawnFunction( ply, tr )
if ( !tr.Hit ) then return end
local SpawnPos = tr.HitPos + tr.HitNormal * 25;
local ent = ents.Create( classname )
ent:SetPos( SpawnPos )
ent:Spawn()
ent:Activate()
if ShouldSetOwner then
ent.Owner = ply
end
return ent
end
----------------
-- Initialize --
----------------
function ENT:Initialize()
self:SetModel( model )
self:SetHullType( HULL_HUMAN )
self:SetHullSizeNormal()
self:SetNPCState( NPC_STATE_SCRIPT )
self:SetSolid( SOLID_BBOX )
self:CapabilitiesAdd( CAP_ANIMATEDFACE )
self:SetUseType( SIMPLE_USE )
self:DropToFloor()
end
------------
-- On use --
------------
function ENT:AcceptInput( name, activator, caller )
if name == "Use" and caller:IsPlayer() and IsValid( caller ) then
activator:SendLua( [[ chat.AddText( Color( 30, 139, 195 ), "[Server] ", Color( 228, 241, 254 ), "You activated the NPC" ]] )
end
end[/CODE]
cl_npc_info.lua
[CODE]include('sh_npc_info.lua')
function ENT:Initialize()
self.AutomaticFrameAdvance = true;
end
function ENT:Draw()
self.Entity:DrawModel()
end[/CODE]
sh_npc_info.lua
[CODE]ENT.Type = "anim"
ENT.Base = "base_ai"
ENT.PrintName = "Info NPC"
ENT.Author = "Austin"
ENT.Purpose = "NPC for displaying information to the player about the server"
ENT.Spawnable = true
ENT.SetAutomaticFrameAdvance = true
ENT.AdminSpawnable = true
ENT.Category = "test NPC's"[/CODE]
Doesn't even show up in the spawn menu under entities
Here is the error when i try to spawn it via chat command
[CODE][ERROR] gamemodes/x/gamemode/structure/chatcommands/sv_chatcommands.lua:120: Tried to use a NULL entity!
1. SetPos - [C]:-1
2. v - gamemodes/x/gamemode/structure/chatcommands/sv_chatcommands.lua:120
3. unknown - gamemodes/x/gamemode/structure/chatcommands/sv_chatcommands.lua:13[/CODE]
If you need any more info please do ask, thank you.\
EDIT: Here is the code that spawns the entity (im using an API that I found, and no it's not creating the error.
[CODE]RegisterChatCommand("/npc", function( ply, args )
local ent = ents.Create( "npc_info" )
ent:SetPos( ply:GetPos() )
ent:Spawn()
ent:Activate()
end)[/CODE]
uhh yes it is
Could you post the RegisterChatCommand function please?
Or, try replacing the bit of code where you use that function with this:
[CODE]
hook.Add( 'PlayerSay', 'SOME_UNIQUE_NAME', function( ply, txt, team )
if txt == '/npc' then
local ent = ents.Create( "npc_info" )
ent:SetPos( ply:GetPos() )
ent:Spawn()
ent:Activate()
end
end )
[/CODE]
I know you said that function wasn't creating the problem, but I think it might be...
If the problem is outside of the entity, why is it not even showing up in the spawn menu? When I get home I'll show the register chat command function, but I'm almost certain thats not the problem. Also if I change the class name of the box in the chat command it works fine.
[QUOTE=Austin1346;49711835]If the problem is outside of the entity, why is it not even showing up in the spawn menu? When I get home I'll show the register chat command function, but I'm almost certain thats not the problem. Also if I change the class name of the box in the chat command it works fine.[/QUOTE]
Where did you put those files?
[QUOTE=Sir TE5T;49710540]uhh yes it is[/QUOTE]
What makes you think it's the API that is creating the error? Is it because the error tells you the path of where it's located?
[QUOTE=GGG KILLER;49712019]Where did you put those files?[/QUOTE]
In mygamemode/entities/entities/npc_info
[QUOTE=Austin1346;49712037]What makes you think it's the API that is creating the error? Is it because the error tells you the path of where it's located?[/QUOTE]
What makes us think that is because the "NULL" entity is when ents.Create fails and because of the path mentioned.
If you're implying that the API is the problem, why does the entity not show up in the spawn menu under entities?
Rename them to init.lua and cl_init.lua
[QUOTE=Zeh Matt;49713812]Rename them to init.lua and cl_init.lua[/QUOTE]
Thanks a ton, this fixed it. I forgot that if i wanted to make a custom name for them that i would have to AddCSLuaFile and include them from another file that's already loaded.
Aside that, I've ran into another problem. I'm still using the same code in the op, and I get this error when trying to spawn it in the Q menu.
[QUOTE][ERROR] gamemodes/x/entities/entities/npc_info/init.lua:38: attempt to call method 'SetHullType' (a nil value)
1. unknown - gamemodes/x/entities/entities/npc_info/init.lua:38
2. Spawn - [C]:-1
3. SpawnFunction - gamemodes/x/entities/entities/npc_info/init.lua:22
4. Spawn_SENT - gamemodes/sandbox/gamemode/commands.lua:610
5. unknown - gamemodes/sandbox/gamemode/commands.lua:675
6. unknown - lua/includes/modules/concommand.lua:54[/QUOTE]
In the case that anyone is lazy, here is the ENT:Intialize func
[LUA]function ENT:Initialize()
self:SetModel( model )
self:SetHullType( HULL_HUMAN )
self:SetHullSizeNormal()
self:SetNPCState( NPC_STATE_SCRIPT )
self:SetSolid( SOLID_BBOX )
self:CapabilitiesAdd( CAP_ANIMATEDFACE )
self:SetUseType( SIMPLE_USE )
self:DropToFloor()
end[/LUA]
Sorry, you need to Log In to post a reply to this thread.