local ENT = nrequire("sh_art_npc.lua") local log = nrequire("log.lua") util.AddNetworkString( "art_opennpcdialog" ) util.AddNetworkString( "art_closenpcdialog" ) util.AddNetworkString( "art_updatenpcdialog") local oinit = ENT.Initalize function ENT:Initialize() --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 log.error("NPC created without model, this might be a bug!") end if self.Pos then self:SetPos(self.Pos) else log.error("NPC created without a position, this might be a bug!") end self.talking = false if self.Name then self:SetName(self.Name) else log.error("NPC created without a name! They won't be able to open doors!") end if self.Ang then self:SetAngles(self.Ang) end if self.OnSpawn then self.OnSpawn(self) end self.allowedNodes = {} self.NavNodes = self.NavNodes or {} 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 oinit then oinit(self) end end function ENT:OnInjured(dmg) if self.OnDammage ~= nil then self:OnDammage(dmg) end end local removeblock = { ["prop_door_rotating"] = function(bot,ent) ent:Fire("OpenAwayFrom",bot:GetName()) timer.Simple(3,function() ent:Fire("Close") end) end } function ENT:BehaveUpdate(num) if not self.BehaveThread then return end if self.curnode and self.curnode:IsValid() and 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 --error("Finished action") self.curnode = self:selectNewNode() self.nodereached = false 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) local ecl if (tr ~= nil) and (tr.Entity ~= nil) and tr.Entity:IsValid() then ecl = tr.Entity:GetClass() end if tr.Hit and removeblock[ecl] ~= nil then removeblock[ecl](self,tr.Entity) end local ok, message = coroutine.resume( self.BehaveThread ) if not ok then self.BehaveThread = nil Msg( self, "error: ", message, "\n" ); end end function ENT:OnKilled(dmg) if not self.Drops then return end for k,v in pairs(self.Drops) do local rng = math.random(0,100) local itemname = self.Drops[k][1] local itemchance = self.Drops[k][2] local heightoffset = 10 if rng < itemchance then local drop = ents.Create("ws_item") drop.Item = GetItemByName(itemname) drop:SetModel(drop.Item.Model) drop:SetPos(self:GetPos() + (self:GetUp() * heightoffset)) drop:Spawn() heightoffset = heightoffset + 10 end end self:BecomeRagdoll( dmg ) end local devs = {} concommand.Add("artery_develop",function(ply,cmd,args) if not ply:IsAdmin() then return end if devs[ply] then devs[ply] = nil else devs[ply] = true end end) --Fix the dialog so we aren't sending functions local function SendableDialog(tbl) local ntbl = table.Copy(tbl) ntbl["Options"] = table.GetKeys(tbl["Options"]) return ntbl end function ENT:Use(ply) if devs[ply] then else 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("art_opennpcdialog") net.WriteEntity(self) net.WriteTable(SendableDialog(self.DialogCursors[ply])) net.Send(ply) end end net.Receive("art_updatenpcdialog",function(len,ply) local npc = net.ReadEntity() local option = net.ReadString() npc.DialogCursors[ply] = npc.DialogCursors[ply]["Options"][option](ply) net.Start("art_opennpcdialog") net.WriteEntity(npc) net.WriteTable(SendableDialog(npc.DialogCursors[ply])) net.Send(ply) end) scripted_ents.Register(ENT, "art_npc")