Compare commits

...

3 Commits

Author SHA1 Message Date
Pascal Abresch 552564713b heavily cleanup lua code 2018-12-30 02:49:07 +01:00
Pascal Abresch 28f91d7a43 spawn props statically 2018-12-30 02:48:37 +01:00
Pascal Abresch 252f7d0d06 modified readme 2018-12-30 02:48:20 +01:00
3 changed files with 168 additions and 189 deletions

View File

@ -1,2 +1 @@
# propplace
this addon is designed to place props, that's about it

View File

@ -14,6 +14,10 @@ if SERVER then
ent:SetPos(pos)
ent:SetAngles(angle)
ent:Spawn()
local physx = ent:GetPhysicsObject()
if physx and physx:IsValid() then
physx:EnableMotion(false)
end
cleanup.Add(player, "props", ent)
undo.Create(("Spawned " .. model_file))
undo.AddEntity(ent)

View File

@ -20,236 +20,212 @@ SWEP.DrawCrosshair = true
SWEP.AccurateCrosshair = true
SWEP.ViewModel = "models/weapons/v_slam.mdl"
SWEP.WorldModel = "models/weapons/w_slam.mdl"
if SERVER then return end
if (not propplacer or not propplacer.last_model) then -- don't remove values on hot reload
propplacer = {last_model = nil, last_tick = 0, rotatepitch = 0, rotateroll = 0, rotateyaw = 0}
end
-- clientside variables
local ShootSound = Sound("garrysmod/balloon_pop_cute.wav")
local function _0_(...)
if (CLIENT and (not propplacer or not propplacer.last_model)) then
propplacer = {last_model = nil, last_tick = 0, rotatepitch = 0, rotateroll = 0, rotateyaw = 0}
return nil
end
end
_0_(...)
local function _1_(...)
if CLIENT then
SWEP.model = "models/balloons/balloon_dog.mdl"
SWEP.freeze = false
SWEP.angles = Angle(0, 0, 0)
return nil
end
end
_1_(...)
SWEP.model = "models/balloons/balloon_dog.mdl"
SWEP.freeze = false
SWEP.angles = Angle(0, 0, 0)
SWEP.PrimaryAttack = function(self)
self:EmitSound(ShootSound)
if (CLIENT and IsFirstTimePredicted()) then
local function _2_()
if self.freeze then
return self.last_pos
else
return self.Owner:GetEyeTrace().HitPos
end
if IsFirstTimePredicted() then
self:EmitSound(ShootSound)
if self.freeze then
self:Place(self.model, self.last_pos, (self.last_angles + self.angles))
self.freeze = false
else
self:Place(self.model, self.Owner:GetEyeTrace().HitPos + propplacer.last_model.aabb, self.angles )
end
local function _3_()
if self.freeze then
return (self.last_angles + self.angles)
else
local ang = Angle(0, self.Owner:EyeAngles().y, 0)
ang:Add(self.angles)
return ang
end
end
self:Place(self.model, _2_(), _3_())
self.freeze = false
return nil
end
end
do local _ = SWEP.PrimaryAttack end
SWEP.SecondaryAttack = function(self)
if (CLIENT and IsFirstTimePredicted()) then
if IsFirstTimePredicted() then
self.last_pos = self.Owner:GetEyeTrace().HitPos
self.last_angles = Angle(0, self.Owner:EyeAngles().y, 0)
self.last_angles = Angle(0, 0, 0)
self.freeze = not self.freeze
return nil
end
end
do local _ = SWEP.SecondaryAttack end
SWEP.Reload = function(self)
if (CLIENT and IsFirstTimePredicted()) then
if IsFirstTimePredicted() then
self["angles"] = Angle(0, 0, 0)
return nil
end
end
do local _ = SWEP.Reload end
SWEP.Holster = function(self)
local function _2_()
if (CLIENT and propplacer.last_model and (LocalPlayer():SteamID64() == self.Owner:SteamID64())) then
print("Remove shadow model")
propplacer.last_model:Remove()
propplacer.last_model = nil
return nil
end
if propplacer.last_model and (LocalPlayer():SteamID64() == self.Owner:SteamID64()) then
--print("Removeing shadow model")
propplacer.last_model:Remove()
propplacer.last_model = nil
end
_2_()
return true
end
do local _ = SWEP.Holster end
SWEP.DrawHUD = function(self)
local function _2_()
if (CLIENT and not propplacer.last_model) then
print("Spawn shadow model ", self.model)
propplacer.last_model = ClientsideModel(self.model, RENDERGROUP_TRANSLUCENT)
if IsValid(propplacer.last_model) then
propplacer.last_model:SetModel(self.model)
propplacer.last_model:SetCollisionGroup(COLLISION_GROUP_WORLD)
propplacer.last_model:SetRenderFX(kRenderFxPulseFastWide)
propplacer.last_model:SetRenderMode(RENDERMODE_TRANSALPHA)
propplacer.last_model:SetPos(self.Owner:GetEyeTrace().HitPos)
do
local ang = Angle(0, self.Owner:EyeAngles().y, 0)
ang:Add(self.angles)
propplacer.last_model:SetAngles(ang)
end
return propplacer.last_model:Spawn()
if not propplacer.last_model then
propplacer.last_model = ClientsideModel(self.model, RENDERGROUP_TRANSLUCENT)
if IsValid(propplacer.last_model) then
local eyetrace = self.Owner:GetEyeTrace()
local hitpos = eyetrace.HitPos
propplacer.last_model:SetModel(self.model)
propplacer.last_model:SetCollisionGroup(COLLISION_GROUP_WORLD)
propplacer.last_model:SetRenderFX(kRenderFxDistort)--PulseFastWide)
propplacer.last_model:SetRenderMode(RENDERMODE_TRANSALPHA)
propplacer.last_model:SetPos(hitpos)
propplacer.last_model:SetAngles(Angle(0,0,0))
propplacer.last_model:Spawn()
propplacer.last_model:PhysicsInit(SOLID_VPHYSICS)
propplacer.last_model:SetSolid(SOLID_VPHYSICS)
propplacer.last_model.phys = propplacer.last_model:GetPhysicsObject()
if IsValid(propplacer.last_model.phys) then
local aabb = propplacer.last_model.phys:GetAABB()
aabb = Vector(math.abs(aabb.x), math.abs(aabb.y), math.abs(aabb.z))
propplacer.last_model.aabb = aabb
propplacer.last_model:SetPos(Vector( hitpos.x + aabb.x, hitpos.y + aabb.y, hitpos.z + aabb.z))
print (propplacer.last_model.aabb)
print("Spawned shadow model " .. self.model .. " with size ", propplacer.last_model.aabb)
else
propplacer.last_model.aabb = Vector(0, 0, 0)
end
end
end
_2_()
if self.freeze then
propplacer.last_model:SetPos(self.last_pos)
return propplacer.last_model:SetAngles((self.last_angles + self.angles))
else
propplacer.last_model:SetPos(self.Owner:GetEyeTrace().HitPos)
do
local ang = Angle(0, self.Owner:EyeAngles().y, 0)
ang:Add(self.angles)
return propplacer.last_model:SetAngles(ang)
if self.freeze then
--propplacer.last_model:SetPos(self.last_pos)
--no need to set new pos, right?
--if it is checked up in freeze state anyway
--TODO: set model in init based on freeze state
propplacer.last_model:SetAngles((self.last_angles + self.angles))
else
propplacer.last_model:SetPos(self.Owner:GetEyeTrace().HitPos + propplacer.last_model.aabb)
propplacer.last_model:SetAngles(self.angles)
end
end
end
do local _ = SWEP.DrawHUD end
SWEP.Think = function(self)
if (CLIENT and propplacer.last_model and (LocalPlayer():SteamID64() == self.Owner:SteamID64())) then
local function _2_()
if (propplacer.rotateyaw ~= 0) then
return self.Owner:ConCommand(("rotatepropyaw " .. propplacer.rotateyaw))
end
if propplacer.last_model and (LocalPlayer():SteamID64() == self.Owner:SteamID64()) then
if (propplacer.rotateyaw ~= 0) then
return self.Owner:ConCommand(("rotatepropyaw " .. propplacer.rotateyaw))
end
_2_()
local function _3_()
if (propplacer.rotatepitch ~= 0) then
return self.Owner:ConCommand(("rotateproppitch " .. propplacer.rotatepitch))
end
if (propplacer.rotatepitch ~= 0) then
return self.Owner:ConCommand(("rotateproppitch " .. propplacer.rotatepitch))
end
_3_()
if (propplacer.rotateroll ~= 0) then
return self.Owner:ConCommand(("rotateproproll " .. propplacer.rotateroll))
end
end
end
do local _ = SWEP.Think end
SWEP.Place = function(self, model_file, pos, angle)
if CLIENT then
propplacer["last_tick"] = engine.TickCount()
net.Start("Propplacer.Place")
net.WriteString(model_file)
net.WriteVector(pos)
net.WriteAngle(angle)
return net.SendToServer()
end
propplacer["last_tick"] = engine.TickCount()
net.Start("Propplacer.Place")
net.WriteString(model_file)
net.WriteVector(pos)
net.WriteAngle(angle)
return net.SendToServer()
end
do local _ = SWEP.Place end
local function find_weapon(table, name)
local retentry = nil
for key, entry in pairs(table) do
local function _2_()
if (entry.PrintName == name) then
retentry = entry
return nil
end
if (entry.PrintName == name) then
retentry = entry
end
_2_()
end
return retentry
end
do local _ = find_weapon end
if CLIENT then
local function _2_(ply, cmd, args, argStr)
local weapon = find_weapon(ply:GetWeapons(), "PropPlacer")
if weapon then
weapon.model = argStr
local function gettraceplane(eyepos, eyeangles)
end
local function _2_(ply, cmd, args, argStr)
local weapon = find_weapon(ply:GetWeapons(), "PropPlacer")
if weapon then
weapon.model = argStr
util.PrecacheModel( argStr )
if propplacer.last_model then
propplacer.last_model:Remove()
propplacer.last_model = nil
return nil
else
return print("Error: Do not have PropPlacer. Please get the PropPlacer.")
end
else
print("Error: Do not have PropPlacer. Please get the PropPlacer.")
end
concommand.Add("selectprop", _2_, nil, nil, 0)
local function _3_(ply, cmd, args, argStr)
local weapon = find_weapon(ply:GetWeapons(), "PropPlacer")
local rot = tonumber(argStr)
if (weapon and rot) then
return weapon.angles:Add(Angle(rot, 0, 0))
else
return print("Error: No PropPlacer owned or rotation value invalid.")
end
end
concommand.Add("rotateproppitch", _3_)
local function _4_(ply, cmd, args, argStr)
local rot = tonumber(args[1])
if rot then
propplacer.rotatepitch = rot
return nil
end
end
concommand.Add("+rotateproppitch", _4_)
local function _5_(ply, cmd, args, argStr)
propplacer.rotatepitch = 0
return nil
end
concommand.Add("-rotateproppitch", _5_)
local function _6_(ply, cmd, args, argStr)
local weapon = find_weapon(ply:GetWeapons(), "PropPlacer")
local rot = tonumber(argStr)
if (weapon and rot) then
return weapon.angles:Add(Angle(0, rot, 0))
else
return print("Error: No PropPlacer owned or rotation value invalid.")
end
end
concommand.Add("rotatepropyaw", _6_)
local function _7_(ply, cmd, args, argStr)
local rot = tonumber(args[1])
if rot then
propplacer.rotateyaw = rot
return nil
end
end
concommand.Add("+rotatepropyaw", _7_)
local function _8_(ply, cmd, args, argStr)
propplacer.rotateyaw = 0
return nil
end
concommand.Add("-rotatepropyaw", _8_)
local function _9_(ply, cmd, args, argStr)
local weapon = find_weapon(ply:GetWeapons(), "PropPlacer")
local rot = tonumber(argStr)
if (weapon and rot) then
return weapon.angles:Add(Angle(0, 0, rot))
else
return print("Error: No PropPlacer owned or rotation value invalid.")
end
end
concommand.Add("rotateproproll", _9_)
local function _10_(ply, cmd, args, argStr)
local rot = tonumber(args[1])
if rot then
propplacer.rotateroll = rot
return nil
end
end
concommand.Add("+rotateproproll", _10_)
local function _11_(ply, cmd, args, argStr)
propplacer.rotateroll = 0
return nil
end
return concommand.Add("-rotateproproll", _11_)
end
concommand.Add("selectprop", _2_, nil, nil, 0)
local function _3_(ply, cmd, args, argStr)
local weapon = find_weapon(ply:GetWeapons(), "PropPlacer")
local rot = tonumber(argStr)
if (weapon and rot) then
return weapon.angles:Add(Angle(rot, 0, 0))
else
return print("Error: No PropPlacer owned or rotation value invalid.")
end
end
concommand.Add("rotateproppitch", _3_)
local function _4_(ply, cmd, args, argStr)
local rot = tonumber(args[1])
if rot then
propplacer.rotatepitch = rot
end
end
concommand.Add("+rotateproppitch", _4_)
local function _5_(ply, cmd, args, argStr)
propplacer.rotatepitch = 0
end
concommand.Add("-rotateproppitch", _5_)
local function _6_(ply, cmd, args, argStr)
local weapon = find_weapon(ply:GetWeapons(), "PropPlacer")
local rot = tonumber(argStr)
if (weapon and rot) then
return weapon.angles:Add(Angle(0, rot, 0))
else
return print("Error: No PropPlacer owned or rotation value invalid.")
end
end
concommand.Add("rotatepropyaw", _6_)
local function _7_(ply, cmd, args, argStr)
local rot = tonumber(args[1])
if rot then
propplacer.rotateyaw = rot
end
end
concommand.Add("+rotatepropyaw", _7_)
local function _8_(ply, cmd, args, argStr)
propplacer.rotateyaw = 0
end
concommand.Add("-rotatepropyaw", _8_)
local function _9_(ply, cmd, args, argStr)
local weapon = find_weapon(ply:GetWeapons(), "PropPlacer")
local rot = tonumber(argStr)
if (weapon and rot) then
return weapon.angles:Add(Angle(0, 0, rot))
else
return print("Error: No PropPlacer owned or rotation value invalid.")
end
end
concommand.Add("rotateproproll", _9_)
local function _10_(ply, cmd, args, argStr)
local rot = tonumber(args[1])
if rot then
propplacer.rotateroll = rot
end
end
concommand.Add("+rotateproproll", _10_)
local function _11_(ply, cmd, args, argStr)
propplacer.rotateroll = 0
return nil
end
concommand.Add("-rotateproproll", _11_)