if (SERVER) then --the init.lua stuff goes in here AddCSLuaFile ("shared.lua")endif (CLIENT) then --the cl_init.lua stuff goes in here SWEP.PrintName = "Flashbang" SWEP.SlotPos = 6 SWEP.IconLetter = "g" SWEP.NameOfSWEP = "weapon_ttt_flashbang" --always make this the name of the folder the SWEP is in. killicon.AddFont( SWEP.NameOfSWEP, "CSKillIcons", SWEP.IconLetter, Color( 255, 80, 0, 255 ) ) SWEP.Icon = "VGUI/ttt/icon_bw_flashbang"endSWEP.Primary.NumNades = 3 --number of throwable grenades at your disposalSWEP.Grenade = "rcs_thrownflashbang" --self explanitorylocal here = trueSWEP.Author = "cheesylard"SWEP.Category = "RealCS"SWEP.Spawnable = trueSWEP.AdminSpawnable = trueSWEP.Base = "weapon_tttbasegrenade"SWEP.Kind = WEAPON_EQUIP2SWEP.CanBuy = { ROLE_TRAITOR }SWEP.LimitedStock = trueSWEP.EquipMenuData = { type = "Weapon", desc = "Use for distraction.\nUse it wise, you only\nhave one flashbang."};SWEP.AllowDrop = trueSWEP.AutoSpawnable = falseSWEP.ViewModel = "models/weapons/v_eq_flashbang.mdl"SWEP.WorldModel = "models/weapons/w_eq_flashbang.mdl"SWEP.Primary.ClipSize = -1SWEP.Primary.DefaultClip = -1SWEP.Primary.Automatic = trueSWEP.Primary.Ammo = "none"SWEP.Secondary.ClipSize = -1SWEP.Secondary.DefaultClip = -1SWEP.Secondary.Automatic = falseSWEP.Secondary.Ammo = "none"SWEP.IronSightsPos = Vector (7.3161, 0, 0.6718)SWEP.IronSightsAng = Vector (7.2937, 9.6773, 51.2462)
local DIETIMER = 1.5; --time in seconds, for the grenade to transition from full white to clearlocal EFFECT_DELAY = 0.5; --time, in seconds when the effects still are going on, even when the whiteness of the flash is gone (set to -1 for no effects at all =]).local pos, endflash, endflash2;if (CLIENT) then function ENT:Initialize() pos = self:GetPos() timer.Simple(2, function() local beeplight = DynamicLight( self:EntIndex() ) if ( beeplight ) then beeplight.Pos = pos beeplight.r = 255 beeplight.g = 255 beeplight.b = 255 beeplight.Brightness = 6 beeplight.Size = 1000 beeplight.Decay = 1000 beeplight.DieTime = CurTime() + 0.15 end end) end function ENT:Think() pos = self:GetPos() end function ENT:Draw() self.Entity:DrawModel() end function ENT:IsTranslucent() return true end --actual white stuff function SimulateFlash_REALCS_NOT_ANYTHINGELSE() if LocalPlayer():GetNetworkedFloat("RCS_flashed_time") > CurTime()then local pl = LocalPlayer(); local e = pl:GetNetworkedFloat("RCS_flashed_time"); --when it dies away local s = pl:GetNetworkedFloat("RCS_flashed_time_start"); --when it started local alpha; if(e-CurTime()>DIETIMER)then alpha = 255; else local pf = 1-(CurTime() - (e-DIETIMER))/(e - (e-DIETIMER)); alpha = pf*255; end surface.SetDrawColor(255,255,255,math.Round(alpha)); surface.DrawRect(0,0,surface.ScreenWidth(),surface.ScreenHeight()); //draw.SimpleText("alpha: "..alpha,"TargetID",0,0,Color(0,0,0,255),0,0); //draw.SimpleText("time left: "..(e-CurTime()),"TargetID",0,15,Color(0,0,0,255),0,0); end end hook.Add("HUDPaint", "SimulateFlash_REALCS_NOT_ANYTHINGELSE", SimulateFlash_REALCS_NOT_ANYTHINGELSE); --motion blur and other junk local function SimulateBlur_REALCS_NOT_ANYTHINGELSE() local pl = LocalPlayer(); local e = pl:GetNetworkedFloat("RCS_flashed_time") + EFFECT_DELAY; --when it dies away local s = pl:GetNetworkedFloat("RCS_flashed_time_start"); --when it started if (e > CurTime() && e-EFFECT_DELAY-CurTime()<=DIETIMER )then local pf = 1-(CurTime() - (e-DIETIMER))/(DIETIMER); DrawMotionBlur( 0,pf/((DIETIMER+EFFECT_DELAY)/DIETIMER), 0); //DrawBloom( 3, pf*5, 6, 6, 12, 0, 255, 255, 255 ); elseif(e > CurTime())then DrawMotionBlur( 0, 0.01, 0); else DrawMotionBlur( 0, 0, 0); end end hook.Add( "RenderScreenspaceEffects", "SimulateBlur_REALCS_NOT_ANYTHINGELSE", SimulateBlur_REALCS_NOT_ANYTHINGELSE ) endENT.Type = "anim"function ENT:OnRemove()endfunction ENT:PhysicsUpdate()endfunction ENT:PhysicsCollide(data,phys) if data.Speed > 50 then self.Entity:EmitSound(Sound("weapons/flashbang/grenade_hit1.wav")) end local lollol = -data.Speed * data.HitNormal * .1 + (data.OurOldVelocity * -0.6) phys:ApplyForceCenter(lollol)end
local FLASH_INTENSITY = 2250; --the higher the number, the longer the flash will be whitening your screenAddCSLuaFile( "shared.lua" )include("shared.lua")local function simplifyangle(angle) while(angle>=180) do angle = angle - 360; end while(angle <= -180) do angle = angle + 360; end return angle;end/*uselesslocal function pos_to_ang(pos1, pos2) --takes the angle from the first argument to the second argument and returns it for use with the flashbang. (function made by chee/syla/rd) local xR,yR; --initialize variables if(pos1.y == pos2.y) then--if your dividing by zero OSHI- xR = 90; --what it WOULD return, but dividing by zero obviously creates a rip in the space time continuum, let's not do that. else xR = math.atan((pos2.z-pos1.z)/(pos2.y-pos1.y)); --gets tangent of slope end if (pos1.z > pos2.z || pos1.y > pos2.y) && !(pos1.z > pos2.z || pos1.y > pos2.y) then --angles are switched around xR = -1*xR; --inverse it end if(pos1.x == pos2.x)then yR = 90; else yR = math.atan((pos2.y-pos1.y)/(pos2.x-pos1.x)); end if (pos1.y > pos2.y || pos1.x > pos2.x) && !(pos1.y > pos2.y || pos1.x > pos2.x) then yR = -1*yR; end return Angle(xR, yR, 0);end*/function ENT:Explode() self.Entity:EmitSound(Sound("weapons/flashbang/flashbang_explode"..math.random(1,2)..".wav")); for _,pl in pairs(player.GetAll()) do //--local ang = pos_to_ang(pl:GetShootPos(), self.Entity:GetPos()); local ang = (self.Entity:GetPos() - pl:GetShootPos()):Normalize():Angle() //print("Ideal angle: Angle("..ang.p..", "..ang.y..", "..ang.r..")\n"); //print("Player angle: Angle("..pl:EyeAngles().p..", "..pl:EyeAngles().y..", "..pl:EyeAngles().r..")\n"); local tracedata = {}; tracedata.start = pl:GetShootPos(); tracedata.endpos = self.Entity:GetPos(); tracedata.filter = pl; local tr = util.TraceLine(tracedata); local pitch = simplifyangle(ang.p - pl:EyeAngles().p); local yaw = simplifyangle(ang.y - pl:EyeAngles().y); //print("Relativity to FOV: Angle("..pitch..", "..yaw..", 0)\n"); if (!tr.HitWorld) then local dist = pl:GetShootPos():Distance( self.Entity:GetPos() ) local endtime = FLASH_INTENSITY/dist; if (endtime > 6) then endtime = 6; elseif(endtime < 0.4) then endtime = 0.4; end simpendtime = math.floor(endtime); tenthendtime = math.floor((endtime-simpendtime)*10); if( pitch > -45 && pitch < 45 && yaw > -45 && yaw < 45 ) || (pl:GetEyeTrace().Entity && pl:GetEyeTrace().Entity == self.Entity )then --in FOV //pl:PrintMessage(HUD_PRINTTALK, "In FOV"); else //pl:PrintMessage(HUD_PRINTTALK, "Not in FOV"); endtime = endtime/2; end if (pl:GetNetworkedFloat("RCS_flashed_time") > CurTime()) then --if you're already flashed pl:SetNetworkedFloat("RCS_flashed_time", endtime+pl:GetNetworkedFloat("RCS_flashed_time")+CurTime()-pl:GetNetworkedFloat("RCS_flashed_time_start")); --add more to it else --not flashed pl:SetNetworkedFloat("RCS_flashed_time", endtime+CurTime()); end pl:SetNetworkedFloat("RCS_flashed_time_start", CurTime()); end end self.Entity:Remove();endfunction ENT:Initialize() self.Entity:SetModel("models/weapons/w_eq_flashbang_thrown.mdl") self.Entity:PhysicsInit( SOLID_VPHYSICS ) self.Entity:SetMoveType( MOVETYPE_VPHYSICS ) self.Entity:SetSolid( SOLID_VPHYSICS ) self.Entity:DrawShadow( false ) self.Entity:SetCollisionGroup( COLLISION_GROUP_WEAPON ) local phys = self.Entity:GetPhysicsObject() if (phys:IsValid()) then phys:Wake() end timer.Simple(2, function() if self.Entity then self:Explode() end end )endfunction ENT:Think()endfunction ENT:OnTakeDamage() self:Explode()endfunction ENT:Use()endfunction ENT:StartTouch()endfunction ENT:EndTouch()endfunction ENT:Touch()end
if SERVER then AddCSLuaFile( "shared.lua" ) endSWEP.HoldType = "grenade"if CLIENT then SWEP.PrintName = "Flashbang" SWEP.Slot = 3 SWEP.Icon = "VGUI/ttt/icon_nades"endSWEP.Base = "weapon_tttbasegrenade"SWEP.Spawnable = trueSWEP.AdminSpawnable = trueSWEP.ViewModel = "models/weapons/v_eq_flashbang.mdl"SWEP.WorldModel = "models/weapons/w_eq_flashbang.mdl"SWEP.Weight = 5SWEP.AutoSpawnable = true-- really the only difference between grenade weapons: the model and the thrown-- ent.function SWEP:GetGrenadeName() return "ttt_flashbang"end
if SERVER then AddCSLuaFile("shared.lua")endENT.Type = "anim"ENT.Base = "ttt_basegrenade_proj"ENT.Model = Model("models/weapons/w_eq_smokegrenade_thrown.mdl")AccessorFunc( ENT, "radius", "Radius", FORCE_NUMBER )function ENT:Initialize() if not self:GetRadius() then self:SetRadius(20) end return self.BaseClass.Initialize(self)endif (CLIENT) then /*--------------------------------------------------------- Initialize ---------------------------------------------------------*/ function ENT:Initialize() local Pos = self:GetPos() timer.Simple(2, function() local dynamicflash = DynamicLight( self:EntIndex() ) if ( dynamicflash ) then dynamicflash.Pos = Pos dynamicflash.r = 255 dynamicflash.g = 255 dynamicflash.b = 255 dynamicflash.Brightness = 5 dynamicflash.Size = 1000 dynamicflash.Decay = 1000 dynamicflash.DieTime = CurTime() + 0.5 end end) end em:Finish() end/*--------------------------------------------------------- Think ---------------------------------------------------------*/ function ENT:Think() end /*--------------------------------------------------------- Draw ---------------------------------------------------------*/ function ENT:Draw() self.Entity:DrawModel() end /*--------------------------------------------------------- IsTranslucent ---------------------------------------------------------*/ function ENT:IsTranslucent() return true end function FlashEffect() if LocalPlayer():GetNetworkedFloat("FLASHED_END") > CurTime() then local pl = LocalPlayer(); local FlashedEnd = pl:GetNetworkedFloat("FLASHED_END") local FlashedStart = pl:GetNetworkedFloat("FLASHED_START") local Alpha if(FlashedEnd - CurTime() > FLASHTIMER) then Alpha = 150; else local FlashAlpha = 1 - (CurTime() - (FlashedEnd - FLASHTIMER)) / (FlashedEnd - (FlashedEnd - FLASHTIMER)); Alpha = FlashAlpha * 150; end surface.SetDrawColor(255, 255, 255, math.Round(Alpha)) surface.DrawRect(0, 0, surface.ScreenWidth(), surface.ScreenHeight()) end end hook.Add("HUDPaint", "FlashEffect", FlashEffect); local function StunEffect() local pl = LocalPlayer(); local FlashedEnd = pl:GetNetworkedFloat("FLASHED_END") local FlashedStart = pl:GetNetworkedFloat("FLASHED_START") if (FlashedEnd > CurTime() and FlashedEnd - EFFECT_DELAY - CurTime() <= FLASHTIMER) then local FlashAlpha = 1 - (CurTime() - (FlashedEnd - FLASHTIMER)) / (FLASHTIMER); DrawMotionBlur( 0, FlashAlpha / ((FLASHTIMER + EFFECT_DELAY) / (FLASHTIMER * 4)), 0); elseif (FlashedEnd > CurTime()) then DrawMotionBlur( 0, 0.01, 0); else DrawMotionBlur( 0, 0, 0); end end hook.Add( "RenderScreenspaceEffects", "StunEffect", StunEffect )endENT.Type = "anim"/*---------------------------------------------------------OnRemove---------------------------------------------------------*/function ENT:OnRemove()end/*---------------------------------------------------------PhysicsUpdate---------------------------------------------------------*/function ENT:PhysicsUpdate()end/*---------------------------------------------------------PhysicsCollide---------------------------------------------------------*/function ENT:PhysicsCollide(data,phys) if data.Speed > 50 then self.Entity:EmitSound(Sound("Flashbang.Bounce")) end local impulse = -data.Speed * data.HitNormal * .4 + (data.OurOldVelocity * -.6) phys:ApplyForceCenter(impulse) endfunction ENT:Explode(tr) if SERVER then self.Entity:EmitSound(Sound("Flashbang.Explode")); for _,pl in pairs(player.GetAll()) do local ang = (self.Entity:GetPos() - pl:GetShootPos()):Normalize():Angle() local tracedata = {}; tracedata.start = pl:GetShootPos(); tracedata.endpos = self.Entity:GetPos(); tracedata.filter = pl; local tr = util.TraceLine(tracedata); if (!tr.HitWorld) then local dist = pl:GetShootPos():Distance( self.Entity:GetPos() ) local endtime = FLASH_INTENSITY / (dist * 2); if (endtime > 6) then endtime = 6; elseif (endtime < 1) then endtime = 0; end simpendtime = math.floor(endtime); tenthendtime = math.floor((endtime - simpendtime) * 10);-- if (pl:GetNetworkedFloat("FLASHED_END") > CurTime()) then-- pl:SetNetworkedFloat("FLASHED_END", endtime + pl:GetNetworkedFloat("FLASHED_END") + CurTime() - pl:GetNetworkedFloat("FLASHED_START"));-- else pl:SetNetworkedFloat("FLASHED_END", endtime + CurTime());-- end pl:SetNetworkedFloat("FLASHED_END_START", CurTime()); end end self.Entity:Remove();end