aboutsummaryrefslogtreecommitdiff
path: root/entities
diff options
context:
space:
mode:
authorAlexander Pickering <alexandermpickering@gmail.com>2016-08-09 17:53:52 -0400
committerAlexander Pickering <alexandermpickering@gmail.com>2016-08-09 17:53:52 -0400
commitd4f197a35c207c9891d3f4dc5e9708af48c935de (patch)
treeee8fd3960c3a3fb4ecaf0f62b50d251f007ebaf3 /entities
parent2fe3c4551344870e3784733fce2d95027b5c8382 (diff)
downloadartery-d4f197a35c207c9891d3f4dc5e9708af48c935de.tar.gz
artery-d4f197a35c207c9891d3f4dc5e9708af48c935de.tar.bz2
artery-d4f197a35c207c9891d3f4dc5e9708af48c935de.zip
Added some weapons
Diffstat (limited to 'entities')
-rw-r--r--entities/entities/art_chest/cl_init.lua3
-rw-r--r--entities/entities/art_chipmill/cl_init.lua121
-rw-r--r--entities/entities/art_chipmill/init.lua81
-rw-r--r--entities/entities/art_chipmill/shared.lua30
-rw-r--r--entities/entities/art_serverchanger/cl_init.lua66
-rw-r--r--entities/entities/art_serverchanger/init.lua39
-rw-r--r--entities/entities/art_serverchanger/shared.lua21
-rw-r--r--entities/entities/info_townienode/cl_init.lua69
-rw-r--r--entities/entities/info_townienode/init.lua16
-rw-r--r--entities/entities/info_townienode/shared.lua23
-rw-r--r--entities/entities/npc_townie/cl_init.lua68
-rw-r--r--entities/entities/npc_townie/init.lua50
-rw-r--r--entities/entities/npc_townie/shared.lua156
-rw-r--r--entities/weapons/hands.lua29
14 files changed, 716 insertions, 56 deletions
diff --git a/entities/entities/art_chest/cl_init.lua b/entities/entities/art_chest/cl_init.lua
index 072d421..2907968 100644
--- a/entities/entities/art_chest/cl_init.lua
+++ b/entities/entities/art_chest/cl_init.lua
@@ -1,5 +1,6 @@
include('shared.lua')
-local invfuncs = include("../../../gamemode/shared/inventory_common.lua")
+--local invfuncs = include("../../../gamemode/shared/inventory_common.lua")
+local invfuncs = ART.invfuncs
ENT.RenderGroup = RENDERGROUP_BOTH
diff --git a/entities/entities/art_chipmill/cl_init.lua b/entities/entities/art_chipmill/cl_init.lua
new file mode 100644
index 0000000..6eb1d1f
--- /dev/null
+++ b/entities/entities/art_chipmill/cl_init.lua
@@ -0,0 +1,121 @@
+
+ART.chips = {}
+ART.RegisterChipType = function(tbl)
+ assert(ART.chips[tbl.Name] == nil,"Trying to register a chip twice:"..tbl.Name)
+ ART.chips[tbl.Name] = tbl
+end
+include('shared.lua')
+
+ENT.RenderGroup = RENDERGROUP_BOTH
+
+function ENT:Initialize()
+end
+
+function ENT:OnRemove()
+end
+
+function ENT:Think()
+end
+
+local function drawchipsavaliable(panel, chips)
+ for k,v in pairs(chips) do
+ local chiptbl = ART.chips[k]
+ local chippanel = vgui.Create("DPanel",panel)
+ chippanel:SetSize(64,80)
+ chippanel.chip = chiptbl
+ chippanel:Droppable("chiptype")
+ local chipitem = vgui.Create( "DImage",chippanel )
+ chipitem:SetMaterial( chiptbl:GetImage() )
+ chipitem:SetSize(64,64)
+ local chipname = vgui.Create("DLabel",chippanel)
+ chipname:SetPos( 0, 64 )
+ chipname:SetText( k )
+ chipname:SetDark(true)
+ chipname:SetContentAlignment(5)
+ --chipitem:Dock(TOP)
+ panel:AddItem(chippanel)
+ end
+end
+local workspacesize = {5,5}
+local workspacegridemptys = {}
+local workspacechips = {}
+for k=1,workspacesize[2] do
+ workspacechips[k] = {}
+end
+local function drawworkgrid(panel,blocks)
+ workspacegridemptys = {}
+ local grid = vgui.Create( "DGrid", panel )
+ grid:SetPos( 0, 0 )
+ grid:SetCols( workspacesize[1] )
+ grid:SetColWide( 64 )
+ grid:SetRowHeight(64)
+
+ for i = 1, workspacesize[1] * workspacesize[2] do
+ local griditem = vgui.Create( "DPanel" )
+ griditem:SetText( i )
+ griditem:SetSize( 64, 64 )
+ grid:AddItem( griditem )
+ griditem:Receiver( "chiptype", function(receiver,
+ tableOfDroppedPanels,
+ isDropped,
+ menuIndex,
+ mouseX,
+ mouseY )
+ local chiptbl = tableOfDroppedPanels[1].chip
+ print("Chiptable was:")
+ PrintTable(chiptbl)
+ print("Receiver was:",receiver)
+ if isDropped then
+ --workspacechips[i]
+ print("The icon was dropped on me!")
+ elseif griditem.image == nil then
+ for k,v in pairs(workspacegridemptys) do
+ if v.ghostimage == nil then continue end
+ v.ghostimage:Remove()
+ v.ghostimage = nil
+ end
+ griditem.ghostimage = vgui.Create( "DImage", griditem )
+ griditem.ghostimage:SetMaterial( chiptbl:GetImage() )
+ griditem.ghostimage:SetSize(64,64)
+ end
+ print("Something was dragged and dropped!")
+ end, {} )
+ table.insert(workspacegridemptys,griditem)
+ end
+end
+
+net.Receive("openchipmill",function()
+ local width,height = ScrW(),ScrH()
+ local chipframe = vgui.Create( "DFrame" )
+ chipframe:SetPos( width / 10, height / 10 )
+ chipframe:SetSize( width / 1.25, height / 1.25 )
+ chipframe:SetTitle( "Chip mill" )
+ chipframe:SetDraggable( true )
+ chipframe:MakePopup()
+
+ local chipsavaliable = {
+ ["Clock"] = 1,
+ }
+ chipsavaliablepanel = vgui.Create( "DPanel", chipframe )
+ chipsavaliablepanel:Dock(RIGHT)
+ local chipscroll = vgui.Create( "DScrollPanel", chipsavaliablepanel )
+ chipscroll:Dock(FILL)
+ drawchipsavaliable(chipscroll,chipsavaliable)
+
+ chipworkspace = vgui.Create( "DPanel",chipframe )
+ chipworkspace:Dock(FILL)
+ drawworkgrid(chipworkspace,{})
+
+ chiptools = vgui.Create( "DPanel",chipframe )
+ chiptools:Dock(LEFT)
+
+ millfunctions = vgui.Create( "DPanel",chipframe )
+ millfunctions:Dock(BOTTOM)
+
+
+end)
+
+function ENT:Draw()
+
+ self:DrawModel()
+end
diff --git a/entities/entities/art_chipmill/init.lua b/entities/entities/art_chipmill/init.lua
new file mode 100644
index 0000000..aa1f0e7
--- /dev/null
+++ b/entities/entities/art_chipmill/init.lua
@@ -0,0 +1,81 @@
+AddCSLuaFile( "cl_init.lua" )
+AddCSLuaFile( "shared.lua" )
+
+ART.RegisterChipType = function(tbl)
+ print("Trying to register chip type!")
+end
+include("shared.lua")
+
+local mdltbl = {
+{"models/props_c17/furnituretable002a.mdl",
+Vector(2,1,-30),
+Angle(0,-90,0)},
+{"models/props_junk/meathook001a.mdl",
+Vector(22,10,2),
+Angle(-1,126,160)},
+{"models/props_interiors/pot01a.mdl",
+Vector(2,-3,-13),
+Angle(0,180,180)},
+{"models/props_junk/metal_paintcan001a.mdl",
+Vector(-4,-2,-16),
+Angle(0,-45,0)},
+{"models/props_c17/furnituretable002a.mdl",
+Vector(2,-3,-30),
+Angle(85,-90,1)},
+{"models/props_c17/tools_wrench01a.mdl",
+Vector(-23,2,-10),
+Angle(-2,-26,0)},
+{"models/props_c17/trappropeller_lever.mdl",
+Vector(21,-2,-10),
+Angle(88,-104,63)},
+{"models/props_junk/garbage_takeoutcarton001a.mdl",
+Vector(23,11,11),
+Angle(-11,39,-179)},
+{"models/props_junk/garbage_milkcarton002a.mdl",
+Vector(17,6,16),
+Angle(71,34,177)},
+{"models/props_junk/garbage_metalcan001a.mdl",
+Vector(12,2,13),
+Angle(-5,-42,-162)},
+{"models/props_junk/flare.mdl",
+Vector(8,0,10),
+Angle(-13,-89,152)},
+}
+
+function ENT:Initialize()
+ self:SetModel("models/hunter/blocks/cube2x2x1.mdl")
+ self:SetAngles(Angle(90,90,180))
+ self:PhysicsInit( SOLID_VPHYSICS )
+ self:SetMoveType( MOVETYPE_NONE )
+ self:SetSolid( SOLID_VPHYSICS )
+ self:SetCollisionGroup( COLLISION_GROUP_INTERACTIVE )
+ self:SetUseType(SIMPLE_USE)
+
+ local phys = self:GetPhysicsObject()
+ --Wait a second so that we have a valid pos, self:GetPos() will return origin without this.
+ timer.Simple(1,function()
+ self:SetPos(self:GetPos() + Vector(0,0,30))
+ self:SetColor( Color( 0, 0, 0, 0 ) )
+ self:SetRenderMode( RENDERMODE_TRANSALPHA )
+ for k,v in pairs(mdltbl) do
+ print("Createing a " .. k)
+ local part = ents.Create("prop_dynamic")
+ part:SetModel(v[1])
+ part:SetPos(self:GetPos() + v[2])
+ part:SetAngles(v[3])
+ part:Spawn()
+ end
+ end)
+
+
+ phys:EnableMotion(false)
+ phys:Sleep()
+end
+
+util.AddNetworkString("openchipmill")
+
+function ENT:Use(ply)
+ net.Start("openchipmill")
+ net.WriteEntity(self)
+ net.Send(ply)
+end
diff --git a/entities/entities/art_chipmill/shared.lua b/entities/entities/art_chipmill/shared.lua
new file mode 100644
index 0000000..82eef2c
--- /dev/null
+++ b/entities/entities/art_chipmill/shared.lua
@@ -0,0 +1,30 @@
+ENT.Type = "anim"
+ENT.Base = "base_anim"
+
+--[[
+ The different kinds of chips
+]]
+
+local clockon = Material("materials/chipicons/clock1.png")
+local clockoff = Material("materials/chipicons/clock2.png")
+local clocktype = {
+ ["Name"] = "Clock",
+ ["GetImage"] = function(self)
+ if self.A == 1 then
+ return clockon
+ else
+ return clockoff
+ end
+ end,
+ ["OnTick"] = function(self)
+ self.A = self.A == 1 and 0 or 1
+ end,
+ ["Inputs"] = {},
+ ["Outputs"] = {
+ ["A"] = function(self)
+ return self.A
+ end,
+ },
+}
+
+ART.RegisterChipType(clocktype)
diff --git a/entities/entities/art_serverchanger/cl_init.lua b/entities/entities/art_serverchanger/cl_init.lua
new file mode 100644
index 0000000..ae9d143
--- /dev/null
+++ b/entities/entities/art_serverchanger/cl_init.lua
@@ -0,0 +1,66 @@
+include('shared.lua')
+
+ENT.RenderGroup = RENDERGROUP_BOTH
+
+/*---------------------------------------------------------
+ Name: Draw
+ Desc: Draw it!
+---------------------------------------------------------*/
+function ENT:Draw()
+ self:DrawModel()
+end
+
+/*---------------------------------------------------------
+ Name: DrawTranslucent
+ Desc: Draw translucent
+---------------------------------------------------------*/
+function ENT:DrawTranslucent()
+
+ -- This is here just to make it backwards compatible.
+ -- You shouldn't really be drawing your model here unless it's translucent
+
+ self:Draw()
+
+end
+
+/*---------------------------------------------------------
+ Name: BuildBonePositions
+ Desc:
+---------------------------------------------------------*/
+function ENT:BuildBonePositions( NumBones, NumPhysBones )
+
+ -- You can use this section to position the bones of
+ -- any animated model using self:SetBonePosition( BoneNum, Pos, Angle )
+
+ -- This will override any animation data and isn't meant as a
+ -- replacement for animations. We're using this to position the limbs
+ -- of ragdolls.
+
+end
+
+
+
+/*---------------------------------------------------------
+ Name: SetRagdollBones
+ Desc:
+---------------------------------------------------------*/
+function ENT:SetRagdollBones( bIn )
+
+ -- If this is set to true then the engine will call
+ -- DoRagdollBone (below) for each ragdoll bone.
+ -- It will then automatically fill in the rest of the bones
+
+ self.m_bRagdollSetup = bIn
+
+end
+
+
+/*---------------------------------------------------------
+ Name: DoRagdollBone
+ Desc:
+---------------------------------------------------------*/
+function ENT:DoRagdollBone( PhysBoneNum, BoneNum )
+
+ -- self:SetBonePosition( BoneNum, Pos, Angle )
+
+end
diff --git a/entities/entities/art_serverchanger/init.lua b/entities/entities/art_serverchanger/init.lua
new file mode 100644
index 0000000..ebb1e54
--- /dev/null
+++ b/entities/entities/art_serverchanger/init.lua
@@ -0,0 +1,39 @@
+
+AddCSLuaFile( "cl_init.lua" )
+AddCSLuaFile( "shared.lua" )
+
+include("shared.lua")
+
+function ENT:Initialize()
+ --print("NPC spawned!")
+ --self:SetCollisionGroup(COLLISION_GROUP_INTERACTIVE)
+ --self:SetUseType(SIMPLE_USE)
+
+ if(self.Model) then self:SetModel(self.Model)
+ else print("Server changer created without model, this might be a bug!") end
+
+ if self.Pos then self:SetPos(self.Pos)
+ else print("Server changer created without a position, this might be a bug!") end
+
+ if self.OnHit then self.PhysicsCollide = self.OnHit
+ else print("Server changer created without an OnHit, this might be a bug!") end
+
+ self.talking = false
+
+ if self.Name then self:SetName(self.Name)
+ else print("NPC created without a name! They won't be able to open doors!") end
+
+ if self.OnSpawn then self.OnSpawn(self) end
+
+ self:SetMoveType(MOVETYPE_NONE)
+ self:PhysicsInit(SOLID_OBB)
+ self:SetSolid(SOLID_VPHYSICS)
+
+ constraint.Weld(self,game.GetWorld(),0,0,0,true,true)
+
+end
+
+function ENT:PhysicsCollide(coldata,obj)
+ print("Physics collide detected")
+ if self.OnHit then self.OnHit(coldata,obj) end
+end
diff --git a/entities/entities/art_serverchanger/shared.lua b/entities/entities/art_serverchanger/shared.lua
new file mode 100644
index 0000000..b7fc605
--- /dev/null
+++ b/entities/entities/art_serverchanger/shared.lua
@@ -0,0 +1,21 @@
+ENT.Base = "base_entity"
+ENT.Type = "anim"
+//WS stuff
+ENT.Drops = nil
+ENT.OnDammage = nil
+ENT.Speed = 0
+ENT.Model = nil
+
+ENT.Behave = nil
+ENT.Act = nil
+
+/*---------------------------------------------------------
+ Name: OnRemove
+ Desc: Called just before entity is deleted
+---------------------------------------------------------*/
+function ENT:OnRemove()
+end
+
+function ENT:Use()
+
+end
diff --git a/entities/entities/info_townienode/cl_init.lua b/entities/entities/info_townienode/cl_init.lua
new file mode 100644
index 0000000..53dec09
--- /dev/null
+++ b/entities/entities/info_townienode/cl_init.lua
@@ -0,0 +1,69 @@
+include('shared.lua')
+
+ENT.RenderGroup = RENDERGROUP_BOTH
+
+/*---------------------------------------------------------
+ Name: Draw
+ Desc: Draw it!
+---------------------------------------------------------*/
+function ENT:Draw()
+ --self:DrawModel()
+ render.SetColorMaterial()
+ render.DrawSphere( self:GetPos(), 10, 30, 30, Color( 0, 175, 175, 100 ) )
+
+end
+
+/*---------------------------------------------------------
+ Name: DrawTranslucent
+ Desc: Draw translucent
+---------------------------------------------------------*/
+function ENT:DrawTranslucent()
+
+ // This is here just to make it backwards compatible.
+ // You shouldn't really be drawing your model here unless it's translucent
+
+ --self:Draw()
+
+end
+
+/*---------------------------------------------------------
+ Name: BuildBonePositions
+ Desc:
+---------------------------------------------------------*/
+function ENT:BuildBonePositions( NumBones, NumPhysBones )
+
+ // You can use this section to position the bones of
+ // any animated model using self:SetBonePosition( BoneNum, Pos, Angle )
+
+ // This will override any animation data and isn't meant as a
+ // replacement for animations. We're using this to position the limbs
+ // of ragdolls.
+
+end
+
+
+
+/*---------------------------------------------------------
+ Name: SetRagdollBones
+ Desc:
+---------------------------------------------------------*/
+function ENT:SetRagdollBones( bIn )
+
+ // If this is set to true then the engine will call
+ // DoRagdollBone (below) for each ragdoll bone.
+ // It will then automatically fill in the rest of the bones
+
+ self.m_bRagdollSetup = bIn
+
+end
+
+
+/*---------------------------------------------------------
+ Name: DoRagdollBone
+ Desc:
+---------------------------------------------------------*/
+function ENT:DoRagdollBone( PhysBoneNum, BoneNum )
+
+ // self:SetBonePosition( BoneNum, Pos, Angle )
+
+end
diff --git a/entities/entities/info_townienode/init.lua b/entities/entities/info_townienode/init.lua
new file mode 100644
index 0000000..9fa7f7e
--- /dev/null
+++ b/entities/entities/info_townienode/init.lua
@@ -0,0 +1,16 @@
+--[[
+ This entity gives townies things to do
+]]
+AddCSLuaFile( "cl_init.lua" )
+AddCSLuaFile( "shared.lua" )
+
+include("shared.lua")
+
+function ENT:Initialize()
+ self:SetModel("models/error.mdl")
+ self:SetMoveType(MOVETYPE_NONE)
+ self:SetSolid(SOLID_NONE)
+ self:SetCollisionGroup(COLLISION_GROUP_INTERACTIVE)
+ --self:SetNoDraw(true)
+ self:SetPos(self.Position)
+end
diff --git a/entities/entities/info_townienode/shared.lua b/entities/entities/info_townienode/shared.lua
new file mode 100644
index 0000000..8b42e7f
--- /dev/null
+++ b/entities/entities/info_townienode/shared.lua
@@ -0,0 +1,23 @@
+ENT.Base = "base_entity"
+
+//WS stuff
+ENT.Drops = nil
+ENT.OnDammage = nil
+ENT.Speed = 0
+ENT.Model = nil
+
+ENT.Behave = nil
+ENT.Act = nil
+
+/*---------------------------------------------------------
+ Name: OnRemove
+ Desc: Called just before entity is deleted
+---------------------------------------------------------*/
+function ENT:OnRemove()
+end
+
+function ENT:DoActivity(npc)
+ if not self.onActivity() then
+ print("Node without activity, this might be an error!")
+ end
+end
diff --git a/entities/entities/npc_townie/cl_init.lua b/entities/entities/npc_townie/cl_init.lua
index f941737..a8ba643 100644
--- a/entities/entities/npc_townie/cl_init.lua
+++ b/entities/entities/npc_townie/cl_init.lua
@@ -16,8 +16,8 @@ end
---------------------------------------------------------*/
function ENT:DrawTranslucent()
- // This is here just to make it backwards compatible.
- // You shouldn't really be drawing your model here unless it's translucent
+ -- This is here just to make it backwards compatible.
+ -- You shouldn't really be drawing your model here unless it's translucent
self:Draw()
@@ -29,12 +29,12 @@ end
---------------------------------------------------------*/
function ENT:BuildBonePositions( NumBones, NumPhysBones )
- // You can use this section to position the bones of
- // any animated model using self:SetBonePosition( BoneNum, Pos, Angle )
+ -- You can use this section to position the bones of
+ -- any animated model using self:SetBonePosition( BoneNum, Pos, Angle )
- // This will override any animation data and isn't meant as a
- // replacement for animations. We're using this to position the limbs
- // of ragdolls.
+ -- This will override any animation data and isn't meant as a
+ -- replacement for animations. We're using this to position the limbs
+ -- of ragdolls.
end
@@ -46,9 +46,9 @@ end
---------------------------------------------------------*/
function ENT:SetRagdollBones( bIn )
- // If this is set to true then the engine will call
- // DoRagdollBone (below) for each ragdoll bone.
- // It will then automatically fill in the rest of the bones
+ -- If this is set to true then the engine will call
+ -- DoRagdollBone (below) for each ragdoll bone.
+ -- It will then automatically fill in the rest of the bones
self.m_bRagdollSetup = bIn
@@ -61,6 +61,52 @@ end
---------------------------------------------------------*/
function ENT:DoRagdollBone( PhysBoneNum, BoneNum )
- // self:SetBonePosition( BoneNum, Pos, Angle )
+ -- self:SetBonePosition( BoneNum, Pos, Angle )
end
+
+local chatframe = nil
+
+net.Receive("opennpcdialog",function()
+ if chatframe ~= nil and chatframe:IsValid() then
+ chatframe:Remove()
+ chatframe = nil
+ end
+ local width, height = ScrW(), ScrH()
+ local who = net.ReadEntity()
+ local chattbl = net.ReadTable()
+ chatframe = vgui.Create( "DFrame" )
+ chatframe:SetPos( (width / 2) - (width / 4), height - (height / 4) )
+ chatframe:SetSize( width / 2, height / 4 )
+ chatframe:SetTitle( chattbl["Name"] )
+ chatframe:SetDraggable( true )
+ chatframe.OnClose = function()
+ net.Start("closenpcdialog")
+ net.WriteEntity(who)
+ net.SendToServer()
+ end
+
+ local chattxt = vgui.Create( "DLabel", chatframe )
+ --chattxt:SetPos( 40, 40 )
+ chattxt:SetText(chattbl["Message"])
+ chattxt:Dock(TOP)
+
+ for k,v in pairs(chattbl["Options"]) do
+ local chatbutton = vgui.Create( "DButton",chatframe )
+ --chatbutton:SetPos( 40, 40 )
+ chatbutton:SetText( v )
+ --chatbutton:SetSize( 120, 60 )
+ chatbutton.DoClick = function()
+ net.Start("updatenpcdialog")
+ net.WriteEntity(who)
+ net.WriteString(v)
+ net.SendToServer()
+ end
+ chatbutton:Dock(BOTTOM)
+ end
+ chattxt:Dock(FILL)
+
+
+
+ chatframe:MakePopup()
+end)
diff --git a/entities/entities/npc_townie/init.lua b/entities/entities/npc_townie/init.lua
index aa0f007..66cfaf1 100644
--- a/entities/entities/npc_townie/init.lua
+++ b/entities/entities/npc_townie/init.lua
@@ -6,12 +6,48 @@ include('shared.lua')
function ENT:Initialize()
--print("NPC spawned!")
- --self:SetMoveType(MOVETYPE_STEP)
- self:SetSolid(SOLID_OBB)
- --self:SetCollisionGroup(COLLISION_GROUP_INTERACTIVE)
+ --self:SetMoveType(MOVETYPE_VPHYSICS)
+ self:SetSolid(SOLID_BBOX )
+ self:SetCollisionGroup(COLLISION_GROUP_NPC )
+
+ self:SetHealth(50)
+
+ self.loco:SetDeathDropHeight(500) //default 200
+ self.loco:SetAcceleration(400) //default 400
+ self.loco:SetDeceleration(400) //default 400
+ self.loco:SetStepHeight(18) //default 18
+ self.loco:SetJumpHeight(25) //default 58
+ self.loco:SetDesiredSpeed( 50 )
+
+ self.nodereached = false
+
+ self.lastdooropen = CurTime()
if(self.Model) then self:SetModel(self.Model)
else print("NPC created without model, this might be a bug!") end
+
+ if self.Pos then self:SetPos(self.Pos)
+ else print("NPC created without a position, this might be a bug!") end
+
+ self.talking = false
+
+ if self.Name then self:SetName(self.Name)
+ else print("NPC created without a name! They won't be able to open doors!") end
+
+ if self.OnSpawn then self.OnSpawn(self) end
+
+ self.allowedNodes = {}
+
+ for k,v in pairs(ents.FindByClass( "info_townienode" ) ) do
+ if self.NavNodes[v.Name] then
+ table.insert(self.allowedNodes,v)
+ end
+ end
+
+ self:SetUseType( SIMPLE_USE )
+
+ self.DialogCursors = {}
+ --[[
if(not self.Stats) then
print("NPC created without any stats, this is a bug!")
return
@@ -24,6 +60,7 @@ function ENT:Initialize()
if(self.Stats["Step"]) then self.loco:SetJumpHeight(self.Stats["Step"]) end
if(self.OnSpawn) then self:OnSpawn() end
--self:SetModel( "models/Humans/Group01/Female_01.mdl" )
+ ]]
--[[
self:SetHullType( HULL_HUMAN );
self:SetHullSizeNormal();
@@ -46,13 +83,6 @@ function ENT:OnInjured(dmg)
if self.OnDammage != nil then self:OnDammage(dmg) end
end
-function ENT:OnContact(ent)
- if(ent:GetClass() == "ws_arrow") then
- self:TakeDamage(30)
- ent:SetParent(self)
- end
-end
-
function ENT:OnKilled(dmg)
if(CLIENT) then return end
if not self.Drops then return end
diff --git a/entities/entities/npc_townie/shared.lua b/entities/entities/npc_townie/shared.lua
index 3662edd..437275a 100644
--- a/entities/entities/npc_townie/shared.lua
+++ b/entities/entities/npc_townie/shared.lua
@@ -104,20 +104,158 @@ function ENT:Use()
end
+function ENT:OnStuck()
+ print("I'm stuck!")
+ self.curnode = self:selectNewNode()
+ self.nodereached = false
+end
+
+function ENT:selectNewNode()
+ --print("selectNewNode called")
+ --debug.Trace()
+ --print("Selecting from nodes")
+ --PrintTable(self.allowedNodes)
+ --local nodes = ents.FindByClass("info_townienode")
+ if #self.allowedNodes == 0 then return end
+ local rnode = table.Random(self.allowedNodes)
+ return rnode
+end
+
+local removeblock = {
+ ["prop_door_rotating"] = function(bot,ent)
+ ent:Fire("OpenAwayFrom",bot:GetName())
+ --Couln't get it to open correct direction, back up and go through
+ timer.Simple(3,function()
+ ent:Fire("Close")
+ end)
+ end
+}
+
function ENT:BehaveUpdate(num)
- --print(num)
- --self:BehaveUpdate(num)
+ if not self.BehaveThread then return end
+ if self.curnode ~= nil and self.curnode:IsValid() then
+ if self.curnode:GetPos():Distance(self:GetPos()) < 5 then
+ if self.nodereached == false then
+ self.curnode.OnReached(self)
+ self.nodereached = true
+ else
+ if self.curnode.IsDone(self) then
+ print("Finished action")
+ self.curnode = self:selectNewNode()
+ self.nodereached = false
+ end
+ end
+ end
+ end
+ local trdata = {
+ ["start"] = self:GetPos() + (self:GetUp()*72),
+ ["endpos"] = self:GetPos() + (self:GetUp()*72) + (self:GetForward()*32),
+ ["filter"] = self
+ }
+ local tr = util.TraceLine(trdata)
+ if tr.Hit then
+ --print(tr.Entity)
+ if removeblock[tr.Entity:GetClass()] ~= nil then
+ removeblock[tr.Entity:GetClass()](self,tr.Entity)
+ end
+ end
+ local ok, message = coroutine.resume( self.BehaveThread )
+ if ( ok == false ) then
- if(self.BehaveUpdate) then
- self:BehaveUpdate(num)
- end
+
+ self.BehaveThread = nil
+ Msg( self, "error: ", message, "\n" );
+
+
+ end
end
function ENT:RunBehaviour()
- if(self.Behave) then
- self:Behave()
- else
- self:DefaultBehaviour()
+ while true do
+ --print("In runbehaviour")
+ local opts = { lookahead = 300,
+ tolerance = 20,
+ draw = true,
+ maxage = 1,
+ repath = 0.1 }
+ if self.curnode == nil or not self.curnode:IsValid() or self.curnode:GetPos():Distance(self:GetPos()) < 5 then
+ self.curnode = self:selectNewNode()
+ end
+ if self.curnode == nil then
+ print("Townie could not find any nodes!")
+ while true do
+ coroutine.yield()
+ end
+ end
+ if self.curnode ~= nil and self.curnode:IsValid() then
+ self:MoveToPos( self.curnode:GetPos(), opts )
+ self:StartActivity(ACT_WALK )
+ end
+ --print("Called movetopos")
+ coroutine.yield()
+ end
+end
+
+if SERVER then
+ util.AddNetworkString( "opennpcdialog" )
+ util.AddNetworkString( "closenpcdialog" )
+ util.AddNetworkString( "updatenpcdialog")
+end
+
+--Fix the dialog so we aren't sending functions
+function SendableDialog(tbl)
+ local ntbl = table.Copy(tbl)
+ ntbl["Options"] = table.GetKeys(tbl["Options"])
+ return ntbl
+end
+
+net.Receive("closenpcdialog",function(len,ply)
+ print("player closed dialog1")
+ local npc = net.ReadEntity()
+ print("player closed dialog")
+ npc.DialogCursors[ply] = nil
+ if next(npc.DialogCursors) == nil then -- no one is talking to us, resume movement
+ if npc.loco:GetMaxYawRate() == 0 and npc.loco:GetAcceleration() == 0 then
+ npc.loco:SetMaxYawRate(npc.oyaw)
+ npc.loco:SetAcceleration(npc.oacc)
+ end
end
+end)
+
+net.Receive("updatenpcdialog",function(len,ply)
+ local npc = net.ReadEntity()
+ local option = net.ReadString()
+ npc.DialogCursors[ply] = npc.DialogCursors[ply]["Options"][option](ply)
+ net.Start("opennpcdialog")
+ net.WriteEntity(npc)
+ net.WriteTable(SendableDialog(npc.DialogCursors[ply]))
+ net.Send(ply)
+end)
+
+function ENT:Use(ply)
+ self.DialogCursors[ply] = self.getDialogFor(ply)
+ --
+ if self.oyaw ~= 0 and self.oacc ~= 0 then
+ self.oyaw, self.oacc,self.onod = self.loco:GetMaxYawRate(), self.loco:GetAcceleration(), self.curnode
+ end
+ self.loco:SetAcceleration(0)
+ self.loco:SetVelocity(Vector(0,0,0))
+ self.loco:SetMaxYawRate(9999990)
+ self.loco:FaceTowards(ply:GetPos())
+ self.loco:SetMaxYawRate(0)
+ timer.Simple(0.5,function()
+ --self.loco:FaceTowards(ply:GetPos())
+
+
+ end)
+ net.Start("opennpcdialog")
+ net.WriteEntity(self)
+ net.WriteTable(SendableDialog(self.DialogCursors[ply]))
+ net.Send(ply)
+end
+
+function ENT:OnClose()
+ self.loco:SetMaxYawRate(self.oyaw)
+ self.loco:SetAcceleration(self.oacc)
end
diff --git a/entities/weapons/hands.lua b/entities/weapons/hands.lua
index 3d74aa3..c97249a 100644
--- a/entities/weapons/hands.lua
+++ b/entities/weapons/hands.lua
@@ -77,31 +77,10 @@ function SWEP:PrimaryAttack()
end
function SWEP:SecondaryAttack()
- --[[
- if (CLIENT and !IsFirstTimePredicted()) then return end
- if (!self.Owner.Weapons or !self.Owner.Weapons[self.Owner.Select]) then return end
- if (self.Owner.CD and self.Owner.CD > CurTime()) then return end
-
- local item = self.Owner.Weapons[self.Owner.Select].Item
-
- if (!item or !item.OnSecondary) then return end
-
- self.Owner:SetAnimation( PLAYER_ATTACK1 )
-
- local Trace = {
- start = self.Owner:GetShootPos(),
- endpos = self.Owner:GetShootPos()+self.Owner:GetAimVector()*item.Range,
- filter = self.Owner,
- mins = Box*-1,
- maxs = Box,
- }
-
- local Tr = util.TraceHull(Trace)
-
- item:OnSecondary(self.Owner,Tr)
-
- self.Owner.CD = CurTime()+item.CD
- ]]
+ local rightitem = self.Owner.Inventory.Equiped["Right"]
+ if rightitem ~= false and rightitem.onClick ~= nil then
+ rightitem:onClick(self.Owner)
+ end
end
if (CLIENT) then