-snip- I’m going to make a new more specific thread
For the first thing, you make a custom entity, and use the ENT:Use() function to call a menu.
For the second thing, here’s an example that spawns all the npcs from a table.
[lua]
local to_spawn =
{“npc_headcrab”,Vector(10,10,10)},
{“npc_antlion”,Vector(50,50,50},
function SpawnNPC()
for _,v in ipairs(to_spawn) do
local npc = ents.Create(v[1])
npc:SetPos(v[2])
npc:Spawn()
npc:Activate()
end
end
hook.Add(“InitPostEntity”,“SpawnNPCs”,SpawnNPC)[/lua]
Use InitPostEntity, as that is called once after the map/gamemode is loaded.
The Ent:Use isn’t the problem, Making an entity that has the model of an NPC and is animated and stands there is the problem. And I don’t get the second thing, wouldn’t that just spawn NPC’s and not entity’s? But thank you.
EDIT: I forgot npc_blah is an entity… Wow. I’m really not thinking today.
Thank you so much!
In lua/entites/snpc_name:
shared.lua;
[LUA]
ENT.Base = “base_ai”
ENT.Type = “ai”
ENT.PrintName = “Test SNPC”
ENT.Author = “Spencer Henslol”
ENT.Contact = “rawr@poop.com” //fill in these if you want it to be in the spawn menu
ENT.Purpose = “rawr”
ENT.Instructions = “rawr”
ENT.AutomaticFrameAdvance = true
VoiceListM = {
Sound(“vo/npc/male01/answer30.wav”),
Sound(“vo/npc/male01/hi01.wav”),
Sound(“vo/npc/male01/hi02.wav”),
Sound(“vo/npc/male01/question06.wav”),
Sound(“vo/npc/male01/question29.wav”),
}
function ENT:Use( ply, caller )
self:EmitSound(table.Random(VoiceListM))
ply:SendLua(“Menu()”)
end
function ENT:AcceptInput(input, entActivator, entCaller, data)
if string.lower(input) == “use” then
self:Use(entActivator,entCaller)
return
end
end
[/LUA]
in init.lua;
[LUA]
AddCSLuaFile( “cl_init.lua” )
AddCSLuaFile( “shared.lua” )
include(‘shared.lua’)
function ENT:Initialize()
self:SetUseType(SIMPLE_USE)
self:SetModel( "models/Humans/Group02/Male_07.mdl" )
self:SetHullType( HULL_HUMAN );
self:SetHullSizeNormal();
self:SetSolid( SOLID_BBOX )
self:SetMoveType( MOVETYPE_STEP )
self:CapabilitiesAdd( CAP_MOVE_GROUND | CAP_OPEN_DOORS | CAP_ANIMATEDFACE | CAP_TURN_HEAD | CAP_USE_SHOT_REGULATOR | CAP_AIM_GUN )
self:SetMaxYawSpeed( 5000 )
//don't touch stuff above here
self:SetHealth(100)
self:SetSequence(204)
end
function ENT:OnTakeDamage(dmg)
return false
end
[/LUA]
in cl_init.lua;
[LUA]
include(‘shared.lua’)
ENT.RenderGroup = RENDERGROUP_BOTH
function ENT:Draw()
self.Entity:DrawModel()
end
function ENT:DrawTranslucent()
self:Draw()
end
function ENT:SetRagdollBones( bIn )
self.m_bRagdollSetup = bIn
end
function Menu()
local poop = vgui.Create(“DFrame”)
poop.Paint = function()
draw.RoundedBox(0,0,0,poop:GetWide(),poop:GetTall(),Color(0,0,0,210))
surface.SetDrawColor(255,255,50,200)
surface.DrawOutlinedRect(0,0,poop:GetWide(),poop:GetTall())
end
poop:SetDraggable(false)
poop:SetTitle(“Title fo’ you bitches”)
poop:SetSize(ScrW() - 20,ScrH() - 20)
poop:SetPos(10,10)
poop:MakePopup()
end
[/LUA]
THEN do the script Entoros gave you, but in ents.Create, just replace the “v[1]” thingy with the name of the folder that you put those scripts in.
By the way, in shared.lua, theres a line saying “self:SetSequence(204)” You can remove that. I think that makes him sitting. I forget. I just took a random SNPC I made a while ago and pasted it.
Thank you so much, but how would I go about finding the vector coordinates of some place ingame?
Goto that place and type getpos into console.
[LUA]
function GetPosition (P, key)
if key == IN_ATTACK2 then
print(P:GetPos())
end
end
hook.Add( “KeyPress”, “Supdooood”, GetPosition )
[/LUA]
Put that in an autorun file and lua_openscript_cl autorun/client/filename.lua it. Then right click to get your current position.
Edit: Doh, didn’t know there was a getpos command >.<
Thank you, also one more thing, I can not spawn the SNPC. Nothing happens. I added
[lua]
ENT.Spawnable = false;
ENT.AdminSpawnable = true;
[/lua]
To shared.lua to test it but nothing happens when I click it.
Yeah. You have to spawn it via lua. There’s no spawn function in the scripts I gave you.
Okay, The code you gave me for creating the entitys isn’t working. The autorun file isn’t even being downloaded. If I put the code in my cl_init.lua it fucks up my gamemode. Any help?
Well are you sure you have them right?
In autorun/client/somefoldername there should be:
-shared.lua
-cl_init.lua
-init.lua
And the spawn code should be in an autorun file because it’s a hook for that kind of file. You can use this in your gamemode init.lua though:
[LUA]
function GM:InitPostEntity()
NPCz=ents.Create(“The folder name where you put the files for the SNPC”)
NPCz:SetPos(Vector(100,500,5))
NPCz:Spawn()
end
[/LUA]
Its serverside… Isnt it?
Not for the NPC. And oops. I said that wrong.
Should be autorun/entities/folder name. My mistake :3
I put that code in my init.lua
heres the code:
[lua]
function GM:InitPostEntity()
NPCz=ents.Create(“snpc_hatlady”)
NPCz:SetPos(Vector(-2877.906250,-2080.531250,-131.968750))
NPCz:Spawn()
end
[/lua]
I have the Hat Lady SNPC in (By hat lady SNPC I mean the SNPC you gave me earlier)
gamemodes/ColzRP/entities/entities/snpc_hatlady
Still not working
You have double entities folders and the init.lua you’re putting it in is the gamemode’s init.lua right?
Your suppose to have double folders. And yes the method is in init.lua
Yeah. Just to autorun/entities/folder name
Still not working, nothing was downloaded.
You have to add the lua file with AddCSLuaFile. What I gave you will work if you do it right. I gotta work on some stuff for now. Maybe someone else can help you. Sorry.
Init.lua
[lua]
AddCSLuaFile( “cl_init.lua” )
AddCSLuaFile( “shared.lua” )
include(‘shared.lua’)
function ENT:Initialize()
self:SetUseType(SIMPLE_USE)
self:SetModel( "models/Humans/Group01/Female_02.mdl" )
self:SetHullType( HULL_HUMAN );
self:SetHullSizeNormal();
self:SetSolid( SOLID_BBOX )
self:SetMoveType( MOVETYPE_STEP )
self:CapabilitiesAdd( CAP_MOVE_GROUND | CAP_ANIMATEDFACE | CAP_TURN_HEAD)
self:SetMaxYawSpeed( 5000 )
//don't touch stuff above here
self:SetHealth(10000000000)
self:SetSequence(204)
end
function ENT:OnTakeDamage(dmg)
return false
end
[/lua]
Shared.lua
[lua]
ENT.Base = “base_ai”
ENT.Type = “ai”
ENT.PrintName = “Hat Lady”
ENT.Author = “Facepunch”
ENT.Contact = “helix@colzdragon.com” //fill in these if you want it to be in the spawn menu
ENT.Purpose = “Colzdragon”
ENT.Instructions = “”
ENT.AutomaticFrameAdvance = true
VoiceListM = {
Sound(“vo/npc/female01/question19.wav”),
Sound(“vo/npc/female01/answer33.wav”),
Sound(“vo/npc/female01/getgoingsoon.wav”),
Sound(“vo/npc/female01/question16.wav”),
Sound(“vo/npc/female01/question15.wav”),
}
function ENT:Use( ply, caller )
self:EmitSound(table.Random(VoiceListM))
ply:SendLua(“Menu()”)
end
function ENT:AcceptInput(input, entActivator, entCaller, data)
if string.lower(input) == “use” then
self:Use(entActivator,entCaller)
return
end
end
[/lua]
cl_init.lua
[lua]
include(‘shared.lua’)
ENT.RenderGroup = RENDERGROUP_BOTH
function ENT:Draw()
self.Entity:DrawModel()
end
function ENT:DrawTranslucent()
self:Draw()
end
function ENT:SetRagdollBones( bIn )
self.m_bRagdollSetup = bIn
end
function Menu()
local hatMenu = vgui.Create(“DFrame”)
hatMenu.Paint = function()
draw.RoundedBox(0,0,0,hatMenu:GetWide(),hatMenu:GetTall(),Color(0,0,0,210))
surface.SetDrawColor(255,255,50,200)
surface.DrawOutlinedRect(0,0,hatMenu:GetWide(),hatMenu:GetTall())
end
poop:SetDraggable(false)
poop:SetTitle(“Hat Store”)
poop:SetSize(ScrW() - 20,ScrH() - 20)
poop:SetPos(10,10)
poop:MakePopup()
end
[/lua]
In my gamemodes init.lua:
[lua]
function GM:InitPostEntity()
NPCz=ents.Create(“snpc_hatlady”)
NPCz:SetPos(Vector(-2877.906250,-2080.531250,-131.968750))
NPCz:Spawn()
end
[/lua]
Directorys:
lua/autorun/entities/hatlady/cl_init.lua
lua/autorun/entities/hatlady/shared.lua
lua/autorun/entities/hatlady/init.lua
What could I possibly be doing wrong?