So here is what i got Note the derma is just a simple test , i need to improve it after i get it to work.
my goal is to make a scripted npc that spawns an item somewhere on the map after talking to the npc.
When you found the item you talk to the npc again and you get a reward.
some sort of job npc
Butfor now i need to get it to work :-/
I'm new to lua so please help .
cl_init.lua
[code]include('shared.lua')
ENT.RenderGroup = RENDERGROUP_BOTH
function ENT:Draw()
self:DrawModel()
end
function ENT:DrawTranslucent()
self:Draw()
end
function ENT:BuildBonePositions(NumBones,NumPhysBones)
end
function ENT:SetRagdollBones(bIn)
self.m_bRagdollSetup = bIn
end
[/code]
init.lua
[code]AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include('shared.lua')
schdPatrol = ai_schedule.New("AIFighter Chase")
schdPatrol:EngTask("TASK_WAIT_FOR_MOVEMENT",0)
function ENT:Initialize()
self:SetModel("models/srp/trader.mdl")
self:SetHullType(HULL_HUMAN)
self:SetHullSizeNormal()
self:SetSolid(SOLID_BBOX)
self:SetMoveType(MOVETYPE_STEP)
self:SetUseType(SIMPLE_USE)
self:CapabilitiesAdd(CAP_MOVE_GROUND | CAP_USE | CAP_AUTO_DOORS | CAP_OPEN_DOORS | CAP_TURN_HEAD | CAP_ANIMATEDFACE)
self:SetMaxYawSpeed(5000)
self:Give ( "Weapon_SPAS-12" )
self:SetHealth(999999999999999999)
end
*/
function ENT:OnTakeDamage(dmg)
self:SetHealth(self:Health() - dmg:GetDamage())
if self:Health() <= 0 then
self:SetSchedule( SCHED_FALL_TO_GROUND )
end
end
function ENT:Think()
/*
if self.NextRandomSound <= CurTime() and self.NextRandomSounda <= CurTime() and self.NextSound <= CurTime() and self.NextDamageSound <= CurTime() then
local sound = table.Random(self.RandomSound)
self:EmitSound(sound,100,100)
self.NextRandomSound = CurTime()+SoundDuration(sound)+0.1
self.NextRandomSounda = CurTime()+math.random(40,50)
end*/
end
{
PANEL={}
function PANEL:Init()
end
vgui.Register("HelpPanel",PANEL)
}
function ENT:AcceptInput(inp,ply,caller)
if inp == "Use" and ply:IsPlayer() then
local DermaPanel = vgui.Create( "DFrame" )
DermaPanel:SetPos( 50,50 )
DermaPanel:SetSize( 300, 400 )
DermaPanel:SetTitle( "Looking for a mission Stalker" )
DermaPanel:SetVisible( true )
DermaPanel:SetDraggable( true )
DermaPanel:ShowCloseButton( true )
DermaPanel:MakePopup()
button = vgui.Create( "DButton", window );
button:SetSize( 50, 30 );
button:SetPos( 55, 60 );
button:SetText( "Test Button" );
button.DoClick = function( button )
local DermaPanel = vgui.Create( "DFrame" )
DermaPanel:SetPos( 100,50 )
DermaPanel:SetSize( 200, 300 )
DermaPanel:SetTitle( "Let me see what you can do" )
DermaPanel:SetVisible( true )
DermaPanel:SetDraggable( true )
DermaPanel:ShowCloseButton( true )
DermaPanel:MakePopup()
end
end
function ENT:SelectSchedule()
self:StartSchedule(schdPatrol)
end
[/code]
shared.lua
[code]ENT.Base = "base_ai"
ENT.Type = "ai"
ENT.Contact = ""
ENT.Purpose = ""
ENT.Instructions = ""
ENT.Author = "Moordact"
ENT.Category = "SNPCs"
ENT.PrintName = "Job NPC"
ENT.Spawnable = true
ENT.AdminSpawnable = true
ENT.AutomaticFrameAdvance = true
function ENT:OnRemove()
end
function ENT:PhysicsUpdate( physobj )
end
function ENT:SetAutomaticFrameAdvance(bUsingAnim)
self.AutomaticFrameAdvance = bUsingAnim
end
[/code]
Really and truly, most people use the normal npc_ entities and hook commands on them.
but why wont it work? i get this error when i join my test server :
entities/hgn_npc/init.lua:23: unexpected symbol near '*'
Folder = entities/hgn_npc
Fixed the above error .
Can't seem to spawn the entitie :-/
________________________________________________________
When i use ent_create in console it says
Attempted to create unknown entity type hgn_npc!
[lua]
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include('shared.lua')
schdPatrol = ai_schedule.New("AIFighter Chase")
schdPatrol:EngTask("TASK_WAIT_FOR_MOVEMENT",0)
function ENT:Initialize()
self:SetModel("models/srp/trader.mdl")
self:SetHullType(HULL_HUMAN)
self:SetHullSizeNormal()
self:SetSolid(SOLID_BBOX)
self:SetMoveType(MOVETYPE_STEP)
self:SetUseType(SIMPLE_USE)
self:CapabilitiesAdd(CAP_MOVE_GROUND | CAP_USE | CAP_AUTO_DOORS | CAP_OPEN_DOORS | CAP_TURN_HEAD | CAP_ANIMATEDFACE)
self:SetMaxYawSpeed(5000)
self:Give ( "Weapon_SPAS-12" )
self:SetHealth(999999999999999999)
end
function ENT:OnTakeDamage(dmg)
self:SetHealth(self:Health() - dmg:GetDamage())
if self:Health() <= 0 then
self:SetSchedule( SCHED_FALL_TO_GROUND )
end
end
function ENT:Think()
/*
if self.NextRandomSound <= CurTime() and self.NextRandomSounda <= CurTime() and self.NextSound <= CurTime() and self.NextDamageSound <= CurTime() then
local sound = table.Random(self.RandomSound)
self:EmitSound(sound,100,100)
self.NextRandomSound = CurTime()+SoundDuration(sound)+0.1
self.NextRandomSounda = CurTime()+math.random(40,50)
end*/
end
{
PANEL={}
function PANEL:Init()
end
vgui.Register("HelpPanel",PANEL)
}
function ENT:AcceptInput(inp,ply,caller)
if inp == "Use" and ply:IsPlayer() then
local DermaPanel = vgui.Create( "DFrame" )
DermaPanel:SetPos( 50,50 )
DermaPanel:SetSize( 300, 400 )
DermaPanel:SetTitle( "Looking for a mission Stalker" )
DermaPanel:SetVisible( true )
DermaPanel:SetDraggable( true )
DermaPanel:ShowCloseButton( true )
DermaPanel:MakePopup()
button = vgui.Create( "DButton", window );
button:SetSize( 50, 30 );
button:SetPos( 55, 60 );
button:SetText( "Test Button" );
button.DoClick = function( button )
local DermaPanel = vgui.Create( "DFrame" )
DermaPanel:SetPos( 100,50 )
DermaPanel:SetSize( 200, 300 )
DermaPanel:SetTitle( "Let me see what you can do" )
DermaPanel:SetVisible( true )
DermaPanel:SetDraggable( true )
DermaPanel:ShowCloseButton( true )
DermaPanel:MakePopup()
end
end
function ENT:SelectSchedule()
self:StartSchedule(schdPatrol)
end
[/lua]
replace init.lua with that see what happens
[QUOTE=moordact;17793019]but why wont it work? i get this error when i join my test server :
entities/hgn_npc/init.lua:23: unexpected symbol near '*'
Folder = entities/hgn_npc
Fixed the above error .
Can't seem to spawn the entitie :-/
________________________________________________________
When i use ent_create in console it says
Attempted to create unknown entity type hgn_npc![/QUOTE]
[QUOTE=moordact;17793019]but why wont it work? i get this error when i join my test server :
entities/hgn_npc/init.lua:23: unexpected symbol near '*'
Folder = entities/hgn_npc
Fixed the above error .
Can't seem to spawn the entitie :-/[/QUOTE]
in the init.lua put
[lua]
function spawnNpc()
local npc = ents.Create("npc_citizen")
npc:SetPos(npc:GetPos(Vector(0,0,0)))
npc:Spawn()
end
hook.Add( "InitPostEntity", "Npc", spawnNpc)
function GM:PlayerUse( ply, entity )
if ( !ply:IsValid( ) ) then return; end
if ( entity:GetClass( ) == "npc_citizen" ) then
umsg.Start( "shopmenu", ply )
umsg.End( )
end
end
[/lua]
Cl_init.lua
[lua]
function VGUI_ShopMenu( )
Msg("Hey you clicked me!")
end
usermessage.Hook( "shopmenu", VGUI_ShopMenu )[/lua]
thanks , trying both ! will post wich helped me , thanks anyway
Well none of them changed anything :-/ <
The problem is , i got it in my spawnmenu , i dont get no errors but when i click to spawn it nothing happens
Sorry, you need to Log In to post a reply to this thread.