mirror of
https://github.com/fortressforever/fortressforever-scripts.git
synced 2024-11-26 06:20:46 +00:00
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:
parent
6c818f5cec
commit
1f5fbe6bba
2 changed files with 139 additions and 43 deletions
|
@ -13,6 +13,61 @@ IncludeScript("base_respawnturret");
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
POINTS_PER_CAPTURE = 10;
|
POINTS_PER_CAPTURE = 10;
|
||||||
FLAG_RETURN_TIME = 60;
|
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
|
-- Buttons
|
||||||
|
@ -32,7 +87,6 @@ function button_common:allowed( allowed_entity )
|
||||||
return EVENT_DISALLOWED
|
return EVENT_DISALLOWED
|
||||||
end
|
end
|
||||||
|
|
||||||
-- TODO this doesn't work
|
|
||||||
function button_common:onfailuse( use_entity )
|
function button_common:onfailuse( use_entity )
|
||||||
if IsPlayer( use_entity ) then
|
if IsPlayer( use_entity ) then
|
||||||
local player = CastToPlayer( use_entity )
|
local player = CastToPlayer( use_entity )
|
||||||
|
@ -45,8 +99,6 @@ end
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
-- red button
|
-- red button
|
||||||
--button_red = button_common:new({ team = Team.kBlue, sec_up = true })
|
|
||||||
|
|
||||||
button_red = button_common:new({
|
button_red = button_common:new({
|
||||||
team = Team.kBlue,
|
team = Team.kBlue,
|
||||||
sec_up = true,
|
sec_up = true,
|
||||||
|
@ -63,7 +115,11 @@ button_red = button_common:new({
|
||||||
-- Button responses
|
-- Button responses
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
function button_red:onin()
|
function button_red:onin()
|
||||||
|
if SECURITY_LENGTH == 60 or SECURITY_LENGTH == 30 then
|
||||||
|
BroadCastMessage( "#FF_RED_SEC_"..SECURITY_LENGTH )
|
||||||
|
else
|
||||||
BroadCastMessage( "#FF_RED_SECURITY_DEACTIVATED" )
|
BroadCastMessage( "#FF_RED_SECURITY_DEACTIVATED" )
|
||||||
|
end
|
||||||
SpeakAll( "SD_REDDOWN" )
|
SpeakAll( "SD_REDDOWN" )
|
||||||
|
|
||||||
self.sec_up = false
|
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 )
|
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")
|
LogLuaEvent(0, 0, "security_down", "team", "red")
|
||||||
|
|
||||||
|
security_off("red")
|
||||||
end
|
end
|
||||||
|
|
||||||
function button_red:onout()
|
function button_red:onout()
|
||||||
|
@ -84,6 +141,7 @@ function button_red:onout()
|
||||||
AddHudIconToAll( self.sec_up_icon, "red-sec-up", self.iconx, self.icony, self.iconw, self.iconh, self.iconalign )
|
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")
|
LogLuaEvent(0, 0, "security_up", "team", "red")
|
||||||
|
|
||||||
|
security_on("red")
|
||||||
end
|
end
|
||||||
|
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
@ -91,8 +149,6 @@ end
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
-- blue button
|
-- blue button
|
||||||
--button_blue = button_common:new({ team = Team.kRed, sec_up = true })
|
|
||||||
|
|
||||||
button_blue = button_common:new({
|
button_blue = button_common:new({
|
||||||
team = Team.kRed,
|
team = Team.kRed,
|
||||||
sec_up = true,
|
sec_up = true,
|
||||||
|
@ -109,7 +165,11 @@ button_blue = button_common:new({
|
||||||
-- Button responses
|
-- Button responses
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
function button_blue:onin()
|
function button_blue:onin()
|
||||||
|
if SECURITY_LENGTH == 60 or SECURITY_LENGTH == 30 then
|
||||||
|
BroadCastMessage( "#FF_BLUE_SEC_"..SECURITY_LENGTH )
|
||||||
|
else
|
||||||
BroadCastMessage( "#FF_BLUE_SECURITY_DEACTIVATED" )
|
BroadCastMessage( "#FF_BLUE_SECURITY_DEACTIVATED" )
|
||||||
|
end
|
||||||
SpeakAll( "SD_BLUEDOWN" )
|
SpeakAll( "SD_BLUEDOWN" )
|
||||||
|
|
||||||
self.sec_up = false
|
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 )
|
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")
|
LogLuaEvent(0, 0, "security_down", "team", "blue")
|
||||||
|
|
||||||
|
security_off("blue")
|
||||||
end
|
end
|
||||||
|
|
||||||
function button_blue:onout()
|
function button_blue:onout()
|
||||||
|
@ -129,37 +190,49 @@ function button_blue:onout()
|
||||||
RemoveHudItemFromAll( "blue-sec-down")
|
RemoveHudItemFromAll( "blue-sec-down")
|
||||||
AddHudIconToAll( self.sec_up_icon, "blue-sec-up", self.iconx, self.icony, self.iconw, self.iconh, self.iconalign )
|
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
|
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
|
-- 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 lasers hurt blue and vice-versa
|
||||||
|
red_security_hurt = not_red_trigger:new({})
|
||||||
red_laser_hurt = hurt:new({ team = Team.kBlue })
|
blue_security_hurt = not_blue_trigger:new({})
|
||||||
blue_laser_hurt = hurt:new({ team = Team.kRed })
|
-- the trigger_hurts can also be named like this
|
||||||
|
red_laser_hurt = red_security_hurt
|
||||||
-- function precache()
|
blue_laser_hurt = blue_security_hurt
|
||||||
-- precache sounds
|
|
||||||
-- PrecacheSound("vox.blueup")
|
|
||||||
-- PrecacheSound("vox.bluedown")
|
|
||||||
-- PrecacheSound("vox.redup")
|
|
||||||
-- PrecacheSound("vox.reddown")
|
|
||||||
-- end
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-------------------------
|
-------------------------
|
||||||
-- flaginfo
|
-- flaginfo
|
||||||
|
|
|
@ -97,6 +97,29 @@ end
|
||||||
no_annoyances = noannoyances
|
no_annoyances = noannoyances
|
||||||
spawn_protection = 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
|
-- Trigger_ff_clips
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in a new issue