From 8ee00a8e21e8d9fccadaa6cf26c46636def592ac Mon Sep 17 00:00:00 2001 From: cheetah Date: Wed, 22 Jul 2020 20:24:31 +0200 Subject: [PATCH] added throwing icecream and beer --- lua/entities/snack_automat.lua | 2 +- lua/entities/thrown_food.lua | 202 ++++++++++++++++++++++---- lua/weapons/f_base.lua | 29 +++- lua/weapons/f_beer_duff.lua | 29 ++++ lua/weapons/f_icecream_chocolate.lua | 4 +- lua/weapons/f_icecream_neapolitan.lua | 3 +- lua/weapons/f_icecream_pistachio.lua | 4 +- lua/weapons/f_icecream_strawberry.lua | 4 +- lua/weapons/f_icecream_vanilla.lua | 4 +- 9 files changed, 244 insertions(+), 37 deletions(-) create mode 100644 lua/weapons/f_beer_duff.lua diff --git a/lua/entities/snack_automat.lua b/lua/entities/snack_automat.lua index bf5cf09..e3f06e7 100644 --- a/lua/entities/snack_automat.lua +++ b/lua/entities/snack_automat.lua @@ -16,7 +16,7 @@ table.insert(FoodItems, { energy = 10, price = 10 }) table.insert(FoodItems, { - ent = "beercan2", model = "models/foodnhouseholditems/beercan2.mdl", + ent = "f_beer_duff", model = "models/foodnhouseholditems/beercan2.mdl", iconEnt="beercan2", energy = 10, price = 10 }) table.insert(FoodItems, { diff --git a/lua/entities/thrown_food.lua b/lua/entities/thrown_food.lua index 89fcf6a..836b073 100644 --- a/lua/entities/thrown_food.lua +++ b/lua/entities/thrown_food.lua @@ -1,41 +1,187 @@ AddCSLuaFile() -- maybe doing it later DEFINE_BASECLASS( "base_anim" ) - -ENT.Type = "anim" +ENT.Base = "base_anim" +ENT.Type = "anim" ENT.PrintName = "Thrown Food" ENT.Author = "catSIXe" - +ENT.FoodType = "generic" +ENT.FoodSplashColor = Color(255, 255, 255) + +if SERVER then + util.AddNetworkString( "Food_Explosion" ) + util.AddNetworkString( "Food_DecalEx" ) +end +if CLIENT then + local emitter = ParticleEmitter(Vector(0,0,0)) + function food_splash_init(particle, vel, color) + particle:SetColor(color.r,color.g,color.b) + particle:SetVelocity( vel or VectorRand():GetNormalized() * 15) + particle:SetGravity( Vector(0,0,-500) ) + particle:SetLifeTime(0) + particle:SetDieTime(math.Rand(5,10)) + particle:SetStartSize(4) + particle:SetEndSize(0) + particle:SetStartAlpha(255) + particle:SetEndAlpha(0) + particle:SetCollide(true) + particle:SetBounce(0.3) + particle:SetRoll(math.pi*math.Rand(0,1)) + particle:SetRollDelta(math.pi*math.Rand(-10,10)) + end + net.Receive("Food_Explosion",function () + if !emitter then emitter = ParticleEmitter(Vector(0,0,0)) end + --if !self or !emitter then return MsgN("No Emitter or self exist") end + local pos = net.ReadVector() + local norm = net.ReadVector() + local bucketvel = net.ReadVector() + local entid = net.ReadFloat() + local color = Color(net.ReadInt(8), net.ReadInt(8), net.ReadInt(8)) + MsgN(color) + timer.Destroy("particle_timer"..entid) + + for i = 1,20 do + local particle = emitter:Add( "decals/decal_paintsplatter002", pos ) + if particle then + local dir = VectorRand():GetNormalized() + food_splash_init(particle, ((-norm)+dir):GetNormalized() * math.Rand(0,200) + bucketvel*0.5, color) + end + end + end) + net.Receive("Food_DecalEx",function () + local material = net.ReadString() + local ent = net.ReadEntity() + local position = net.ReadVector() + local normal = net.ReadVector() + local color = Color(net.ReadInt(8), net.ReadInt(8), net.ReadInt(8)) + local s = net.ReadInt(10) + --local entid = net.ReadFloat() + util.DecalEx(Material(material), ent, position, normal, color, s, s) + end) +end +function ENT:SetupFoodType(foodType) + self:SetNWString("foodType", foodType) + self.FoodType = foodType +end +function ENT:SetupColor(color) + self:SetNWInt("color_R", color.r) + self:SetNWInt("color_G", color.g) + self:SetNWInt("color_B", color.b) + self.FoodSplashColor = color +end function ENT:Initialize() - self:SetModel( "models/props_junk/PopCan01a.mdl" ) + self:SetModel( "models/props_phx/misc/potato.mdl" ) self:PhysicsInit( SOLID_VPHYSICS ) self:SetMoveType( MOVETYPE_VPHYSICS ) self:SetSolid( SOLID_VPHYSICS ) - local phys = self:GetPhysicsObject() - if (phys:IsValid()) then - phys:Wake() + --self:SetCollisionGroup(COLLISION_GROUP_DEBRIS) + if CLIENT then + if !emitter then emitter = ParticleEmitter(Vector(0,0,0)) end + emitter:SetPos(LocalPlayer():GetPos()) + + if IsValid(self) then + local kt = "particle_timer"..self:EntIndex() + timer.Create(kt, 0.01, 0, function() + if !emitter then + emitter = ParticleEmitter(LocalPlayer():GetPos()) + return + end + if !IsValid(self) then + timer.Destroy(kt) + return + end + color = Color(self:GetNWInt("color_R"), self:GetNWInt("color_G"), self:GetNWInt("color_B")) + if math.Rand(0,1) < 0.33 then + local particle = emitter:Add( "decals/decal_paintsplatter002", self:GetPos() + VectorRand():GetNormalized() * 4) + if particle then + food_splash_init(particle, Vector(0), color) + end + end + end) + end + end +end + +function ENT:PhysicsCollide(colData, collider) + if CLIENT then return end + --[[net.WriteVector() + net.WriteVector(colData.HitNormal) + net.WriteVector(colData.OurOldVelocity) + net.WriteFloat(entid)--]] + PrintTable(colData) + + if IsValid(colData.HitEntity) then + if colData.HitEntity:IsPlayer() then + MsgN("Collision with Player") + colData.HitEntity:ViewPunch( Angle( math.Rand(-8,8), math.Rand(-8,8), 0 ) ) + self:EmitSound("physics/body/body_medium_impact_hard"..math.floor(math.Rand(1,6))..".wav") + else + self:EmitSound("physics/cardboard/cardboard_box_impact_soft"..math.floor(math.Rand(1,7))..".wav") + end + --[[if not self.Paneled and colData.HitEntity:GetClass() == "mediaplayer_tv" then + self.Paneled = true + local overlayPanel = ents.Create("prop_physics") + overlayPanel:SetPos(colData.HitPos) + local a = colData.HitNormal:Angle() + a:RotateAroundAxis(a:Forward(), 90) + a:RotateAroundAxis(a:Right(), 90) + overlayPanel:SetAngles(a) + overlayPanel:SetModel("models/props_phx/construct/glass/glass_plate1x1.mdl") + overlayPanel:Spawn() + --overlayPanel:SetMoveType(MOVETYPE_NONE) + overlayPanel:SetColor(Color(255,255,255,1)) + overlayPanel:Activate() + local phys = overlayPanel:GetPhysicsObject( ) + if IsValid( phys ) then + phys:Wake() + phys:EnableMotion(false) + end + local p1 = colData.HitPos - (colData.HitNormal * 20) + local p2 = colData.HitPos + (colData.HitNormal * 20) + self:Splash(p1, p2) + SafeRemoveEntityDelayed(overlayPanel, 15) + SafeRemoveEntity( self ) + -- return true --exit prematurely + --self.Hitted = false + end--]] + end + local p1 = colData.HitPos--colData.HitPos - (colData.HitNormal * 10) + local p2 = colData.HitNormal --HitPos + (colData.HitNormal * 10) + local entid = self:EntIndex() + net.Start("Food_Explosion") + net.WriteVector(self:GetPos()) + net.WriteVector(colData.HitNormal) + net.WriteVector(colData.OurOldVelocity) + net.WriteFloat(entid) + net.WriteInt(self.FoodSplashColor.r or 255,8) + net.WriteInt(self.FoodSplashColor.g or 255,8) + net.WriteInt(self.FoodSplashColor.b or 255,8) + net.Broadcast() + if self.FoodType == "generic" then + util.Decal("YellowBlood", p1, p2) + elseif self.FoodType == "icecream" then + self:EmitSound("physics/flesh/flesh_impact_hard"..math.floor(math.Rand(1,6))..".wav") + net.Start("Food_DecalEx") + net.WriteString("decals/decal_paintsplatterblue001") + net.WriteEntity(colData.HitEntity) + net.WriteVector(colData.HitPos) + net.WriteVector(colData.HitNormal) + net.WriteInt(self.FoodSplashColor.r or 255,8) + net.WriteInt(self.FoodSplashColor.g or 255,8) + net.WriteInt(self.FoodSplashColor.b or 255,8) + net.WriteInt(1,10) + net.Broadcast() + elseif self.FoodType == "beer" then + util.Decal("BeerSplash", p1, p2) + --else if self.FoodType == "generic" then end + timer.Create("kill_kt"..entid,0.25,2,function () + for _,v in pairs(player.GetAll()) do + v:SendLua("timer.Destroy('particle_timer"..entid.."')") + end + end) + SafeRemoveEntity( self ) end -function ENT:Throw(ply) - +function ENT:Splash(p1, p2) end -function ENT:PhysicsCollide() - local effectdata = EffectData() - effectdata:SetOrigin(self.Entity:GetPos()) - effectdata:SetEntity(self.Entity) - effectdata:SetStart(self.Entity:GetPos()) - effectdata:SetNormal(Vector(0,0,1)) - --util.Effect("ManhackSparks", effectdata) - util.Effect("cball_explode", effectdata) - util.Effect("Explosion", effectdata) - local thumper = effectdata - thumper:SetOrigin(self.Entity:GetPos()) - thumper:SetScale(500) - thumper:SetMagnitude(500) - util.Effect("ThumperDust", effectdata) - local scorchstart = self.Entity:GetPos() + ((Vector(0,0,1)) * 5) - local scorchend = self.Entity:GetPos() + ((Vector(0,0,-1)) * 5) - SafeRemoveEntity(self.Entity) - util.Decal("Scorch", scorchstart, scorchend) -end \ No newline at end of file diff --git a/lua/weapons/f_base.lua b/lua/weapons/f_base.lua index 0ecdb37..b050bbe 100644 --- a/lua/weapons/f_base.lua +++ b/lua/weapons/f_base.lua @@ -1,4 +1,6 @@ AddCSLuaFile() + +CreateConVar( "food_spam", 0, FCVAR_NOTIFY, "Make food spammable") SWEP.PrintName = "Base" SWEP.Author = "catSIXe" @@ -46,6 +48,7 @@ SWEP.VElements = { SWEP.WElements = { ["food"] = { type = "Model", model = "models/foodnhouseholditems/icecream1.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(3.72, 2.571, -1.547), angle = Angle(166.132, -180, 10.519), size = Vector(0.5, 0.5, 0.5), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} } } +SWEP.FoodType = "generic" function SWEP:PrimaryAttack() if SERVER then @@ -54,9 +57,29 @@ function SWEP:PrimaryAttack() end end function SWEP:SecondaryAttack() - self:PrimaryAttack() - -- maybe throwing food - return false + local tr = self.Owner:GetEyeTrace() + self:EmitSound("weapons/slam/throw.wav") + self.Owner:ViewPunch( Angle( math.Rand(-8,8), math.Rand(-8,8), 0 ) ) + self.BaseClass.ShootEffects (self) + if (!SERVER) then return end + local ent = ents.Create("thrown_food") + ent:SetPos(self.Owner:GetShootPos()) + --ent:SetAngles(self.Owner:EyeAngles()) + ent:SetupFoodType(self.FoodType) + ent:SetupColor(self.FoodColor or Color(255,255,255)) + ent:Spawn() + ent:SetModel(self.WorldModel) + ent:Activate() + local phys = ent:GetPhysicsObject( ) + if IsValid( phys ) then + phys:SetVelocity( self.Owner:GetPhysicsObject():GetVelocity() ) + phys:AddVelocity( self.Owner:GetAimVector( ) * 128 * phys:GetMass( ) ) + --phys:AddAngleVelocity( VectorRand() * 128 * phys:GetMass( ) ) + end + + SafeRemoveEntityDelayed(ent, 15) + if GetConVar("food_spam"):GetBool() then return true end + SafeRemoveEntity(self.Weapon) end /******************************************************** SWEP Construction Kit base code diff --git a/lua/weapons/f_beer_duff.lua b/lua/weapons/f_beer_duff.lua new file mode 100644 index 0000000..c4bffed --- /dev/null +++ b/lua/weapons/f_beer_duff.lua @@ -0,0 +1,29 @@ +AddCSLuaFile() +SWEP.Base = "f_base" + +SWEP.PrintName = "Beer (Pißwasser)" +SWEP.Category = "catSIXe Food" +SWEP.Spawnable = true +SWEP.AdminOnly = false + +SWEP.HoldType = "passive" +SWEP.ViewModelFOV = 40.804020100503 +SWEP.ViewModelFlip = false +SWEP.UseHands = true +SWEP.ViewModel = "models/weapons/c_grenade.mdl" +SWEP.WorldModel = "models/foodnhouseholditems/beercan02.mdl" +SWEP.ShowViewModel = true +SWEP.ShowWorldModel = true +SWEP.ViewModelBoneMods = { + ["ValveBiped.Pin"] = { scale = Vector(0.009, 0.009, 0.009), pos = Vector(-30, -30, -30), angle = Angle(0, 0, 0) }, + ["ValveBiped.Grenade_body"] = { scale = Vector(0.009, 0.009, 0.009), pos = Vector(-30, -30, -30), angle = Angle(0, 0, 0) } +} +SWEP.IronSightsPos = Vector(-2.12, -8.443, 3.21) +SWEP.IronSightsAng = Vector(0, 0, 0) +SWEP.VElements = { + ["food"] = { type = "Model", model = "models/foodnhouseholditems/beercan02.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(2.753, 2.474, -2.033), angle = Angle(-180, 109.517, 4.415), size = Vector(0.73, 0.73, 0.73), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} } +} +SWEP.WElements = { + ["food"] = { type = "Model", model = "models/foodnhouseholditems/icecream2.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(3.72, 2.571, -1.547), angle = Angle(166.132, -180, 10.519), size = Vector(0.5, 0.5, 0.5), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} } +} +SWEP.FoodType = "beer" \ No newline at end of file diff --git a/lua/weapons/f_icecream_chocolate.lua b/lua/weapons/f_icecream_chocolate.lua index 383c655..bea8f3d 100644 --- a/lua/weapons/f_icecream_chocolate.lua +++ b/lua/weapons/f_icecream_chocolate.lua @@ -25,4 +25,6 @@ SWEP.VElements = { } SWEP.WElements = { ["food"] = { type = "Model", model = "models/foodnhouseholditems/icecream4.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(3.72, 2.571, -1.547), angle = Angle(166.132, -180, 10.519), size = Vector(0.5, 0.5, 0.5), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} } -} \ No newline at end of file +} +SWEP.FoodType = "icecream" +SWEP.FoodColor = Color(102,68,0) \ No newline at end of file diff --git a/lua/weapons/f_icecream_neapolitan.lua b/lua/weapons/f_icecream_neapolitan.lua index e19f1eb..fc534da 100644 --- a/lua/weapons/f_icecream_neapolitan.lua +++ b/lua/weapons/f_icecream_neapolitan.lua @@ -25,4 +25,5 @@ SWEP.VElements = { } SWEP.WElements = { ["food"] = { type = "Model", model = "models/foodnhouseholditems/icecream1.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(3.72, 2.571, -1.547), angle = Angle(166.132, -180, 10.519), size = Vector(0.5, 0.5, 0.5), color = Color(255, 255, 255, 255), surpresslightning = false, material = ""} -} \ No newline at end of file +} +SWEP.FoodType = "icecream" \ No newline at end of file diff --git a/lua/weapons/f_icecream_pistachio.lua b/lua/weapons/f_icecream_pistachio.lua index 35cb702..ddfc486 100644 --- a/lua/weapons/f_icecream_pistachio.lua +++ b/lua/weapons/f_icecream_pistachio.lua @@ -25,4 +25,6 @@ SWEP.VElements = { } SWEP.WElements = { ["food"] = { type = "Model", model = "models/foodnhouseholditems/icecream5.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(3.72, 2.571, -1.547), angle = Angle(166.132, -180, 10.519), size = Vector(0.5, 0.5, 0.5), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} } -} \ No newline at end of file +} +SWEP.FoodType = "icecream" +SWEP.FoodColor = Color(187,227,167) \ No newline at end of file diff --git a/lua/weapons/f_icecream_strawberry.lua b/lua/weapons/f_icecream_strawberry.lua index 2c82b4f..9a64509 100644 --- a/lua/weapons/f_icecream_strawberry.lua +++ b/lua/weapons/f_icecream_strawberry.lua @@ -25,4 +25,6 @@ SWEP.VElements = { } SWEP.WElements = { ["food"] = { type = "Model", model = "models/foodnhouseholditems/icecream3.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(3.72, 2.571, -1.547), angle = Angle(166.132, -180, 10.519), size = Vector(0.5, 0.5, 0.5), color = Color(255, 255, 255, 255), surpresslightning = false, material = "" } -} \ No newline at end of file +} +SWEP.FoodType = "icecream" +SWEP.FoodColor = Color(255, 192, 203) \ No newline at end of file diff --git a/lua/weapons/f_icecream_vanilla.lua b/lua/weapons/f_icecream_vanilla.lua index 6ea153e..4567a62 100644 --- a/lua/weapons/f_icecream_vanilla.lua +++ b/lua/weapons/f_icecream_vanilla.lua @@ -25,4 +25,6 @@ SWEP.VElements = { } SWEP.WElements = { ["food"] = { type = "Model", model = "models/foodnhouseholditems/icecream2.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(3.72, 2.571, -1.547), angle = Angle(166.132, -180, 10.519), size = Vector(0.5, 0.5, 0.5), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} } -} \ No newline at end of file +} +SWEP.FoodType = "icecream" +SWEP.FoodColor = Color(243,229,190) \ No newline at end of file