aboutsummaryrefslogtreecommitdiff
path: root/gamemode/shared/player_ghost.lua
diff options
context:
space:
mode:
authorApickx <Apickx@cogarr.org>2015-12-28 19:10:44 -0500
committerApickx <Apickx@cogarr.org>2015-12-28 19:10:44 -0500
commit5c4ebc932d8c02522802c842d43d863d89aca162 (patch)
tree6be7ad664bdf060127e6df6baa72beaf508aa149 /gamemode/shared/player_ghost.lua
downloadwintersurvival2-5c4ebc932d8c02522802c842d43d863d89aca162.tar.gz
wintersurvival2-5c4ebc932d8c02522802c842d43d863d89aca162.tar.bz2
wintersurvival2-5c4ebc932d8c02522802c842d43d863d89aca162.zip
Initial commit
Diffstat (limited to 'gamemode/shared/player_ghost.lua')
-rw-r--r--gamemode/shared/player_ghost.lua97
1 files changed, 97 insertions, 0 deletions
diff --git a/gamemode/shared/player_ghost.lua b/gamemode/shared/player_ghost.lua
new file mode 100644
index 0000000..049ede7
--- /dev/null
+++ b/gamemode/shared/player_ghost.lua
@@ -0,0 +1,97 @@
+local meta = FindMetaTable("Player")
+
+if (SERVER) then
+ util.AddNetworkString("Ghost")
+ util.AddNetworkString("GhostRemove")
+
+ function meta:GhostStructure(item)
+ item = GetItemByName(item)
+
+ if (!item or !item.Ghost) then return end
+ if (!self.StructurePlace) then self.StructurePlace = true end
+
+ net.Start("Ghost")
+ net.WriteString(item.Name)
+ net.Send(self)
+ end
+
+ function meta:GhostRemove()
+ self.StructurePlace = false
+ net.Start("GhostRemove") net.Send(self)
+ end
+else
+ local Zero = Vector(0,0,0)
+ local gr = Color(0,255,0,100)
+ local Box = Vector(8,8,8)
+
+ net.Receive("Ghost",function()
+ local pl = LocalPlayer()
+ local It = GetItemByName(net.ReadString())
+
+ if (!It) then return end
+ if (!IsValid(pl.Ghost)) then pl.Ghost = ClientsideModel("error.mdl") pl.Ghost:SetNoDraw(true) end
+
+ pl.GhostItem = It
+ pl.StructurePlace = true
+ end)
+
+ net.Receive("GhostRemove",function() LocalPlayer().StructurePlace = false end)
+
+ hook.Add("PostDrawTranslucentRenderables","GhostStructure",function()
+ local pl = LocalPlayer()
+
+ if (pl:IsPigeon() or !pl.GhostItem or !pl.GhostItem.Ghost or !IsValid(pl.Ghost) or !pl.StructurePlace) then return end
+
+ local Ghost = pl.Ghost
+ local Aim = Angle(0,pl:GetAimVector():Angle().y+90,0)
+ local Pos = util.TraceHull({
+ start = pl:GetShootPos(),
+ endpos = pl:GetShootPos()+pl:GetAimVector()*pl.GhostItem.Range,
+ filter = pl,
+ mins = Box*-1,
+ maxs = Box,
+ })
+
+ local CanP = pl:CanPlaceStructure(Pos)
+ Pos = Pos.HitPos
+
+ for k,v in pairs(pl.GhostItem.Ghost) do
+ local OffPos = v.Pos*1
+ OffPos:Rotate(Aim)
+
+ Ghost:SetModel(v.Model)
+ Ghost:SetRenderOrigin(Pos+OffPos)
+ Ghost:SetRenderAngles(v.Ang+Aim)
+
+ local mat = Matrix()
+ mat:Scale( v.Size or Zero )
+
+ Ghost:EnableMatrix( "RenderMultiply", mat )
+ Ghost:SetupBones()
+
+ if (CanP) then render.SetColorModulation(0,10,0)
+ else render.SetColorModulation(10,0,0) end
+
+ render.SetBlend(0.7)
+ Ghost:DrawModel()
+ render.SetColorModulation(1,1,1)
+ render.SetBlend(1)
+ end
+
+ Ghost:SetRenderOrigin(Pos)
+ end)
+end
+
+function meta:CanPlaceStructure(Tr)
+ if (Tr and Tr.HitPos) then
+ local A = util.PointContents( Tr.HitPos )
+ local Ang = math.AngleNormalize(Tr.HitNormal:Angle())
+
+ if (A == CONTENTS_WATER or A == CONTENTS_WATER+CONTENTS_TRANSLUCENT ) then return false end
+ if (Ang.p < -120 or Ang.p > -60) then return false end
+
+ --if (!Tr.HitWorld) then return false end
+ end
+
+ return self.StructurePlace
+end