local Barricade_Table = { [1] = { state = 4, solid = false, health = 400, manager = nil }, [2] = { state = 4, solid = false, health = 400, manager = nil }, [3] = { state = 8, solid = false, health = 1200, manager = nil }, [4] = { state = 0, solid = false, health = 100, manager = nil }, [5] = { state = 0, solid = false, health = 100, manager = nil } } local Cade_Map = { "A", "B", "C", "D", "E" } local Barricade_Thinker = 0 local Barricade_AttackThinker = 0 PrintTable(Barricade_Table) CEntity.GetModel = function(self) if self:IsValid() then return self.m_ModelName end end function OnWaveInit() timer.Simple(0.5, function() if IsValid( ents.FindByName("Barricade_A_Script_Manager") ) then Barricade_Table[1].manager = ents.FindByName("Barricade_A_Script_Manager") end end) timer.Simple(0.5, function() if IsValid( ents.FindByName("Barricade_B_Script_Manager") ) then Barricade_Table[2].manager = ents.FindByName("Barricade_B_Script_Manager") end end) timer.Simple(0.5, function() if IsValid( ents.FindByName("Barricade_C_Script_Manager") ) then Barricade_Table[3].manager = ents.FindByName("Barricade_C_Script_Manager") end end) timer.Simple(0.5, function() if IsValid( ents.FindByName("Barricade_D_Script_Manager") ) then Barricade_Table[4].manager = ents.FindByName("Barricade_D_Script_Manager") end end) timer.Simple(0.5, function() if IsValid( ents.FindByName("Barricade_E_Script_Manager") ) then Barricade_Table[5].manager = ents.FindByName("Barricade_E_Script_Manager") end end) timer.Simple(1, function() for cade, v in pairs( Barricade_Table ) do local cade_name = "Barricade_" .. tostring( Cade_Map[cade] ) .. "_Part_" local brush_name = "Barricade_" .. tostring( Cade_Map[cade] ) .. "_Brush" if Barricade_Table[cade].manager ~= nil then local i = 1 while ( IsValid( ents.FindByName(cade_name .. tostring(i) ) ) ) do local hCade = ents.FindByName(cade_name .. tostring(i) ) local iState = Barricade_Table[cade].state local hBrush = nil if IsValid( ents.FindByName( brush_name ) ) then hBrush = ents.FindByName( brush_name ) end hCade.Damageable = false if not hCade.callbacks then hCade.callbacks = {} end if not hCade.callbacks.damaged then hCade.callbacks.damaged = hCade:AddCallback( ON_DAMAGE_RECEIVED_POST, function( ent, dmginfo, prevHealth ) CadeDamage( ent, dmginfo, prevHealth, cade ) end) end if hBrush ~= nil then hBrush.Damageable = false if not hBrush.callbacks then hBrush.callbacks = {} end hBrush.callbacks.damaged = hBrush:AddCallback( ON_DAMAGE_RECEIVED_POST, function( ent, dmginfo, prevHealth ) CadeDamage( ent, dmginfo, prevHealth, cade ) end) end i = i + 1 if i > 50 then break end --prevent stack overflow end end for i = 1, Barricade_Table[cade].state do ents.FindByName(cade_name .. tostring(i) ):AcceptInput( "Enable" ) ents.FindByName(cade_name .. tostring(i) ):AcceptInput( "EnableCollision" ) ents.FindByName(cade_name .. tostring(i) ).m_nSolidType = 6 ents.FindByName(cade_name .. tostring(i) ).Damageable = true end end end) Barricade_Table = { [1] = { state = 4, solid = false, health = 400, manager = nil }, [2] = { state = 4, solid = false, health = 400, manager = nil }, [3] = { state = 8, solid = false, health = 1200, manager = nil }, [4] = { state = 0, solid = false, health = 100, manager = nil }, [5] = { state = 0, solid = false, health = 100, manager = nil } } end function CadeDamage( ent, dmginfo, prevHealth, cade ) if ent.Damageable then local dmg = dmginfo.Damage local wep = dmginfo.Weapon local atk = dmginfo.Attacker if IsValidAliveRealPlayer( atk ) and ( atk:GetTeam() ~= 1 ) and ( atk:GetPlayerItemBySlot(2) ~= wep ) then return end Barricade_Table[cade].health = Barricade_Table[cade].health - dmg local cade_health = Barricade_Table[cade].health local cade_state = Barricade_Table[cade].state local next_cade_decrease = ( Barricade_Table[cade].state - 1 ) * 100 if cade_state > 4 then next_cade_decrease = next_cade_decrease + ( Barricade_Table[cade].state - ( 5 ) ) * 100 end local cade_name = "Barricade_" .. tostring( Cade_Map[cade] ) .. "_Part_" local hCade = ents.FindByName(cade_name .. tostring( Barricade_Table[cade].state ) ) local brush_name = "Barricade_" .. tostring( Cade_Map[cade] ) .. "_Brush" local hBrush = nil if IsValid( ents.FindByName( brush_name ) ) then hBrush = ents.FindByName( brush_name ) end ent:PlaySound("Wood_Plank.ImpactHard") ent:PlaySound("Wood_Plank.ImpactHard") if next_cade_decrease > cade_health then hCade:AcceptInput( "Disable" ) hCade:AcceptInput( "DisableCollision" ) ent:PlaySound("Wood_Plank.Break") ent:PlaySound("Wood_Plank.Break") hCade.Damageable = false ents.FindByName("nav_refresh"):AcceptInput("recomputeblockers") util.ParticleEffect( "crate_drop", hCade:GetAbsOrigin() ) util.ParticleEffect( "mvm_pow_gold_seq_wood3mid", hCade:GetAbsOrigin() ) Barricade_Table[cade].state = math.max( cade_state - 1, 0 ) cade_state = Barricade_Table[cade].state if cade_state > 4 and ( hBrush ~= nil ) then hBrush:AcceptInput( "Disable") hBrush.Damageable = false end end end end function removeCallbacks(player, callbacks) if not IsValid(player) then return end for _, callbackId in pairs(callbacks) do player:RemoveCallback(callbackId) end end function OnGameTick() if CurTime() >= Barricade_Thinker then for cade, v in pairs( Barricade_Table ) do if Barricade_Table[cade].manager ~= nil then local hManager = Barricade_Table[cade].manager local cade_name = "Barricade_" .. tostring( Cade_Map[cade] ) .. "_Part_" for _, hPlayer in pairs( ents.FindInBox( hManager:GetAbsOrigin() + Vector(-160,-160,-184), hManager:GetAbsOrigin() + Vector(160,160,0), "player" ) ) do if hPlayer:IsRealPlayer() and hPlayer:IsAlive() and ( hPlayer:GetTeam() ~= 1 ) then if hPlayer.bHasWood then Barricade_Table[cade].state = Barricade_Table[cade].state + 1 if not ( IsValid( ents.FindByName( cade_name .. tostring( Barricade_Table[cade].state ) ) ) ) then hPlayer:Print(2,"This barricade is fully built") Barricade_Table[cade].state = Barricade_Table[cade].state - 1 goto continue end ents.FindByName("nav_refresh"):AcceptInput("recomputeblockers") local brush_name = "Barricade_" .. tostring( Cade_Map[cade] ) .. "_Brush" local hBrush = nil if IsValid( ents.FindByName( brush_name ) ) then hBrush = ents.FindByName( brush_name ) end local percent = 0 local start = hPlayer:GetAbsOrigin() + Vector(0, 0, 24) local endpos = ents.FindByName(cade_name .. tostring(Barricade_Table[cade].state) ):GetAbsOrigin() local startang = Vector(0, 0, -90) local endang = ents.FindByName(cade_name .. tostring(Barricade_Table[cade].state) ):GetAbsAngles() local modelname = tostring( ents.FindByName(cade_name .. tostring(Barricade_Table[cade].state) ):GetModel() ) local iSkin = tonumber( ents.FindByName(cade_name .. tostring(Barricade_Table[cade].state) ).m_nSkin ) hPlayer.bHasWood = false local iState = Barricade_Table[cade].state local hCade = ents.FindByName(cade_name .. tostring(Barricade_Table[cade].state) ) if not hCade.callbacks then hCade.callbacks = {} end hCade.Damageable = true Barricade_Table[cade].health = iState * 100 hCade:AcceptInput( "EnableCollision" ) hCade.m_nSolidType = 6 if iState >= 4 then Barricade_Table[cade].health = Barricade_Table[cade].health + ( ( iState - 4 ) * 100 ) Barricade_Table[cade].solid = true if hBrush ~= nil then hBrush:AcceptInput( "Enable" ) hBrush.Damageable = true end else Barricade_Table[cade].solid = false if hBrush ~= nil then hBrush:AcceptInput( "Disable" ) hBrush.Damageable = false end end local ent_table = { model = modelname, origin = "0 0 0", angles = "0 0 0 ", solid = 0, disableshadows = 1, skin = iSkin, targetname = "DEBUG" } local hWood = ents.CreateWithKeys( "prop_dynamic", ent_table, true, true ) hWood:SetAbsOrigin( start ) hWood:SetAbsAngles( startang ) timer.Create( 0.05, function() percent = percent + 0.1 hWood:SetAbsOrigin( lerpvector( start, endpos, percent ) ) hWood:SetAbsAngles( lerpvector( startang, endang, percent ) ) end, 10) timer.Simple( 0.7, function() hWood:Remove() for i = 1, Barricade_Table[cade].state do ents.FindByName(cade_name .. tostring(i) ):AcceptInput( "Enable" ) ents.FindByName(cade_name .. tostring(i) ):AcceptInput( "EnableCollision" ) ents.FindByName(cade_name .. tostring(i) ).m_nSolidType = 6 ents.FindByName(cade_name .. tostring(i) ).Damageable = true end end) ::continue:: end elseif hPlayer:IsBot() and hPlayer:IsAlive() and ( hPlayer:GetTeam() ~= 1 ) then if Barricade_Table[cade].state > 2 and ( CurTime() >= hPlayer.Barricade_AttackThinker ) then hPlayer.Barricade_AttackThinker = CurTime() + 0.5 local sTargetCade = cade_name .. tostring(3) hPlayer:StunPlayer( 0.2, 0.8, TF_STUNFLAG_SLOWDOWN ) hPlayer:AcceptInput("$BotCommand", "interrupt_action -posent " .. sTargetCade .. " -lookposent " .. sTargetCade .. " -killlook -alwayslook -duration 0.2 -distance 8") hPlayer.m_bLagCompensation = true util.StartLagCompensation( hPlayer ) hPlayer:AcceptInput( "RunScriptCode", "self.GetActiveWeapon().PrimaryAttack()" ) hPlayer.m_bLagCompensation = false util.FinishLagCompensation( hPlayer ) end end end end end Barricade_Thinker = CurTime() + 0.2 end for _, player in pairs( ents.GetAllAliveRealPlayers() ) do if player:GetTeam() ~= 1 then if player.bHasWood then player:WeaponSwitchSlot(2) elseif player:GetPlayerItemBySlot(2):GetItemName() == "Wood Plank" and ( not player.bHasWood ) then player:WeaponStripSlot(2) player:WeaponSwitchSlot(1) player:GiveItem( player.PreviousMelee ) if player.m_iClass ~= TF_CLASS_SPY then player:WeaponSwitchSlot(0) end for i, hologram in pairs( ents.FindAllByName("Barricade_Hologram") ) do hologram:HideTo( player ) end elseif player:GetAttributeValue("move speed penalty") ~= nil and ( not player.bHasWood ) then if player.m_iClass == TF_CLASS_SCOUT then player:SetAttributeValue("move speed penalty", nil) player:SetAttributeValue("increased jump height", nil) player:SetAttributeValue("no_attack", nil) player:GetPlayerItemBySlot(2):SetAttributeValue("custom item model", "") player:GetPlayerItemBySlot(2):SetAttributeValue("custom view model", "") end for i, hologram in pairs( ents.FindAllByName("Barricade_Hologram") ) do hologram:HideTo( player ) end end end end end function OnPlayerConnected( player ) if player:IsRealPlayer() then player.bHasWood = false player:AddCallback( ON_KEY_PRESSED, function( ent, key ) if ent.bHasWood and ( ( key == IN_ATTACK ) or ( key == IN_ATTACK2 ) ) then player.bHasWood = false for i, hologram in pairs( ents.FindAllByName("Barricade_Hologram") ) do hologram:HideTo( ent ) end if ent.m_iClass ~= TF_CLASS_SCOUT then ent:DropItem(2) player:WeaponSwitchSlot(1) player:GiveItem( player.PreviousMelee ) if player.m_iClass ~= TF_CLASS_SPY then player:WeaponSwitchSlot(0) end else player:SetAttributeValue("move speed penalty", nil) player:SetAttributeValue("increased jump height", nil) player:SetAttributeValue("no_attack", nil) player:GetPlayerItemBySlot(2):SetAttributeValue("custom item model", "") player:GetPlayerItemBySlot(2):SetAttributeValue("custom view model", "") end end end) else player.Barricade_AttackThinker = 0 end end function ResetWood(_, activator ) if not IsValidAliveRealPlayer( activator ) then return end if not activator.bHasWood then activator.PreviousMelee = activator:GetPlayerItemBySlot(2):GetItemName() if activator.m_iClass ~= TF_CLASS_SCOUT then activator:GiveItem("Wood Plank") else activator:SetAttributeValue("move speed penalty", 0.7) activator:SetAttributeValue("increased jump height", 0.7) activator:SetAttributeValue("no_attack", 1) activator:GetPlayerItemBySlot(2):SetAttributeValue("custom item model", "models/weapons/c_models/c_paintrain/c_paintrain.mdl") activator:GetPlayerItemBySlot(2):SetAttributeValue("custom view model", "models/weapons/v_models/v_toolbox_engineer.mdl") end activator:Print(3,"You have picked up wood, attack to drop it!") for i, hologram in pairs( ents.FindAllByName("Barricade_Hologram") ) do hologram:ShowTo( activator ) end timer.Simple(0.1, function() for k,v in pairs(ents.FindAllByClass("tf_viewmodel")) do if v.m_hOwner == player then v.m_nSequence = 0 timer.Simple(0.5, function() v.m_nSequence = 1 end) end end end) end activator.bHasWood = true end