Improve base_shutdown.lua

* Add built-in support for trigger-based buttons (blue_security_trigger/red_security_trigger)
 * Add built-in support for Lua-defined security shutdown length (SECURITY_LENGTH)
 * Add built-in support for turning on/off lights, brushes, trigger_ff_clips, and trigger_hurts
 * Add some helpful team-oriented trigger definitions in base_teamplay.lua
This commit is contained in:
squeek 2014-11-30 23:37:55 -08:00
parent 6c818f5cec
commit 1f5fbe6bba
2 changed files with 139 additions and 43 deletions

View file

@ -13,6 +13,61 @@ IncludeScript("base_respawnturret");
-----------------------------------------------------------------------------
POINTS_PER_CAPTURE = 10;
FLAG_RETURN_TIME = 60;
SECURITY_LENGTH = 45;
local base_shutdown_base = {}
base_shutdown_base.startup = startup
function startup()
if type(base_shutdown_base.startup) == "function" then
-- call the saved function
base_shutdown_base.startup()
end
-- this will take care of lights, etc when map loads or round gets restarted/prematch ends
security_on("red")
security_on("blue")
end
-----------------------------------------------------------------------------
-- Security events
-----------------------------------------------------------------------------
-- called when security gets turned off (team is a string prefix, like "red")
function security_off( team )
-- turn off security light, brush, hurt, etc
OutputEvent(team.."_security_light", "TurnOff")
OutputEvent(team.."_security_brush", "Disable")
OutputEvent(team.."_security_hurt", "Disable")
OutputEvent(team.."_laser_hurt", "Disable") -- a possible alias
-- get the clip entity
local clip = GetEntityByName(team.."_security_clip")
if clip then
clip = CastToTriggerClip(clip)
-- clear flags, but send a dummy flag (for some reason with zero flags it blocks everything)
clip:SetClipFlags({ClipFlags.kClipTeamBlue})
end
end
-- called when security gets turned on (team is a string prefix, like "red")
function security_on( team )
-- turn on security light, brush, hurt, etc
OutputEvent(team.."_security_light", "TurnOn")
OutputEvent(team.."_security_brush", "Enable")
OutputEvent(team.."_security_hurt", "Enable")
OutputEvent(team.."_laser_hurt", "Enable") -- a possible alias
-- get the clip entity
local clip = GetEntityByName(team.."_security_clip")
if clip then
clip = CastToTriggerClip(clip)
-- reset flags to normal
clip:SetClipFlags(_G[clipname].clipflags)
end
end
-----------------------------------------------------------------------------
-- Buttons
@ -32,7 +87,6 @@ function button_common:allowed( allowed_entity )
return EVENT_DISALLOWED
end
-- TODO this doesn't work
function button_common:onfailuse( use_entity )
if IsPlayer( use_entity ) then
local player = CastToPlayer( use_entity )
@ -45,8 +99,6 @@ end
-----------------------------------------------------------------------------
-- red button
--button_red = button_common:new({ team = Team.kBlue, sec_up = true })
button_red = button_common:new({
team = Team.kBlue,
sec_up = true,
@ -63,7 +115,11 @@ button_red = button_common:new({
-- Button responses
-----------------------------------------------------------------------------
function button_red:onin()
BroadCastMessage( "#FF_RED_SECURITY_DEACTIVATED" )
if SECURITY_LENGTH == 60 or SECURITY_LENGTH == 30 then
BroadCastMessage( "#FF_RED_SEC_"..SECURITY_LENGTH )
else
BroadCastMessage( "#FF_RED_SECURITY_DEACTIVATED" )
end
SpeakAll( "SD_REDDOWN" )
self.sec_up = false
@ -72,6 +128,7 @@ function button_red:onin()
AddHudIconToAll( self.sec_down_icon, "red-sec-down", self.iconx, self.icony, self.iconw, self.iconh, self.iconalign )
LogLuaEvent(0, 0, "security_down", "team", "red")
security_off("red")
end
function button_red:onout()
@ -83,7 +140,8 @@ function button_red:onout()
RemoveHudItemFromAll( "red-sec-down" )
AddHudIconToAll( self.sec_up_icon, "red-sec-up", self.iconx, self.icony, self.iconw, self.iconh, self.iconalign )
LogLuaEvent(0, 0, "security_up", "team", "red")
security_on("red")
end
-----------------------------------------------------------------------------
@ -91,8 +149,6 @@ end
-----------------------------------------------------------------------------
-- blue button
--button_blue = button_common:new({ team = Team.kRed, sec_up = true })
button_blue = button_common:new({
team = Team.kRed,
sec_up = true,
@ -109,7 +165,11 @@ button_blue = button_common:new({
-- Button responses
-----------------------------------------------------------------------------
function button_blue:onin()
BroadCastMessage( "#FF_BLUE_SECURITY_DEACTIVATED" )
if SECURITY_LENGTH == 60 or SECURITY_LENGTH == 30 then
BroadCastMessage( "#FF_BLUE_SEC_"..SECURITY_LENGTH )
else
BroadCastMessage( "#FF_BLUE_SECURITY_DEACTIVATED" )
end
SpeakAll( "SD_BLUEDOWN" )
self.sec_up = false
@ -118,6 +178,7 @@ function button_blue:onin()
AddHudIconToAll( self.sec_down_icon, "blue-sec-down", self.iconx, self.icony, self.iconw, self.iconh, self.iconalign )
LogLuaEvent(0, 0, "security_down", "team", "blue")
security_off("blue")
end
function button_blue:onout()
@ -128,38 +189,50 @@ function button_blue:onout()
RemoveHudItemFromAll( "blue-sec-down")
AddHudIconToAll( self.sec_up_icon, "blue-sec-up", self.iconx, self.icony, self.iconw, self.iconh, self.iconalign )
LogLuaEvent(0, 0, "security_up", "team", "blue")
LogLuaEvent(0, 0, "security_up", "team", "blue")
security_on("blue")
end
-----------------------------------------------------------------------------
-- Trigger-based security toggling
-----------------------------------------------------------------------------
base_security_trigger = not_team_only_trigger:new({ button = "" })
function base_security_trigger:ontrigger( player )
-- only take sec down if its up currently
local button = _G[self.button]
if button and button.sec_up then
self:onsecuritydown( player )
end
end
function base_security_trigger:onsecuritydown( player )
-- call the button's onin directly
local button = _G[self.button]
button.onin( button )
AddSchedule( self.button.."_security", SECURITY_LENGTH, function() self:onsecurityup() end )
end
function base_security_trigger:onsecurityup()
-- call the button's onout directly
local button = _G[self.button]
button.onout( button )
end
red_security_trigger = base_security_trigger:new( { team = Team.kRed, button = "button_red" } )
blue_security_trigger = base_security_trigger:new( { team = Team.kBlue, button = "button_blue" } )
-----------------------------------------------------------------------------
-- Hurts
-----------------------------------------------------------------------------
hurt = trigger_ff_script:new({ team = Team.kUnassigned })
function hurt:allowed( allowed_entity )
if IsPlayer( allowed_entity ) then
local player = CastToPlayer( allowed_entity )
if player:GetTeamId() == self.team then
return EVENT_ALLOWED
end
end
return EVENT_DISALLOWED
end
-- red lasers hurt blue and vice-versa
red_laser_hurt = hurt:new({ team = Team.kBlue })
blue_laser_hurt = hurt:new({ team = Team.kRed })
-- function precache()
-- precache sounds
-- PrecacheSound("vox.blueup")
-- PrecacheSound("vox.bluedown")
-- PrecacheSound("vox.redup")
-- PrecacheSound("vox.reddown")
-- end
red_security_hurt = not_red_trigger:new({})
blue_security_hurt = not_blue_trigger:new({})
-- the trigger_hurts can also be named like this
red_laser_hurt = red_security_hurt
blue_laser_hurt = blue_security_hurt
-------------------------
-- flaginfo
@ -177,15 +250,15 @@ function flaginfo( player_entity )
RemoveHudItem( player, "red-sec-up" )
RemoveHudItem( player, "blue-sec-up" )
if button_blue.sec_up == true then
AddHudIcon( player, button_blue.sec_up_icon, "blue-sec-up", button_blue.iconx, button_blue.icony, button_blue.iconw, button_blue.iconh, button_blue.iconalign )
else
AddHudIcon( player, button_blue.sec_down_icon, "blue-sec-down", button_blue.iconx, button_blue.icony, button_blue.iconw, button_blue.iconh, button_blue.iconalign )
end
if button_blue.sec_up == true then
AddHudIcon( player, button_blue.sec_up_icon, "blue-sec-up", button_blue.iconx, button_blue.icony, button_blue.iconw, button_blue.iconh, button_blue.iconalign )
else
AddHudIcon( player, button_blue.sec_down_icon, "blue-sec-down", button_blue.iconx, button_blue.icony, button_blue.iconw, button_blue.iconh, button_blue.iconalign )
end
if button_red.sec_up == true then
AddHudIcon( player, button_red.sec_up_icon, "red-sec-up", button_red.iconx, button_red.icony, button_red.iconw, button_red.iconh, button_red.iconalign )
else
AddHudIcon( player, button_red.sec_down_icon, "red-sec-down", button_red.iconx, button_red.icony, button_red.iconw, button_red.iconh, button_red.iconalign )
end
if button_red.sec_up == true then
AddHudIcon( player, button_red.sec_up_icon, "red-sec-up", button_red.iconx, button_red.icony, button_red.iconw, button_red.iconh, button_red.iconalign )
else
AddHudIcon( player, button_red.sec_down_icon, "red-sec-down", button_red.iconx, button_red.icony, button_red.iconw, button_red.iconh, button_red.iconalign )
end
end

View file

@ -97,6 +97,29 @@ end
no_annoyances = noannoyances
spawn_protection = noannoyances
-----------------------------------------------------------------------------
-- Useful trigger definitions
-----------------------------------------------------------------------------
-- team only triggers
team_only_trigger = trigger_ff_script:new({ team = Team.kUnassigned, allow = true })
function team_only_trigger:allowed( allowed_entity ) if allowed_entity and IsPlayer(allowed_entity) and CastToPlayer(allowed_entity):GetTeamId() == self.team then return self.allow else return not self.allow end end
-- triggers that allow any team except the given team
not_team_only_trigger = team_only_trigger:new({allow = false})
-- allow only if on the team
red_trigger = team_only_trigger:new({ team = Team.kRed })
blue_trigger = team_only_trigger:new({ team = Team.kBlue })
yellow_trigger = team_only_trigger:new({ team = Team.kYellow })
green_trigger = team_only_trigger:new({ team = Team.kGreen })
-- allow only if not on the team
not_red_trigger = not_team_only_trigger:new({ team = Team.kRed })
not_blue_trigger = not_team_only_trigger:new({ team = Team.kBlue })
not_yellow_trigger = not_team_only_trigger:new({ team = Team.kYellow })
not_green_trigger = not_team_only_trigger:new({ team = Team.kGreen })
-----------------------------------------------------------------------------
-- Trigger_ff_clips
-----------------------------------------------------------------------------