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_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 diff --git a/lua/autorun/vikrlaundry_config.lua b/lua/autorun/vikrlaundry_config.lua index c6b856c..49a456a 100644 --- a/lua/autorun/vikrlaundry_config.lua +++ b/lua/autorun/vikrlaundry_config.lua @@ -13,13 +13,26 @@ 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" +LaundryConfig.PhraseNotifyText = "You received %s for washing %d clothes" -- 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/cl_init.lua b/lua/entities/clean_laundry_cart/cl_init.lua index 6673bb4..7105135 100644 --- a/lua/entities/clean_laundry_cart/cl_init.lua +++ b/lua/entities/clean_laundry_cart/cl_init.lua @@ -1,14 +1,16 @@ include("shared.lua") +local colWhite = Color(255, 255, 255) +local superAngle = Angle(0, 0, 90) + function ENT:Draw() - self:DrawModel() + self:DrawModel() - local pos = self:LocalToWorld(self:OBBCenter()) - local ang = self:GetAngles() + if self:GetPos():DistToSqr(LocalPlayer():GetPos()) > 500 ^ 2 then return end - local phrase = string.gsub(LaundryConfig.PhraseCleanClothes, "", self:GetClothesNumber()) + local ang = self:GetAngles() - 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(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/clean_laundry_cart/init.lua b/lua/entities/clean_laundry_cart/init.lua index ff0289b..56f9fbe 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) @@ -21,57 +11,46 @@ 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 then return end - local phrase = string.gsub(LaundryConfig.PhraseNotifyText, "", tostring(#self.ClothTable)) - phrase = string.gsub(phrase, "", tostring(#self.ClothTable * LaundryConfig.MoneyPerCloth) .. GAMEMODE.Config.currency) + 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 - DarkRP.notify(cal, 0, 7, phrase) + local reward = numCloth * LaundryConfig.MoneyPerCloth + + cal:addMoney(reward) + + 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 pos = self:LocalToWorld(self:OBBCenter()) - local ang = self:GetAngles() - local entnum = 0 - self.ClothTable = { } + self.ClothTable = {} + local x, y = self:GetModelBounds() - 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 + 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 end - 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 - end - end - - for _, ent in pairs(self.ClothTable) do - entnum = entnum + 1 - end + self:SetClothesNumber(#self.ClothTable) - self:SetClothesNumber(entnum) - - self:NextThink(CurTime() + 0.1) + self:NextThink(CurTime() + 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..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") -end + self:NetworkVar("Int", 0, "ClothesNumber") +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/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/cloth/shared.lua b/lua/entities/cloth/shared.lua index 26abbcb..3eed049 100644 --- a/lua/entities/cloth/shared.lua +++ b/lua/entities/cloth/shared.lua @@ -10,9 +10,9 @@ 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) end -end +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..fb03817 100644 --- a/lua/entities/dirty_laundry_cart/cl_init.lua +++ b/lua/entities/dirty_laundry_cart/cl_init.lua @@ -1,14 +1,16 @@ include("shared.lua") +local colWhite = Color(255, 255, 255) +local superAngle = Angle(0, 0, 90) + function ENT:Draw() - self:DrawModel() + self:DrawModel() - local pos = self:LocalToWorld(self:OBBCenter()) - local ang = self:GetAngles() + if self:GetPos():DistToSqr(LocalPlayer():GetPos()) > 500 ^ 2 then return end - local phrase = string.gsub(LaundryConfig.PhraseDirtyClothes, "", self:GetClothesNumber()) + local ang = self:GetAngles() - 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(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/dirty_laundry_cart/init.lua b/lua/entities/dirty_laundry_cart/init.lua index 4b72e46..dc2de4f 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) @@ -33,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()) @@ -42,24 +37,15 @@ 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()) 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..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") -end + self:NetworkVar("Int", 0, "ClothesNumber") +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..9977ef0 100644 --- a/lua/entities/washing_machine/cl_init.lua +++ b/lua/entities/washing_machine/cl_init.lua @@ -1,32 +1,22 @@ include("shared.lua") -include("autorun/vikrlaundry_config.lua") -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 +local colBlack = Color(10, 10, 10, 100) +local colRed = Color(255, 0, 0) +local colGreen = Color(0, 255, 0) - if self:GetWashing() then - color = Color(0, 255, 0) - end +local x, y, w, h = 0, 0, 30, 30 - 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 +function ENT:Draw() + self:DrawModel() - self.ClothModel:SetPos(self:LocalToWorld(self:OBBCenter())) + if self:GetPos():DistToSqr(LocalPlayer():GetPos()) > 500 ^ 2 then return end - if not self:GetWashing() then - self.ClothModel:Remove() - end -end + local ang = self:GetAngles() + ang:RotateAroundAxis(ang:Up(), 90) + ang:RotateAroundAxis(ang:Forward(), 90) + + 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 \ No newline at end of file diff --git a/lua/entities/washing_machine/init.lua b/lua/entities/washing_machine/init.lua index e159a3c..619d4ce 100644 --- a/lua/entities/washing_machine/init.lua +++ b/lua/entities/washing_machine/init.lua @@ -1,94 +1,72 @@ AddCSLuaFile("cl_init.lua") 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 +include("shared.lua") 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 -end + self:SetModel("models/props_wasteland/laundry_dryer002.mdl") + self:PhysicsInit(SOLID_VPHYSICS) + self:SetMoveType(MOVETYPE_VPHYSICS) + self:SetSolid(SOLID_VPHYSICS) -function ENT:Think() - local pos = self:LocalToWorld(self:OBBCenter()) - local ang = self:GetAngles() - ang:RotateAroundAxis(ang:Up(), 90) - ang:RotateAroundAxis(ang:Forward(), 90) + local phys = self:GetPhysicsObject() + if (phys:IsValid()) then + phys:Wake() + end +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 +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 end - end - - 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..72e7dc1 100644 --- a/lua/entities/washing_machine/shared.lua +++ b/lua/entities/washing_machine/shared.lua @@ -9,11 +9,11 @@ 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 self:NetworkVarNotify("Washing", self.OnWash) end -end +end \ No newline at end of file