From f4a5527a8b3312589e51672f44b55c2a4e902c51 Mon Sep 17 00:00:00 2001 From: Seef0x <47392375+Seef0x@users.noreply.github.com> Date: Tue, 7 Dec 2021 18:29:07 +0100 Subject: [PATCH 01/13] Remove useless loader --- lua/autorun/vikrlaundry_autorun.lua | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 lua/autorun/vikrlaundry_autorun.lua diff --git a/lua/autorun/vikrlaundry_autorun.lua b/lua/autorun/vikrlaundry_autorun.lua deleted file mode 100644 index a47ccb4..0000000 --- a/lua/autorun/vikrlaundry_autorun.lua +++ /dev/null @@ -1,7 +0,0 @@ -if SERVER then - AddCSLuaFile("vikrlaundry_config.lua") - - include("vikrlaundry_config.lua") -elseif CLIENT then - include("vikrlaundry_config.lua") -end From d7dc3f27b5c93c2a3a0ece3a817e0d928947d69d Mon Sep 17 00:00:00 2001 From: Seef0x <47392375+Seef0x@users.noreply.github.com> Date: Tue, 7 Dec 2021 18:31:05 +0100 Subject: [PATCH 02/13] Correct syntax --- lua/entities/clean_laundry_cart/cl_init.lua | 16 +-- lua/entities/clean_laundry_cart/init.lua | 2 +- lua/entities/clean_laundry_cart/shared.lua | 2 +- lua/entities/cloth/cl_init.lua | 4 +- lua/entities/dirty_laundry_cart/cl_init.lua | 16 +-- lua/entities/dirty_laundry_cart/init.lua | 2 +- lua/entities/dirty_laundry_cart/shared.lua | 2 +- lua/entities/washing_machine/cl_init.lua | 41 +++--- lua/entities/washing_machine/init.lua | 130 ++++++++++---------- lua/entities/washing_machine/shared.lua | 2 +- 10 files changed, 109 insertions(+), 108 deletions(-) diff --git a/lua/entities/clean_laundry_cart/cl_init.lua b/lua/entities/clean_laundry_cart/cl_init.lua index 6673bb4..92ce9cf 100644 --- a/lua/entities/clean_laundry_cart/cl_init.lua +++ b/lua/entities/clean_laundry_cart/cl_init.lua @@ -1,14 +1,14 @@ include("shared.lua") function ENT:Draw() - self:DrawModel() + self:DrawModel() - local pos = self:LocalToWorld(self:OBBCenter()) - local ang = self:GetAngles() + local pos = self:LocalToWorld(self:OBBCenter()) + local ang = self:GetAngles() - local phrase = string.gsub(LaundryConfig.PhraseCleanClothes, "", self:GetClothesNumber()) + local phrase = string.gsub(LaundryConfig.PhraseCleanClothes, "", self:GetClothesNumber()) - cam.Start3D2D(pos + (ang:Up() * 5) + (ang:Right() * 21), ang + Angle(0,0,90), 0.25) - draw.SimpleText(tostring(phrase), "DermaLarge", 0, 0, Color(255,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER) - cam.End3D2D() -end + cam.Start3D2D(pos + (ang:Up() * 5) + (ang:Right() * 21), ang + Angle(0,0,90), 0.25) + draw.SimpleText(tostring(phrase), "DermaLarge", 0, 0, Color(255,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER) + cam.End3D2D() +end \ No newline at end of file diff --git a/lua/entities/clean_laundry_cart/init.lua b/lua/entities/clean_laundry_cart/init.lua index ff0289b..8c0d627 100644 --- a/lua/entities/clean_laundry_cart/init.lua +++ b/lua/entities/clean_laundry_cart/init.lua @@ -74,4 +74,4 @@ function ENT:Think() self:NextThink(CurTime() + 0.1) return true -end +end \ No newline at end of file diff --git a/lua/entities/clean_laundry_cart/shared.lua b/lua/entities/clean_laundry_cart/shared.lua index 723ec4e..7f890ba 100644 --- a/lua/entities/clean_laundry_cart/shared.lua +++ b/lua/entities/clean_laundry_cart/shared.lua @@ -10,4 +10,4 @@ ENT.AdminSpawnable = false function ENT:SetupDataTables() self:NetworkVar("Float", 0, "ClothesNumber") -end +end \ No newline at end of file diff --git a/lua/entities/cloth/cl_init.lua b/lua/entities/cloth/cl_init.lua index b2b61eb..428ceb7 100644 --- a/lua/entities/cloth/cl_init.lua +++ b/lua/entities/cloth/cl_init.lua @@ -1,5 +1,5 @@ include("shared.lua") function ENT:Draw() - self:DrawModel() -end + self:DrawModel() +end \ No newline at end of file diff --git a/lua/entities/dirty_laundry_cart/cl_init.lua b/lua/entities/dirty_laundry_cart/cl_init.lua index 9260427..c43e753 100644 --- a/lua/entities/dirty_laundry_cart/cl_init.lua +++ b/lua/entities/dirty_laundry_cart/cl_init.lua @@ -1,14 +1,14 @@ include("shared.lua") function ENT:Draw() - self:DrawModel() + self:DrawModel() - local pos = self:LocalToWorld(self:OBBCenter()) - local ang = self:GetAngles() + local pos = self:LocalToWorld(self:OBBCenter()) + local ang = self:GetAngles() - local phrase = string.gsub(LaundryConfig.PhraseDirtyClothes, "", self:GetClothesNumber()) + local phrase = string.gsub(LaundryConfig.PhraseDirtyClothes, "", self:GetClothesNumber()) - cam.Start3D2D(pos + (ang:Up() * 5) + (ang:Right() * 25), ang + Angle(0, 0, 90), 0.25) - draw.SimpleText(tostring(phrase), "DermaLarge", 0, 0, Color(255, 255, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER) - cam.End3D2D() -end + cam.Start3D2D(pos + (ang:Up() * 5) + (ang:Right() * 25), ang + Angle(0, 0, 90), 0.25) + draw.SimpleText(tostring(phrase), "DermaLarge", 0, 0, Color(255, 255, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER) + cam.End3D2D() +end \ No newline at end of file diff --git a/lua/entities/dirty_laundry_cart/init.lua b/lua/entities/dirty_laundry_cart/init.lua index 4b72e46..e65665a 100644 --- a/lua/entities/dirty_laundry_cart/init.lua +++ b/lua/entities/dirty_laundry_cart/init.lua @@ -62,4 +62,4 @@ function ENT:OnRemove() if timer.Exists("AddClothTimer"..self:EntIndex()) then timer.Remove("AddClothTimer"..self:EntIndex()) end -end +end \ No newline at end of file diff --git a/lua/entities/dirty_laundry_cart/shared.lua b/lua/entities/dirty_laundry_cart/shared.lua index 279f351..dabe2b6 100644 --- a/lua/entities/dirty_laundry_cart/shared.lua +++ b/lua/entities/dirty_laundry_cart/shared.lua @@ -10,4 +10,4 @@ ENT.AdminSpawnable = false function ENT:SetupDataTables() self:NetworkVar("Float", 0, "ClothesNumber") -end +end \ No newline at end of file diff --git a/lua/entities/washing_machine/cl_init.lua b/lua/entities/washing_machine/cl_init.lua index a810118..a9f0955 100644 --- a/lua/entities/washing_machine/cl_init.lua +++ b/lua/entities/washing_machine/cl_init.lua @@ -2,31 +2,32 @@ include("shared.lua") include("autorun/vikrlaundry_config.lua") function ENT:Draw() - self:DrawModel() + self:DrawModel() - local pos = self:LocalToWorld(self:OBBCenter()) - local ang = self:GetAngles() - ang:RotateAroundAxis(ang:Up(), 90) - ang:RotateAroundAxis(ang:Forward(), 90) - local color = Color(255, 0, 0) - local x, y, w, h = 0, 0, 30, 30 + local pos = self:LocalToWorld(self:OBBCenter()) + local ang = self:GetAngles() + ang:RotateAroundAxis(ang:Up(), 90) + ang:RotateAroundAxis(ang:Forward(), 90) + + local color = Color(255, 0, 0) + local x, y, w, h = 0, 0, 30, 30 - if self:GetWashing() then - color = Color(0, 255, 0) - end + if self:GetWashing() then + color = Color(0, 255, 0) + end - cam.Start3D2D(pos + (ang:Up() * 20.75) + (ang:Forward() * 27.5) + (ang:Right() * 12.5), ang, 0.2) - draw.RoundedBox(0, x - w / 2, y - h / 2, w + 2, h + 2, Color(10, 10, 10, 100)) - draw.RoundedBox(0, x - w / 2 + 1, y - h / 2 + 1, w, h, color) - cam.End3D2D() + cam.Start3D2D(pos + (ang:Up() * 20.75) + (ang:Forward() * 27.5) + (ang:Right() * 12.5), ang, 0.2) + draw.RoundedBox(0, x - w / 2, y - h / 2, w + 2, h + 2, Color(10, 10, 10, 100)) + draw.RoundedBox(0, x - w / 2 + 1, y - h / 2 + 1, w, h, color) + cam.End3D2D() end function ENT:Think() - if not self.ClothModel then return end + if not self.ClothModel then return end - self.ClothModel:SetPos(self:LocalToWorld(self:OBBCenter())) + self.ClothModel:SetPos(self:LocalToWorld(self:OBBCenter())) - if not self:GetWashing() then - self.ClothModel:Remove() - end -end + if not self:GetWashing() then + self.ClothModel:Remove() + end +end \ No newline at end of file diff --git a/lua/entities/washing_machine/init.lua b/lua/entities/washing_machine/init.lua index e159a3c..92f1669 100644 --- a/lua/entities/washing_machine/init.lua +++ b/lua/entities/washing_machine/init.lua @@ -4,91 +4,91 @@ AddCSLuaFile("shared.lua") include("shared.lua") function ENT:SpawnFunction(ply, tr, cn) - local ang = ply:GetAngles() - local ent = ents.Create(cn) - ent:SetPos(tr.HitPos + tr.HitNormal + Vector(0, 0, 60)) - ent:SetAngles(Angle(0, ang.y, 0) - Angle(0, 180, 0)) - ent:Spawn() + local ang = ply:GetAngles() + local ent = ents.Create(cn) + ent:SetPos(tr.HitPos + tr.HitNormal + Vector(0, 0, 60)) + ent:SetAngles(Angle(0, ang.y, 0) - Angle(0, 180, 0)) + ent:Spawn() - return ent + return ent end function ENT:Initialize() - self:SetModel("models/props_wasteland/laundry_dryer002.mdl") - self:PhysicsInit(SOLID_VPHYSICS) - self:SetMoveType(MOVETYPE_VPHYSICS) - self:SetSolid(SOLID_VPHYSICS) - - local phys = self:GetPhysicsObject() - if (phys:IsValid()) then - phys:Wake() - end + self:SetModel("models/props_wasteland/laundry_dryer002.mdl") + self:PhysicsInit(SOLID_VPHYSICS) + self:SetMoveType(MOVETYPE_VPHYSICS) + self:SetSolid(SOLID_VPHYSICS) + + local phys = self:GetPhysicsObject() + if (phys:IsValid()) then + phys:Wake() + end end function ENT:Think() - local pos = self:LocalToWorld(self:OBBCenter()) - local ang = self:GetAngles() - ang:RotateAroundAxis(ang:Up(), 90) - ang:RotateAroundAxis(ang:Forward(), 90) + local pos = self:LocalToWorld(self:OBBCenter()) + local ang = self:GetAngles() + ang:RotateAroundAxis(ang:Up(), 90) + ang:RotateAroundAxis(ang:Forward(), 90) - for _, ent in pairs(ents.FindInSphere(pos + (ang:Up() * 20) - (ang:Right() * 9), 20)) do - if ent:GetClass() == "cloth" and not self:GetWashing() then - if not ent:GetClean() then - self:SetClothType(ent:GetClothType()) - self:SetWashing(true) - self:SetWashState(LaundryConfig.WashTime) - ent:Remove() - end + for _, ent in pairs(ents.FindInSphere(pos + (ang:Up() * 20) - (ang:Right() * 9), 20)) do + if ent:GetClass() == "cloth" and not self:GetWashing() then + if not ent:GetClean() then + self:SetClothType(ent:GetClothType()) + self:SetWashing(true) + self:SetWashState(LaundryConfig.WashTime) + ent:Remove() + end + end end - end - self:NextThink(CurTime()) - return true + self:NextThink(CurTime()) + return true end function ENT:OnWash(ent, name, ov, nv) - if timer.Exists("WashTimer" .. self:EntIndex()) then return end + if timer.Exists("WashTimer" .. self:EntIndex()) then return end - timer.Create("WashTimer" .. self:EntIndex(), 1, LaundryConfig.WashTime, function() - self:SetWashState(self:GetWashState() - 1) + timer.Create("WashTimer" .. self:EntIndex(), 1, LaundryConfig.WashTime, function() + self:SetWashState(self:GetWashState() - 1) - timer.Simple(1, function() - if self:IsValid() then - self:EmitSound("plats/elevator_stop1.wav") - end - end) + timer.Simple(1, function() + if self:IsValid() then + self:EmitSound("plats/elevator_stop1.wav") + end + end) - if self:GetWashState() == 0 then - self:SetWashing(false) - timer.Remove("WashTimer"..self:EntIndex()) + if self:GetWashState() == 0 then + self:SetWashing(false) + timer.Remove("WashTimer"..self:EntIndex()) - local pos = self:LocalToWorld(self:OBBCenter()) - local ang = self:GetAngles() + local pos = self:LocalToWorld(self:OBBCenter()) + local ang = self:GetAngles() - ang:RotateAroundAxis(ang:Up(), 90) - ang:RotateAroundAxis(ang:Forward(), 90) + ang:RotateAroundAxis(ang:Up(), 90) + ang:RotateAroundAxis(ang:Forward(), 90) - local cloth = ents.Create("cloth") - if not cloth:IsValid() then return end - cloth:SetPos(pos + (ang:Up() * 25)) - cloth:SetAngles(self:GetAngles()) - cloth:SetClothType(self:GetClothType()) - cloth:SetClean(true) - cloth:Spawn() + local cloth = ents.Create("cloth") + if not cloth:IsValid() then return end + cloth:SetPos(pos + (ang:Up() * 25)) + cloth:SetAngles(self:GetAngles()) + cloth:SetClothType(self:GetClothType()) + cloth:SetClean(true) + cloth:Spawn() - self:EmitSound("plats/elevbell1.wav") - else - self:EmitSound("plats/elevator_start1.wav", SNDLVL_60Db) - self:EmitSound("plats/elevator_move_loop2.wav", SNDLVL_60Db) - end - end) + self:EmitSound("plats/elevbell1.wav") + else + self:EmitSound("plats/elevator_start1.wav", SNDLVL_60Db) + self:EmitSound("plats/elevator_move_loop2.wav", SNDLVL_60Db) + end + end) end function ENT:OnRemove() - if timer.Exists("WashTimer" .. self:EntIndex()) then - timer.Remove("WashTimer" .. self:EntIndex()) - end - if timer.Exists("WashSoundTimer" .. self:EntIndex()) then - timer.Remove("WashSoundTimer" .. self:EntIndex()) - end -end + if timer.Exists("WashTimer" .. self:EntIndex()) then + timer.Remove("WashTimer" .. self:EntIndex()) + end + if timer.Exists("WashSoundTimer" .. self:EntIndex()) then + timer.Remove("WashSoundTimer" .. self:EntIndex()) + end +end \ No newline at end of file diff --git a/lua/entities/washing_machine/shared.lua b/lua/entities/washing_machine/shared.lua index 5f6e3ca..240478c 100644 --- a/lua/entities/washing_machine/shared.lua +++ b/lua/entities/washing_machine/shared.lua @@ -16,4 +16,4 @@ function ENT:SetupDataTables() if SERVER then self:NetworkVarNotify("Washing", self.OnWash) end -end +end \ No newline at end of file From 6ff3bc037ba67c44fb244712f14cbb7916be915c Mon Sep 17 00:00:00 2001 From: Seef0x <47392375+Seef0x@users.noreply.github.com> Date: Tue, 7 Dec 2021 18:48:28 +0100 Subject: [PATCH 03/13] Remove useless spawn functions --- lua/entities/clean_laundry_cart/init.lua | 10 ---------- lua/entities/dirty_laundry_cart/init.lua | 10 ---------- lua/entities/washing_machine/init.lua | 10 ---------- 3 files changed, 30 deletions(-) diff --git a/lua/entities/clean_laundry_cart/init.lua b/lua/entities/clean_laundry_cart/init.lua index 8c0d627..d257780 100644 --- a/lua/entities/clean_laundry_cart/init.lua +++ b/lua/entities/clean_laundry_cart/init.lua @@ -3,16 +3,6 @@ AddCSLuaFile("shared.lua") include("shared.lua") -function ENT:SpawnFunction(ply, tr, cn) - local ang = ply:GetAngles() - local ent = ents.Create(cn) - ent:SetPos(tr.HitPos + tr.HitNormal + Vector(0,0,60)) - ent:SetAngles(Angle(0, ang.y, 0) - Angle(0, 90, 0)) - ent:Spawn() - - return ent -end - function ENT:Initialize() self:SetModel("models/props_wasteland/laundry_cart001.mdl") self:PhysicsInit(SOLID_VPHYSICS) diff --git a/lua/entities/dirty_laundry_cart/init.lua b/lua/entities/dirty_laundry_cart/init.lua index e65665a..e2533b8 100644 --- a/lua/entities/dirty_laundry_cart/init.lua +++ b/lua/entities/dirty_laundry_cart/init.lua @@ -3,16 +3,6 @@ AddCSLuaFile("shared.lua") include("shared.lua") -function ENT:SpawnFunction(ply, tr, cn) - local ang = ply:GetAngles() - local ent = ents.Create(cn) - ent:SetPos(tr.HitPos + tr.HitNormal + Vector(0,0,40)) - ent:SetAngles(Angle(0, ang.y, 0) - Angle(0, 90, 0)) - ent:Spawn() - - return ent -end - function ENT:Initialize() self:SetModel("models/props_wasteland/laundry_basket001.mdl") self:PhysicsInit(SOLID_VPHYSICS) diff --git a/lua/entities/washing_machine/init.lua b/lua/entities/washing_machine/init.lua index 92f1669..cb307ee 100644 --- a/lua/entities/washing_machine/init.lua +++ b/lua/entities/washing_machine/init.lua @@ -3,16 +3,6 @@ AddCSLuaFile("shared.lua") include("shared.lua") -function ENT:SpawnFunction(ply, tr, cn) - local ang = ply:GetAngles() - local ent = ents.Create(cn) - ent:SetPos(tr.HitPos + tr.HitNormal + Vector(0, 0, 60)) - ent:SetAngles(Angle(0, ang.y, 0) - Angle(0, 180, 0)) - ent:Spawn() - - return ent -end - function ENT:Initialize() self:SetModel("models/props_wasteland/laundry_dryer002.mdl") self:PhysicsInit(SOLID_VPHYSICS) From cb34e20b4edf1310b32babaa7802660281c10faf Mon Sep 17 00:00:00 2001 From: Seef0x <47392375+Seef0x@users.noreply.github.com> Date: Tue, 7 Dec 2021 18:54:40 +0100 Subject: [PATCH 04/13] Optimization by using StartTouch function --- lua/entities/washing_machine/init.lua | 28 ++++++++------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/lua/entities/washing_machine/init.lua b/lua/entities/washing_machine/init.lua index cb307ee..619d4ce 100644 --- a/lua/entities/washing_machine/init.lua +++ b/lua/entities/washing_machine/init.lua @@ -1,6 +1,6 @@ AddCSLuaFile("cl_init.lua") AddCSLuaFile("shared.lua") - + include("shared.lua") function ENT:Initialize() @@ -8,32 +8,20 @@ function ENT:Initialize() self:PhysicsInit(SOLID_VPHYSICS) self:SetMoveType(MOVETYPE_VPHYSICS) self:SetSolid(SOLID_VPHYSICS) - + local phys = self:GetPhysicsObject() if (phys:IsValid()) then phys:Wake() end end -function ENT:Think() - local pos = self:LocalToWorld(self:OBBCenter()) - local ang = self:GetAngles() - ang:RotateAroundAxis(ang:Up(), 90) - ang:RotateAroundAxis(ang:Forward(), 90) - - for _, ent in pairs(ents.FindInSphere(pos + (ang:Up() * 20) - (ang:Right() * 9), 20)) do - if ent:GetClass() == "cloth" and not self:GetWashing() then - if not ent:GetClean() then - self:SetClothType(ent:GetClothType()) - self:SetWashing(true) - self:SetWashState(LaundryConfig.WashTime) - ent:Remove() - end - end +function ENT:StartTouch(ent) + if not self:GetWashing() and ent:GetClass() == "cloth" and not ent:GetClean() then + self:SetClothType(ent:GetClothType()) + self:SetWashing(true) + self:SetWashState(LaundryConfig.WashTime) + ent:Remove() end - - self:NextThink(CurTime()) - return true end function ENT:OnWash(ent, name, ov, nv) From e2538f9fafaf197a31284a496ca631b76fcd4e31 Mon Sep 17 00:00:00 2001 From: Seef0x <47392375+Seef0x@users.noreply.github.com> Date: Tue, 7 Dec 2021 18:55:59 +0100 Subject: [PATCH 05/13] Replace useless float by int --- lua/entities/clean_laundry_cart/shared.lua | 2 +- lua/entities/cloth/shared.lua | 2 +- lua/entities/dirty_laundry_cart/shared.lua | 2 +- lua/entities/washing_machine/shared.lua | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lua/entities/clean_laundry_cart/shared.lua b/lua/entities/clean_laundry_cart/shared.lua index 7f890ba..c70b17a 100644 --- a/lua/entities/clean_laundry_cart/shared.lua +++ b/lua/entities/clean_laundry_cart/shared.lua @@ -9,5 +9,5 @@ ENT.Spawnable = true ENT.AdminSpawnable = false function ENT:SetupDataTables() - self:NetworkVar("Float", 0, "ClothesNumber") + self:NetworkVar("Int", 0, "ClothesNumber") end \ No newline at end of file diff --git a/lua/entities/cloth/shared.lua b/lua/entities/cloth/shared.lua index 26abbcb..6380981 100644 --- a/lua/entities/cloth/shared.lua +++ b/lua/entities/cloth/shared.lua @@ -10,7 +10,7 @@ ENT.AdminSpawnable = false function ENT:SetupDataTables() self:NetworkVar("Bool", 0, "Clean") - self:NetworkVar("Float", 1, "ClothType") -- 1 = prisonnier, 2 = garde + self:NetworkVar("Int", 1, "ClothType") -- 1 = prisonnier, 2 = garde if SERVER then self:NetworkVarNotify("Clean", self.OnClothChangeState) diff --git a/lua/entities/dirty_laundry_cart/shared.lua b/lua/entities/dirty_laundry_cart/shared.lua index dabe2b6..6ae7d6c 100644 --- a/lua/entities/dirty_laundry_cart/shared.lua +++ b/lua/entities/dirty_laundry_cart/shared.lua @@ -9,5 +9,5 @@ ENT.Spawnable = true ENT.AdminSpawnable = false function ENT:SetupDataTables() - self:NetworkVar("Float", 0, "ClothesNumber") + self:NetworkVar("Int", 0, "ClothesNumber") end \ No newline at end of file diff --git a/lua/entities/washing_machine/shared.lua b/lua/entities/washing_machine/shared.lua index 240478c..72e7dc1 100644 --- a/lua/entities/washing_machine/shared.lua +++ b/lua/entities/washing_machine/shared.lua @@ -9,8 +9,8 @@ ENT.Spawnable = true ENT.AdminSpawnable = false function ENT:SetupDataTables() - self:NetworkVar("Float", 0, "WashState") - self:NetworkVar("Float", 1, "ClothType") + self:NetworkVar("Int", 0, "WashState") + self:NetworkVar("Int", 1, "ClothType") self:NetworkVar("Bool", 2, "Washing") if SERVER then From ec7109e51fa8873aa77cd6a132848e541a3151fd Mon Sep 17 00:00:00 2001 From: Seef0x <47392375+Seef0x@users.noreply.github.com> Date: Tue, 7 Dec 2021 18:59:46 +0100 Subject: [PATCH 06/13] Optimization of Cam3D2D --- lua/entities/clean_laundry_cart/cl_init.lua | 9 ++++----- lua/entities/dirty_laundry_cart/cl_init.lua | 9 ++++----- lua/entities/washing_machine/cl_init.lua | 17 +++++++---------- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/lua/entities/clean_laundry_cart/cl_init.lua b/lua/entities/clean_laundry_cart/cl_init.lua index 92ce9cf..6a4f2ad 100644 --- a/lua/entities/clean_laundry_cart/cl_init.lua +++ b/lua/entities/clean_laundry_cart/cl_init.lua @@ -1,14 +1,13 @@ include("shared.lua") +local colWhite = Color(255, 255, 255) + function ENT:Draw() self:DrawModel() - local pos = self:LocalToWorld(self:OBBCenter()) local ang = self:GetAngles() - local phrase = string.gsub(LaundryConfig.PhraseCleanClothes, "", self:GetClothesNumber()) - - cam.Start3D2D(pos + (ang:Up() * 5) + (ang:Right() * 21), ang + Angle(0,0,90), 0.25) - draw.SimpleText(tostring(phrase), "DermaLarge", 0, 0, Color(255,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER) + cam.Start3D2D(self:LocalToWorld(self:OBBCenter()) + (ang:Up() * 5) + (ang:Right() * 21), ang + Angle(0, 0, 90), 0.25) + draw.SimpleText(string.format(LaundryConfig.PhraseCleanClothes, self:GetClothesNumber()), "DermaLarge", 0, 0, colWhite, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER) cam.End3D2D() end \ No newline at end of file diff --git a/lua/entities/dirty_laundry_cart/cl_init.lua b/lua/entities/dirty_laundry_cart/cl_init.lua index c43e753..d4d20f4 100644 --- a/lua/entities/dirty_laundry_cart/cl_init.lua +++ b/lua/entities/dirty_laundry_cart/cl_init.lua @@ -1,14 +1,13 @@ include("shared.lua") +local colWhite = Color(255, 255, 255) + function ENT:Draw() self:DrawModel() - local pos = self:LocalToWorld(self:OBBCenter()) local ang = self:GetAngles() - local phrase = string.gsub(LaundryConfig.PhraseDirtyClothes, "", self:GetClothesNumber()) - - cam.Start3D2D(pos + (ang:Up() * 5) + (ang:Right() * 25), ang + Angle(0, 0, 90), 0.25) - draw.SimpleText(tostring(phrase), "DermaLarge", 0, 0, Color(255, 255, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER) + cam.Start3D2D(self:LocalToWorld(self:OBBCenter()) + (ang:Up() * 5) + (ang:Right() * 25), ang + Angle(0, 0, 90), 0.25) + draw.SimpleText(string.format(LaundryConfig.PhraseDirtyClothes, self:GetClothesNumber()), "DermaLarge", 0, 0, colWhite, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER) cam.End3D2D() end \ No newline at end of file diff --git a/lua/entities/washing_machine/cl_init.lua b/lua/entities/washing_machine/cl_init.lua index a9f0955..472642a 100644 --- a/lua/entities/washing_machine/cl_init.lua +++ b/lua/entities/washing_machine/cl_init.lua @@ -1,24 +1,21 @@ include("shared.lua") -include("autorun/vikrlaundry_config.lua") + +local colBlack = Color(10, 10, 10, 100) +local colRed = Color(255, 0, 0) +local colGreen = Color(0, 255, 0) function ENT:Draw() self:DrawModel() - local pos = self:LocalToWorld(self:OBBCenter()) local ang = self:GetAngles() ang:RotateAroundAxis(ang:Up(), 90) ang:RotateAroundAxis(ang:Forward(), 90) - local color = Color(255, 0, 0) local x, y, w, h = 0, 0, 30, 30 - if self:GetWashing() then - color = Color(0, 255, 0) - end - - cam.Start3D2D(pos + (ang:Up() * 20.75) + (ang:Forward() * 27.5) + (ang:Right() * 12.5), ang, 0.2) - draw.RoundedBox(0, x - w / 2, y - h / 2, w + 2, h + 2, Color(10, 10, 10, 100)) - draw.RoundedBox(0, x - w / 2 + 1, y - h / 2 + 1, w, h, color) + cam.Start3D2D(self:LocalToWorld(self:OBBCenter()) + (ang:Up() * 20.75) + (ang:Forward() * 27.5) + (ang:Right() * 12.5), ang, 0.2) + draw.RoundedBox(0, x - w / 2, y - h / 2, w + 2, h + 2, colBlack) + draw.RoundedBox(0, x - w / 2 + 1, y - h / 2 + 1, w, h, self:GetWashing() and colGreen or colRed) cam.End3D2D() end From ba8d37ac3febd8bc3157151fca94d43d59571a7b Mon Sep 17 00:00:00 2001 From: Seef0x <47392375+Seef0x@users.noreply.github.com> Date: Tue, 7 Dec 2021 18:59:57 +0100 Subject: [PATCH 07/13] Remove useless think function --- lua/entities/washing_machine/cl_init.lua | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/lua/entities/washing_machine/cl_init.lua b/lua/entities/washing_machine/cl_init.lua index 472642a..2bf39d8 100644 --- a/lua/entities/washing_machine/cl_init.lua +++ b/lua/entities/washing_machine/cl_init.lua @@ -17,14 +17,4 @@ function ENT:Draw() draw.RoundedBox(0, x - w / 2, y - h / 2, w + 2, h + 2, colBlack) draw.RoundedBox(0, x - w / 2 + 1, y - h / 2 + 1, w, h, self:GetWashing() and colGreen or colRed) cam.End3D2D() -end - -function ENT:Think() - if not self.ClothModel then return end - - self.ClothModel:SetPos(self:LocalToWorld(self:OBBCenter())) - - if not self:GetWashing() then - self.ClothModel:Remove() - end end \ No newline at end of file From 5d46a2d89fbeb010f27169f0bba8ad6a1338f2cb Mon Sep 17 00:00:00 2001 From: Seef0x <47392375+Seef0x@users.noreply.github.com> Date: Tue, 7 Dec 2021 19:02:49 +0100 Subject: [PATCH 08/13] Optimization of think function --- lua/autorun/vikrlaundry_config.lua | 8 ++--- lua/entities/clean_laundry_cart/init.lua | 42 ++++++++---------------- 2 files changed, 17 insertions(+), 33 deletions(-) diff --git a/lua/autorun/vikrlaundry_config.lua b/lua/autorun/vikrlaundry_config.lua index c6b856c..6201885 100644 --- a/lua/autorun/vikrlaundry_config.lua +++ b/lua/autorun/vikrlaundry_config.lua @@ -13,13 +13,13 @@ LaundryConfig.DirtyCartMaxCloth = 20 LaundryConfig.MoneyPerCloth = 10 -- = How many clean clothes are in the cart (default: " clean clothes") -LaundryConfig.PhraseCleanClothes = " clean clothes" +LaundryConfig.PhraseCleanClothes = "%d clean clothes" -- Example : If there is 6 clean clothes, "Clean clothes : " will show "Clean clothes : 6" -- = How many dirty clothes are in the cart (default: " dirty clothes") -LaundryConfig.PhraseDirtyClothes = " dirty clothes" +LaundryConfig.PhraseDirtyClothes = "%d dirty clothes" -- Example : If there is 9 dirty clothes, "Clean clothes : " will show "Dirty clothes : 9" -- = Money received, = clothes washed (default: "You received for washing clothes") -LaundryConfig.PhraseNotifyText = "You received for washing clothes" --- Example : "You got for clothes" will show "You got 60$ for 6 clothes" +LaundryConfig.PhraseNotifyText = "You received %s for washing %d clothes" +-- Example : "You got for clothes" will show "You got 60$ for 6 clothes" \ No newline at end of file diff --git a/lua/entities/clean_laundry_cart/init.lua b/lua/entities/clean_laundry_cart/init.lua index d257780..4c5ab04 100644 --- a/lua/entities/clean_laundry_cart/init.lua +++ b/lua/entities/clean_laundry_cart/init.lua @@ -11,23 +11,22 @@ function ENT:Initialize() self:SetUseType(SIMPLE_USE) - local phys = self:GetPhysicsObject() + local phys = self:GetPhysicsObject() if (phys:IsValid()) then phys:Wake() end end function ENT:Use(act, cal) - if not self.ClothTable then return end - if not (#self.ClothTable > 0) then return end - if not cal:IsValid() then return end + local numCloth = #self.ClothTable - cal:addMoney(#self.ClothTable * LaundryConfig.MoneyPerCloth) + if not self.ClothTable or numCloth < 1 or not cal:IsValid() then return end - local phrase = string.gsub(LaundryConfig.PhraseNotifyText, "", tostring(#self.ClothTable)) - phrase = string.gsub(phrase, "", tostring(#self.ClothTable * LaundryConfig.MoneyPerCloth) .. GAMEMODE.Config.currency) + local reward = numCloth * LaundryConfig.MoneyPerCloth - DarkRP.notify(cal, 0, 7, phrase) + cal:addMoney(reward) + + DarkRP.notify(cal, 0, 7, string.format(LaundryConfig.PhraseNotifyText, DarkRP.formatMoney(reward), numCloth)) for _, ent in pairs(self.ClothTable) do ent:Remove() @@ -35,33 +34,18 @@ function ENT:Use(act, cal) end function ENT:Think() - local pos = self:LocalToWorld(self:OBBCenter()) local ang = self:GetAngles() - local entnum = 0 - self.ClothTable = { } - for _, ent in pairs(ents.FindInSphere(pos + (ang:Forward() * 20), 20)) do - if ent:GetClass() == "cloth" and not table.HasValue(self.ClothTable, ent) then - if ent:GetClean() then - table.insert(self.ClothTable, ent) - end - end - end + self.ClothTable = {} - for _, ent in pairs(ents.FindInSphere(pos - (ang:Forward() * 20), 20)) do - if ent:GetClass() == "cloth" then - if ent:GetClean() and not table.HasValue(self.ClothTable, ent) then - table.insert(self.ClothTable, ent) - end + for _, ent in pairs(ents.FindInSphere(self:LocalToWorld(self:OBBCenter()) + (ang:Forward() * 20), 20)) do + if ent:GetClass() == "cloth" and ent:GetClean() and not table.HasValue(self.ClothTable, ent) then + table.insert(self.ClothTable, ent) end end - for _, ent in pairs(self.ClothTable) do - entnum = entnum + 1 - end - - self:SetClothesNumber(entnum) + self:SetClothesNumber(#self.ClothTable) - self:NextThink(CurTime() + 0.1) + self:NextThink(CurTime() + 1) return true end \ No newline at end of file From 70998d220e559d18316b1478474a414738585507 Mon Sep 17 00:00:00 2001 From: Seef0x <47392375+Seef0x@users.noreply.github.com> Date: Tue, 7 Dec 2021 19:03:47 +0100 Subject: [PATCH 09/13] Optimization of init functions --- lua/entities/cloth/init.lua | 26 +++++++----------------- lua/entities/dirty_laundry_cart/init.lua | 11 +--------- 2 files changed, 8 insertions(+), 29 deletions(-) diff --git a/lua/entities/cloth/init.lua b/lua/entities/cloth/init.lua index 55c8fef..ee3c839 100644 --- a/lua/entities/cloth/init.lua +++ b/lua/entities/cloth/init.lua @@ -6,32 +6,20 @@ include("shared.lua") function ENT:SpawnFunction(ply, tr, cn) local ent = ents.Create(cn) ent:SetPos(tr.HitPos + tr.HitNormal) - if math.random(1, 4) == 4 then - ent:SetClothType(2) - else - ent:SetClothType(1) - end + ent:SetClothType(math.random(1, 4) == 4 and 2 or 1) ent:SetClean(false) ent:Spawn() return ent end +local colOrange = Color(255,125,0) +local colBlue = Color(0,50,255) + function ENT:Initialize() self:SetModel("models/props_junk/garbage_newspaper001a.mdl") - - if not self:GetClean() then - self:SetMaterial("models/props_pipes/GutterMetal01a") - else - self:SetMaterial("models/debug/debugwhite") - end - - if self:GetClothType() == 1 then - self:SetColor(Color(255,125,0)) - elseif self:GetClothType() == 2 then - self:SetColor(Color(0,50,255)) - end - + self:SetMaterial(self:GetClean() and "models/debug/debugwhite" or "models/props_pipes/GutterMetal01a") + self:SetColor(self:GetClothType() == 1 and colOrange or colBlue) self:PhysicsInit(SOLID_VPHYSICS) self:SetMoveType(MOVETYPE_VPHYSICS) self:SetSolid(SOLID_VPHYSICS) @@ -40,4 +28,4 @@ function ENT:Initialize() if (phys:IsValid()) then phys:Wake() end -end +end \ No newline at end of file diff --git a/lua/entities/dirty_laundry_cart/init.lua b/lua/entities/dirty_laundry_cart/init.lua index e2533b8..806dc93 100644 --- a/lua/entities/dirty_laundry_cart/init.lua +++ b/lua/entities/dirty_laundry_cart/init.lua @@ -32,22 +32,13 @@ function ENT:Use(act, cal) if not cloth:IsValid() then return end cloth:SetPos(pos + (ang:Up() * 30)) cloth:SetAngles(self:GetAngles()) - if math.random(1, 4) == 4 then - cloth:SetClothType(2) - else - cloth:SetClothType(1) - end + cloth:SetClothType(math.random(1, 4) == 4 and 2 or 1) cloth:SetClean(false) cloth:Spawn() self:SetClothesNumber(self:GetClothesNumber() - 1) end -function ENT:Think() - self:NextThink(CurTime()) - return true -end - function ENT:OnRemove() if timer.Exists("AddClothTimer"..self:EntIndex()) then timer.Remove("AddClothTimer"..self:EntIndex()) From ebc3c09e2a86c8903d91d64261c733ce0d0cacdf Mon Sep 17 00:00:00 2001 From: Seef0x <47392375+Seef0x@users.noreply.github.com> Date: Tue, 7 Dec 2021 19:16:16 +0100 Subject: [PATCH 10/13] Correct tab --- lua/entities/cloth/shared.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/entities/cloth/shared.lua b/lua/entities/cloth/shared.lua index 6380981..3eed049 100644 --- a/lua/entities/cloth/shared.lua +++ b/lua/entities/cloth/shared.lua @@ -15,4 +15,4 @@ function ENT:SetupDataTables() if SERVER then self:NetworkVarNotify("Clean", self.OnClothChangeState) end -end +end \ No newline at end of file From c12064e319e0ef512762217dde8edf12f9ec5fde Mon Sep 17 00:00:00 2001 From: Seef0x <47392375+Seef0x@users.noreply.github.com> Date: Tue, 7 Dec 2021 19:42:00 +0100 Subject: [PATCH 11/13] Added configuration for white/blacklist teams --- .gitignore | 2 ++ lua/autorun/vikrlaundry_config.lua | 15 ++++++++++++++- lua/entities/clean_laundry_cart/init.lua | 7 ++++++- lua/entities/dirty_laundry_cart/init.lua | 5 +++++ 4 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f3a5a81 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ + +idée.txt diff --git a/lua/autorun/vikrlaundry_config.lua b/lua/autorun/vikrlaundry_config.lua index 6201885..49a456a 100644 --- a/lua/autorun/vikrlaundry_config.lua +++ b/lua/autorun/vikrlaundry_config.lua @@ -22,4 +22,17 @@ LaundryConfig.PhraseDirtyClothes = "%d dirty clothes" -- = Money received, = clothes washed (default: "You received for washing clothes") LaundryConfig.PhraseNotifyText = "You received %s for washing %d clothes" --- Example : "You got for clothes" will show "You got 60$ for 6 clothes" \ No newline at end of file +-- Example : "You got for clothes" will show "You got 60$ for 6 clothes" + +LaundryConfig.PhraseCantInteract = "You cannot interact with this" + +-- true = Blacklist teams, false = Whitelist teams (default: true) +LaundryConfig.BlackOrWhiteList = true +-- Example : If the value is true, all teams in the configuration below will be blacklisted of the addon + +-- Name of white/blacklisted teams +LaundryConfig.Teams = { + ["Guard"] = true, + ["Chief Guard"] = true, + ["Director"] = true +} \ No newline at end of file diff --git a/lua/entities/clean_laundry_cart/init.lua b/lua/entities/clean_laundry_cart/init.lua index 4c5ab04..f864a21 100644 --- a/lua/entities/clean_laundry_cart/init.lua +++ b/lua/entities/clean_laundry_cart/init.lua @@ -20,7 +20,12 @@ end function ENT:Use(act, cal) local numCloth = #self.ClothTable - if not self.ClothTable or numCloth < 1 or not cal:IsValid() then return end + if not self.ClothTable or numCloth < 1 then return end + + if (LaundryConfig.BlackOrWhiteList and LaundryConfig.Teams[team.GetName(cal:Team())]) or (not LaundryConfig.BlackOrWhiteList and not LaundryConfig.Teams[team.GetName(cal:Team())]) then + DarkRP.notify(cal, 1, 5, LaundryConfig.PhraseCantInteract) + return + end local reward = numCloth * LaundryConfig.MoneyPerCloth diff --git a/lua/entities/dirty_laundry_cart/init.lua b/lua/entities/dirty_laundry_cart/init.lua index 806dc93..dc2de4f 100644 --- a/lua/entities/dirty_laundry_cart/init.lua +++ b/lua/entities/dirty_laundry_cart/init.lua @@ -23,6 +23,11 @@ function ENT:Initialize() end function ENT:Use(act, cal) + if (LaundryConfig.BlackOrWhiteList and LaundryConfig.Teams[team.GetName(cal:Team())]) or (not LaundryConfig.BlackOrWhiteList and not LaundryConfig.Teams[team.GetName(cal:Team())]) then + DarkRP.notify(cal, 1, 5, LaundryConfig.PhraseCantInteract) + return + end + if self:GetClothesNumber() <= 0 then return end local pos = self:LocalToWorld(self:OBBCenter()) From 17c261cae87261d6b682b87f8712699a12a7a0d2 Mon Sep 17 00:00:00 2001 From: Seef0x <47392375+Seef0x@users.noreply.github.com> Date: Mon, 28 Mar 2022 23:18:58 +0200 Subject: [PATCH 12/13] Fix an issue --- lua/entities/clean_laundry_cart/init.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lua/entities/clean_laundry_cart/init.lua b/lua/entities/clean_laundry_cart/init.lua index f864a21..56f9fbe 100644 --- a/lua/entities/clean_laundry_cart/init.lua +++ b/lua/entities/clean_laundry_cart/init.lua @@ -33,17 +33,17 @@ function ENT:Use(act, cal) DarkRP.notify(cal, 0, 7, string.format(LaundryConfig.PhraseNotifyText, DarkRP.formatMoney(reward), numCloth)) - for _, ent in pairs(self.ClothTable) do + for index, ent in pairs(self.ClothTable) do + self.ClothTable[index] = nil ent:Remove() end end function ENT:Think() - local ang = self:GetAngles() - self.ClothTable = {} + local x, y = self:GetModelBounds() - for _, ent in pairs(ents.FindInSphere(self:LocalToWorld(self:OBBCenter()) + (ang:Forward() * 20), 20)) do + for _, ent in pairs(ents.FindInBox(self:LocalToWorld(x + Vector(10, 0, 10)), self:LocalToWorld(y - Vector(10, 0, 0)))) do if ent:GetClass() == "cloth" and ent:GetClean() and not table.HasValue(self.ClothTable, ent) then table.insert(self.ClothTable, ent) end From 976068c8297140afab9bf0d5e8e34f8ecc018b12 Mon Sep 17 00:00:00 2001 From: Seef0x <47392375+Seef0x@users.noreply.github.com> Date: Mon, 28 Mar 2022 23:20:08 +0200 Subject: [PATCH 13/13] Optimized draw functions --- lua/entities/clean_laundry_cart/cl_init.lua | 5 ++++- lua/entities/dirty_laundry_cart/cl_init.lua | 5 ++++- lua/entities/washing_machine/cl_init.lua | 6 ++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lua/entities/clean_laundry_cart/cl_init.lua b/lua/entities/clean_laundry_cart/cl_init.lua index 6a4f2ad..7105135 100644 --- a/lua/entities/clean_laundry_cart/cl_init.lua +++ b/lua/entities/clean_laundry_cart/cl_init.lua @@ -1,13 +1,16 @@ include("shared.lua") local colWhite = Color(255, 255, 255) +local superAngle = Angle(0, 0, 90) function ENT:Draw() self:DrawModel() + if self:GetPos():DistToSqr(LocalPlayer():GetPos()) > 500 ^ 2 then return end + local ang = self:GetAngles() - cam.Start3D2D(self:LocalToWorld(self:OBBCenter()) + (ang:Up() * 5) + (ang:Right() * 21), ang + Angle(0, 0, 90), 0.25) + cam.Start3D2D(self:LocalToWorld(self:OBBCenter()) + (ang:Up() * 5) + (ang:Right() * 21), ang + superAngle, 0.25) draw.SimpleText(string.format(LaundryConfig.PhraseCleanClothes, self:GetClothesNumber()), "DermaLarge", 0, 0, colWhite, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER) cam.End3D2D() end \ No newline at end of file diff --git a/lua/entities/dirty_laundry_cart/cl_init.lua b/lua/entities/dirty_laundry_cart/cl_init.lua index d4d20f4..fb03817 100644 --- a/lua/entities/dirty_laundry_cart/cl_init.lua +++ b/lua/entities/dirty_laundry_cart/cl_init.lua @@ -1,13 +1,16 @@ include("shared.lua") local colWhite = Color(255, 255, 255) +local superAngle = Angle(0, 0, 90) function ENT:Draw() self:DrawModel() + if self:GetPos():DistToSqr(LocalPlayer():GetPos()) > 500 ^ 2 then return end + local ang = self:GetAngles() - cam.Start3D2D(self:LocalToWorld(self:OBBCenter()) + (ang:Up() * 5) + (ang:Right() * 25), ang + Angle(0, 0, 90), 0.25) + cam.Start3D2D(self:LocalToWorld(self:OBBCenter()) + (ang:Up() * 5) + (ang:Right() * 25), ang + superAngle, 0.25) draw.SimpleText(string.format(LaundryConfig.PhraseDirtyClothes, self:GetClothesNumber()), "DermaLarge", 0, 0, colWhite, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER) cam.End3D2D() end \ No newline at end of file diff --git a/lua/entities/washing_machine/cl_init.lua b/lua/entities/washing_machine/cl_init.lua index 2bf39d8..9977ef0 100644 --- a/lua/entities/washing_machine/cl_init.lua +++ b/lua/entities/washing_machine/cl_init.lua @@ -4,15 +4,17 @@ local colBlack = Color(10, 10, 10, 100) local colRed = Color(255, 0, 0) local colGreen = Color(0, 255, 0) +local x, y, w, h = 0, 0, 30, 30 + function ENT:Draw() self:DrawModel() + if self:GetPos():DistToSqr(LocalPlayer():GetPos()) > 500 ^ 2 then return end + local ang = self:GetAngles() ang:RotateAroundAxis(ang:Up(), 90) ang:RotateAroundAxis(ang:Forward(), 90) - local x, y, w, h = 0, 0, 30, 30 - cam.Start3D2D(self:LocalToWorld(self:OBBCenter()) + (ang:Up() * 20.75) + (ang:Forward() * 27.5) + (ang:Right() * 12.5), ang, 0.2) draw.RoundedBox(0, x - w / 2, y - h / 2, w + 2, h + 2, colBlack) draw.RoundedBox(0, x - w / 2 + 1, y - h / 2 + 1, w, h, self:GetWashing() and colGreen or colRed)