Compare commits

...

2 Commits

3 changed files with 37 additions and 24 deletions

View File

@ -1,4 +1,4 @@
Copyright (c) 2018 Valentin Anger and other contributours. All rights reserved.
Copyright (c) 2018 Valentin Anger and other contributors. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

View File

@ -29,7 +29,13 @@
(local ShootSound (Sound "garrysmod/balloon_pop_cute.wav"))
(when (and CLIENT (or (not propplacer) (not propplacer.last_model))) ;; Don't remove the references when hot reloading
(global propplacer { :last_model nil :rotateyaw 0 :rotatepitch 0 :rotateroll 0 }))
(global propplacer {
:last_model nil
:rotateyaw 0
:rotatepitch 0
:rotateroll 0
:last_tick 0
}))
(when CLIENT
(set SWEP.model "models/balloons/balloon_dog.mdl")
@ -38,7 +44,8 @@
(defn SWEP.PrimaryAttack [self]
(: self :EmitSound ShootSound)
(when CLIENT
;; NOTE This stops the client (unintentionally) sending several spawn events back to back
(when (and CLIENT (IsFirstTimePredicted))
(: self :Place self.model
(if self.freeze
self.last_pos
@ -51,19 +58,20 @@
(set self.freeze false)))
(defn SWEP.SecondaryAttack [self]
(set self.last_pos (. (: self.Owner :GetEyeTrace) :HitPos))
(set self.last_angles (Angle 0 (. (: self.Owner :EyeAngles) :y) 0))
(set self.freeze (not self.freeze)))
(when (and CLIENT (IsFirstTimePredicted))
(set self.last_pos (. (: self.Owner :GetEyeTrace) :HitPos))
(set self.last_angles (Angle 0 (. (: self.Owner :EyeAngles) :y) 0))
(set self.freeze (not self.freeze))))
(defn SWEP.Holster [self] ;; NOTE Called twice for some reason
(when (and CLIENT propplacer.last_model)
(when (and CLIENT propplacer.last_model (= (: (LocalPlayer) :SteamID64) (: self.Owner :SteamID64)))
(print "Remove shadow model")
(: propplacer.last_model :Remove)
(set propplacer.last_model nil))
true)
(defn SWEP.Deploy [self] ;; TODO Not called by client when given
(when (and CLIENT (not propplacer.last_model))
(when (and CLIENT (not propplacer.last_model) (= (: (LocalPlayer) :SteamID64) (: self.Owner :SteamID64)))
(print "Spawn shadow model " self.model)
(set propplacer.last_model (ClientsideModel self.model RENDERGROUP_TRANSLUCENT))
(when (IsValid propplacer.last_model)
@ -91,7 +99,7 @@
(: propplacer.last_model :SetAngles ang))))))
(defn SWEP.Think [self]
(when (and CLIENT propplacer.last_model)
(when (and CLIENT propplacer.last_model (= (: (LocalPlayer) :SteamID64) (: self.Owner :SteamID64)))
(when (~= propplacer.rotateyaw 0)
(: self.Owner :ConCommand (.. "rotatepropyaw " propplacer.rotateyaw)))
(when (~= propplacer.rotatepitch 0)
@ -100,12 +108,14 @@
(: self.Owner :ConCommand (.. "rotateproproll " propplacer.rotateroll)))))
(defn SWEP.Place [self model_file pos angle]
(when CLIENT
(net.Start "Propplacer.Place")
(net.WriteString model_file)
(net.WriteVector pos)
(net.WriteAngle angle)
(net.SendToServer)))
(when CLIENT ;(> (- (engine.TickCount) propplacer.last_tick) 5))
;; (print (engine.TickCount) propplacer.last_tick (- (engine.TickCount) propplacer.last_tick))
(tset propplacer :last_tick (engine.TickCount))
(net.Start "Propplacer.Place")
(net.WriteString model_file)
(net.WriteVector pos)
(net.WriteAngle angle)
(net.SendToServer)))
(defn find-weapon [table name]
(var retentry nil)

View File

@ -22,7 +22,7 @@ SWEP.WorldModel = "models/weapons/w_slam.mdl"
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, rotatepitch = 0, rotateroll = 0, rotateyaw = 0}
propplacer = {last_model = nil, last_tick = 0, rotatepitch = 0, rotateroll = 0, rotateyaw = 0}
return nil
end
end
@ -38,7 +38,7 @@ end
_1_(...)
SWEP.PrimaryAttack = function(self)
self:EmitSound(ShootSound)
if CLIENT then
if (CLIENT and IsFirstTimePredicted()) then
local function _2_()
if self.freeze then
return self.last_pos
@ -62,15 +62,17 @@ SWEP.PrimaryAttack = function(self)
end
do local _ = SWEP.PrimaryAttack end
SWEP.SecondaryAttack = function(self)
self.last_pos = self.Owner:GetEyeTrace().HitPos
self.last_angles = Angle(0, self.Owner:EyeAngles().y, 0)
self.freeze = not self.freeze
return nil
if (CLIENT and IsFirstTimePredicted()) then
self.last_pos = self.Owner:GetEyeTrace().HitPos
self.last_angles = Angle(0, self.Owner:EyeAngles().y, 0)
self.freeze = not self.freeze
return nil
end
end
do local _ = SWEP.SecondaryAttack end
SWEP.Holster = function(self)
local function _2_()
if (CLIENT and propplacer.last_model) then
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
@ -83,7 +85,7 @@ end
do local _ = SWEP.Holster end
SWEP.Deploy = function(self)
local function _2_()
if (CLIENT and not propplacer.last_model) then
if (CLIENT and not propplacer.last_model and (LocalPlayer():SteamID64() == self.Owner:SteamID64())) then
print("Spawn shadow model ", self.model)
propplacer.last_model = ClientsideModel(self.model, RENDERGROUP_TRANSLUCENT)
if IsValid(propplacer.last_model) then
@ -122,7 +124,7 @@ SWEP.DrawHUD = function(self)
end
do local _ = SWEP.DrawHUD end
SWEP.Think = function(self)
if (CLIENT and propplacer.last_model) then
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))
@ -143,6 +145,7 @@ 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)