Stuff Do-er
Lua Team Wiki Team Fortress Forever Staff
Join Date: Mar 2007
Location: Northern California
Class/Position: Rallygun Shooter Gametype: Conc tag (you just wait) Affiliations: Mustache Brigade Posts Rated Helpful 352 Times
|
Here we go. It turned out to be quite long.
Create one info_ff_script and name it ball
Create two trigger_ff_scripts and name them blue_cap and red_cap
The cap points should be where you want that team to score. Example: The red_cap is where the red team's ball carrier goes to cap. The blue_cap is where the blue team's ball carrier goes to cap.
All the variables in CAPS at the top are for you to change however you wish. Anything that you want to change other than those things might be a bit tricky. I set the classlimits to only allow soli/demo/scout. Those limits are defined in startup() and are easy/straightforward to change if you want to change them.
Hopefully it all works.
Code:
----------------------------------------------------------------------
-- Includes
----------------------------------------------------------------------
IncludeScript("base_push")
----------------------------------------------------------------------
-- Definitions
----------------------------------------------------------------------
BALL_THROW_SPEED = 512
BALL_RETURN_TIME = 60
POINTS_PER_CAPTURE = 10
FORTPOINTS_PER_CAPTURE = 1000
FORT_POINTS_PER_BALL_CARRIER_KILLED = 100
TEAM_POINTS_PER_BALL_CARRIER_KILLED = 0
BALL_CARRIER_SPEED = .75
BALL_CARRIER_DAMAGESCALE = .25
BALL_CARRIER_REMOVEWEAPONS = true
BALL_CARRIER_REMOVEGRENADES = true
TEAM1 = Team.kBlue
TEAM2 = Team.kRed
TEAM1_CARRIER = Team.kYellow
TEAM2_CARRIER = Team.kGreen
TEAM1_NAME = "Team 1"
TEAM2_NAME = "Team 2"
TEAM1_CARRIER_NAME = "Team 1 Ball Carrier"
TEAM2_CARRIER_NAME = "Team 2 Ball Carrier"
----------------------------------------------------------------------
-- Startup
----------------------------------------------------------------------
function startup()
SetTeamName(TEAM1, TEAM1_NAME)
SetTeamName(TEAM2, TEAM2_NAME)
SetTeamName(TEAM1_CARRIER, TEAM1_CARRIER_NAME)
SetTeamName(TEAM2_CARRIER, TEAM2_CARRIER_NAME)
SetPlayerLimit(TEAM1, 0)
SetPlayerLimit(TEAM2, 0)
SetPlayerLimit(TEAM1_CARRIER, -1)
SetPlayerLimit(TEAM2_CARRIER, -1)
local team = GetTeam(TEAM1)
team:SetClassLimit( Player.kScout, 0 )
team:SetClassLimit( Player.kHwguy, -1 )
team:SetClassLimit( Player.kSpy, -1 )
team:SetClassLimit( Player.kCivilian, -1 )
team:SetClassLimit( Player.kSniper, -1 )
team:SetClassLimit( Player.kMedic, -1 )
team:SetClassLimit( Player.kSoldier, 0 )
team:SetClassLimit( Player.kDemoman, 0 )
team:SetClassLimit( Player.kPyro, -1 )
team:SetClassLimit( Player.kEngineer, -1 )
team = GetTeam(TEAM2)
team:SetClassLimit( Player.kScout, 0 )
team:SetClassLimit( Player.kHwguy, -1 )
team:SetClassLimit( Player.kSpy, -1 )
team:SetClassLimit( Player.kCivilian, -1 )
team:SetClassLimit( Player.kSniper, -1 )
team:SetClassLimit( Player.kMedic, -1 )
team:SetClassLimit( Player.kSoldier, 0 )
team:SetClassLimit( Player.kDemoman, 0 )
team:SetClassLimit( Player.kPyro, -1 )
team:SetClassLimit( Player.kEngineer, -1 )
team = GetTeam(TEAM1_CARRIER)
team:SetClassLimit( Player.kScout, 0 )
team:SetClassLimit( Player.kHwguy, -1 )
team:SetClassLimit( Player.kSpy, -1 )
team:SetClassLimit( Player.kCivilian, -1 )
team:SetClassLimit( Player.kSniper, -1 )
team:SetClassLimit( Player.kMedic, -1 )
team:SetClassLimit( Player.kSoldier, 0 )
team:SetClassLimit( Player.kDemoman, 0 )
team:SetClassLimit( Player.kPyro, -1 )
team:SetClassLimit( Player.kEngineer, -1 )
team = GetTeam(TEAM2_CARRIER)
team:SetClassLimit( Player.kScout, 0 )
team:SetClassLimit( Player.kHwguy, -1 )
team:SetClassLimit( Player.kSpy, -1 )
team:SetClassLimit( Player.kCivilian, -1 )
team:SetClassLimit( Player.kSniper, -1 )
team:SetClassLimit( Player.kMedic, -1 )
team:SetClassLimit( Player.kSoldier, 0 )
team:SetClassLimit( Player.kDemoman, 0 )
team:SetClassLimit( Player.kPyro, -1 )
team:SetClassLimit( Player.kEngineer, -1 )
end
-- Give everyone a full resupply
function player_spawn( player_entity )
local player = CastToPlayer( player_entity )
player:AddHealth( 100 )
player:AddArmor( 300 )
player:AddAmmo( Ammo.kNails, 400 )
player:AddAmmo( Ammo.kShells, 400 )
player:AddAmmo( Ammo.kRockets, 400 )
player:AddAmmo( Ammo.kCells, 400 )
player:AddAmmo( Ammo.kDetpack, 1 )
player:AddAmmo( Ammo.kManCannon, 1 )
player:RemoveEffect( EF.kSpeedlua1 )
local team = player:GetTeamId()
if team ~= TEAM1 and team ~= TEAM2 then
ApplyToPlayer( player, { GetChangeFlag( team ) } )
end
UpdateObjectiveIcon( player, GetEntityByName( "ball" ) )
end
-- On ball carrier killed, give appropriate points
function player_killed( killed_player, damageinfo )
if IsPlayer(killed_player) then
local player = CastToPlayer(killed_player)
if player:HasItem( "ball" ) then
-- Entity that is attacking
local attacker = damageinfo:GetAttacker()
-- If no attacker do nothing
if not attacker then
return
end
-- If attacker not a player do nothing
if not IsPlayer(attacker) then
return
end
local player_attacker = CastToPlayer(attacker)
-- If player is damaging self or damaged by own team do nothing
if (player:GetId() == playerAttacker:GetId()) or (player:GetTeamId() == playerAttacker:GetTeamId()) then
return
end
local team = player_attacker:GetTeam()
-- Add points
team:AddScore( TEAM_POINTS_PER_BALL_CARRIER_KILLED )
player_attacker:AddFortPoints( PLAYER_POINTS_PER_BALL_CARRIER_KILLED, "Killed Ball Carrier" )
end
end
end
-- On ball carrier killed, give appropriate points
function player_ondamage( damaged_player, damageinfo )
if IsPlayer(damaged_player) then
local player = CastToPlayer(damaged_player)
if player:HasItem( "ball" ) then
damageinfo:ScaleDamage( BALL_CARRIER_DAMAGESCALE )
end
end
end
-----------------------------------------------------------------------------
-- base_ball
-----------------------------------------------------------------------------
base_ball = info_ff_script:new({
name = "base ball",
team = Team.kUnassigned,
model = "models/items/ball/ball.mdl",
modelskin = 0,
tosssound = "Flag.Toss",
dropnotouchtime = 2,
capnotouchtime = 2,
hudicon = "hud_ball",
hudx = 5,
hudy = 210,
hudwidth = 48,
hudheight = 48,
hudalign = 1,
hudstatusiconbluex = 60,
hudstatusiconbluey = 5,
hudstatusiconredx = 60,
hudstatusiconredy = 5,
hudstatusiconblue = "hud_ball.vtf",
hudstatusiconred = "hud_ball.vtf",
hudstatusiconw = 15,
hudstatusiconh = 15,
hudstatusiconbluealign = 2,
hudstatusiconredalign = 3,
touchflags = {AllowFlags.kOnlyPlayers, AllowFlags.kBlue, AllowFlags.kRed, AllowFlags.kYellow, AllowFlags.kGreen},
botgoaltype = Bot.kFlag
})
function base_ball:hasanimation() return true end
-- For when this object is carried, these offsets are used to place
-- the info_ff_script relative to the players feet
function base_ball:attachoffset()
-- x = forward/backward
-- y = left/right
-- z = up/down
local offset = Vector( 32, 0, 0 )
return offset
end
function base_ball:precache()
PrecacheSound(self.tosssound)
PrecacheSound("yourteam.flagstolen")
PrecacheSound("otherteam.flagstolen")
PrecacheSound("yourteam.drop")
PrecacheSound("otherteam.drop")
PrecacheSound("yourteam.flagreturn")
PrecacheSound("otherteam.flagreturn")
PrecacheSound("yourteam.flagcap")
PrecacheSound("otherteam.flagcap")
info_ff_script.precache(self)
end
function base_ball:spawn()
self.notouch = { }
info_ff_script.spawn(self)
end
function base_ball:addnotouch(player_id, duration)
self.notouch[player_id] = duration
AddSchedule(self.name .. "-" .. player_id, duration, self.removenotouch, self, player_id)
end
function base_ball.removenotouch(self, player_id)
self.notouch[player_id] = nil
end
function base_ball:touch( touch_entity )
if IsPlayer( touch_entity ) then
local player = CastToPlayer( touch_entity )
-- pickup if they can
if self.notouch[player:GetId()] then return; end
if player:GetTeamId() ~= self.team then
-- let the teams know that the ball was picked up
SmartSound(player, "yourteam.flagstolen", "yourteam.flagstolen", "otherteam.flagstolen")
SmartSpeak(player, "CTF_YOUHAVEBALL", "CTF_TEAMHASBALL", "CTF_ENEMYHASBALL")
SmartMessage(player, "#FF_YOUHAVEBALL", "#FF_TEAMHASBALL", "#FF_ENEMYHASBALL", Color.kGreen, Color.kGreen, Color.kRed)
-- if the player is a spy, then force him to lose his disguise
player:SetDisguisable( false )
-- if the player is a spy, then force him to lose his cloak
player:SetCloakable( false )
-- note: this seems a bit backwards (Pickup verb fits Player better)
local ball = CastToInfoScript(entity)
ball:Pickup(player)
AddHudIcon( player, self.hudicon, ball:GetName(), self.hudx, self.hudy, self.hudwidth, self.hudheight, self.hudalign )
RemoveHudItemFromAll( "ball-icon-dropped" )
local team = player:GetTeamId()
if (team == Team.kBlue) then
AddHudIconToAll( self.hudstatusiconblue, "ball-icon-blue", self.hudstatusiconbluex, self.hudstatusiconbluey, self.hudstatusiconw, self.hudstatusiconh, self.hudstatusiconbluealign )
elseif (team == Team.kRed) then
AddHudIconToAll( self.hudstatusiconred, "ball-icon-red", self.hudstatusiconredx, self.hudstatusiconredy, self.hudstatusiconw, self.hudstatusiconh, self.hudstatusiconredalign )
end
local changeflag = GetChangeFlag( team )
ApplyToPlayer( player, { changeflag } )
if BALL_CARRIER_REMOVEWEAPONS then
player:RemoveAllWeapons()
if player:GetClass() == Player.kMedic then
player:GiveWeapon( "ff_weapon_medkit", true )
elseif player:GetClass() == Player.kSpy then
player:GiveWeapon( "ff_weapon_knife", true )
elseif player:GetClass() == Player.kEngineer then
player:GiveWeapon( "ff_weapon_spanner", true )
else
player:GiveWeapon( "ff_weapon_crowbar", true )
end
ApplyToPlayer( player, { AT.kRemoveProjectiles } )
end
if BALL_CARRIER_REMOVEGRENADES then
player:RemoveAmmo( Ammo.kGren1, 4 )
player:RemoveAmmo( Ammo.kGren2, 4 )
ApplyToPlayer( player, { AT.kStopPrimedGrens } )
end
player:AddEffect( EF.kSpeedlua1, -1, 0, BALL_CARRIER_SPEED )
UpdateObjectiveIcon( player, GetCap( team ) )
end
end
end
function base_ball:onownerdie( owner_entity )
-- drop the ball
local ball = CastToInfoScript(entity)
ball:Drop(BALL_RETURN_TIME, 0.0)
if IsPlayer( owner_entity ) then
local player = CastToPlayer( owner_entity )
RemoveHudItem( player, ball:GetName() )
local team = player:GetTeamId()
if (team == Team.kBlue) then
RemoveHudItemFromAll( "ball-icon-blue" )
elseif (team == Team.kRed) then
RemoveHudItemFromAll( "ball-icon-red" )
end
end
end
function base_ball:ownerfeign( owner_entity )
-- drop the ball
local ball = CastToInfoScript(entity)
ball:Drop(BALL_RETURN_TIME, 0.0)
if IsPlayer( owner_entity ) then
local player = CastToPlayer( owner_entity )
RemoveHudItem( player, ball:GetName() )
local team = player:GetTeamId()
if (team == Team.kBlue) then
RemoveHudItemFromAll( "ball-icon-blue" )
elseif (team == Team.kRed) then
RemoveHudItemFromAll( "ball-icon-red" )
end
end
end
function base_ball:dropitemcmd( owner_entity )
-- throw the ball
local ball = CastToInfoScript(entity)
ball:Drop(BALL_RETURN_TIME, BALL_THROW_SPEED)
if IsPlayer( owner_entity ) then
local player = CastToPlayer( owner_entity )
RemoveHudItem( player, ball:GetName() )
local team = player:GetTeamId()
if (team == Team.kBlue) then
RemoveHudItemFromAll( "ball-icon-blue" )
elseif (team == Team.kRed) then
RemoveHudItemFromAll( "ball-icon-red" )
end
end
end
function base_ball:ondrop( owner_entity )
if IsPlayer( owner_entity ) then
local player = CastToPlayer( owner_entity )
-- let the teams know that the flag was dropped
SmartSound(player, "yourteam.drop", "yourteam.drop", "otherteam.drop")
SmartMessage(player, "#FF_YOUBALLDROP", "#FF_TEAMBALLDROP", "#FF_ENEMYBALLDROP", Color.kYellow, Color.kYellow, Color.kYellow)
end
local ball = CastToInfoScript(entity)
ball:EmitSound(self.tosssound)
end
function base_ball:onloseitem( owner_entity )
if IsPlayer( owner_entity ) then
-- let the player that lost the ball put on a disguise
local player = CastToPlayer( owner_entity )
player:SetDisguisable(true)
player:SetCloakable( true )
self:addnotouch(player:GetId(), self.capnotouchtime)
local changeflag = GetChangeFlag( player:GetTeamId() )
ApplyToPlayer( player, { changeflag } )
player:RemoveEffect( EF.kSpeedlua1 )
if BALL_CARRIER_REMOVEWEAPONS then
GiveBackWeapons( player )
player:AddAmmo( Ammo.kNails, 400 )
player:AddAmmo( Ammo.kShells, 400 )
player:AddAmmo( Ammo.kRockets, 400 )
player:AddAmmo( Ammo.kCells, 400 )
player:AddAmmo( Ammo.kDetpack, 1 )
player:AddAmmo( Ammo.kManCannon, 1 )
end
UpdateObjectiveIcon( player, GetEntityByName( "ball" ) )
end
end
function base_ball:onreturn( )
-- let the teams know that the ball was returned
BroadCastMessage("#FF_BALLRETURN", Color.kYellow)
BroadCastSound ( "yourteam.flagreturn" )
SpeakAll( "CTF_BALLRETURN" )
end
-- Define the ball
ball = base_ball:new({})
----------------------------------------------------------------------
-- Cap points
----------------------------------------------------------------------
function pushcap:ontrigger( trigger_entity )
if IsPlayer( trigger_entity ) then
local player = CastToPlayer( trigger_entity )
-- check if the player is carrying the ball
if player:HasItem( self.item ) then
-- reward player for goal
player:AddFortPoints(FORTPOINTS_PER_CAPTURE, "#FF_FORTPOINTS_GOAL")
-- reward player's team for capture
local team = player:GetTeam()
team:AddScore(POINTS_PER_CAPTURE)
local alliedteam = GetTeam( GetAlliedTeam( player:GetTeamId() ) )
alliedteam:AddScore(POINTS_PER_CAPTURE)
local ball = GetInfoScriptByName( "ball" )
-- return the ball
ball:Return()
-- Remove any hud icons
RemoveHudItem( player, ball:GetName() )
local team = player:GetTeamId()
if (team == Team.kBlue) then
RemoveHudItemFromAll( "ball-icon-blue" )
elseif (team == Team.kRed) then
RemoveHudItemFromAll( "ball-icon-red" )
end
-- let the teams know that a capture occured
SmartSound(player, "yourteam.flagcap", "yourteam.flagcap", "otherteam.flagcap")
SmartSpeak(player, "CTF_YOUSCORE", "CTF_TEAMSCORE", "CTF_THEYSCORE")
SmartMessage(player, "#FF_YOUSCORE", "#FF_TEAMSCORE", "#FF_ENEMYSCORE", Color.kGreen, Color.kGreen, Color.kRed)
ApplyToAll({ AT.kRemovePacks, AT.kRemoveProjectiles, AT.kRespawnPlayers, AT.kRemoveBuildables, AT.kRemoveRagdolls, AT.kStopPrimedGrens, AT.kReloadClips })
end
end
end
-- declare the elements
if TEAM1 == Team.kRed then
red_cap = pushcap:new({ team = TEAM2_CARRIER, item = "ball" })
team1_cap = red_cap
elseif TEAM1 == Team.kBlue then
blue_cap = pushcap:new({ team = TEAM2_CARRIER, item = "ball" })
team1_cap = blue_cap
elseif TEAM1 == Team.kGreen then
green_cap = pushcap:new({ team = TEAM2_CARRIER, item = "ball" })
team1_cap = green_cap
elseif TEAM1 == Team.kYellow then
yellow_cap = pushcap:new({ team = TEAM2_CARRIER, item = "ball" })
team1_cap = yellow_cap
end
if TEAM2 == Team.kRed then
red_cap = pushcap:new({ team = TEAM1_CARRIER, item = "ball" })
team2_cap = red_cap
elseif TEAM2 == Team.kBlue then
blue_cap = pushcap:new({ team = TEAM1_CARRIER, item = "ball" })
team2_cap = blue_cap
elseif TEAM2 == Team.kGreen then
green_cap = pushcap:new({ team = TEAM1_CARRIER, item = "ball" })
team2_cap = green_cap
elseif TEAM2 == Team.kYellow then
yellow_cap = pushcap:new({ team = TEAM1_CARRIER, item = "ball" })
team2_cap = yellow_cap
end
----------------------------------------------------------------------
-- Get the team change flag
----------------------------------------------------------------------
function GetChangeFlag( team )
if team == TEAM1 then
if TEAM1_CARRIER == Team.kRed then
return AT.kChangeTeamRed
elseif TEAM1_CARRIER == Team.kBlue then
return AT.kChangeTeamBlue
elseif TEAM1_CARRIER == Team.kGreen then
return AT.kChangeTeamGreen
elseif TEAM1_CARRIER == Team.kYellow then
return AT.kChangeTeamYellow
else
return AT.kChangeTeamSpectator
end
elseif team == TEAM2 then
if TEAM2_CARRIER == Team.kRed then
return AT.kChangeTeamRed
elseif TEAM2_CARRIER == Team.kBlue then
return AT.kChangeTeamBlue
elseif TEAM2_CARRIER == Team.kGreen then
return AT.kChangeTeamGreen
elseif TEAM2_CARRIER == Team.kYellow then
return AT.kChangeTeamYellow
else
return AT.kChangeTeamSpectator
end
elseif team == TEAM1_CARRIER then
if TEAM1 == Team.kRed then
return AT.kChangeTeamRed
elseif TEAM1 == Team.kBlue then
return AT.kChangeTeamBlue
elseif TEAM1 == Team.kGreen then
return AT.kChangeTeamGreen
elseif TEAM1 == Team.kYellow then
return AT.kChangeTeamYellow
else
return AT.kChangeTeamSpectator
end
elseif team == TEAM2_CARRIER then
if TEAM2 == Team.kRed then
return AT.kChangeTeamRed
elseif TEAM2 == Team.kBlue then
return AT.kChangeTeamBlue
elseif TEAM2 == Team.kGreen then
return AT.kChangeTeamGreen
elseif TEAM2 == Team.kYellow then
return AT.kChangeTeamYellow
else
return AT.kChangeTeamSpectator
end
else
return AT.kChangeTeamSpectator
end
end
function GetAlliedTeam( team )
if team == TEAM1 then
return TEAM1_CARRIER
elseif team == TEAM2 then
return TEAM2_CARRIER
elseif team == TEAM1_CARRIER then
return TEAM1
elseif team == TEAM2_CARRIER then
return TEAM2
else
return Team.kSpectator
end
end
function GiveBackWeapons( player )
if IsPlayer( player ) then
if player:GetClass() == Player.kScout then
player:GiveWeapon( "ff_weapon_shotgun", true )
player:GiveWeapon( "ff_weapon_nailgun", true )
end
if player:GetClass() == Player.kSoldier then
player:GiveWeapon( "ff_weapon_shotgun", true )
player:GiveWeapon( "ff_weapon_supershotgun", true )
player:GiveWeapon( "ff_weapon_rpg", true )
end
if player:GetClass() == Player.kDemoman then
player:GiveWeapon( "ff_weapon_shotgun", true )
player:GiveWeapon( "ff_weapon_grenadelauncher", true )
player:GiveWeapon( "ff_weapon_pipelauncher", true )
end
if player:GetClass() == Player.kHwguy then
player:GiveWeapon( "ff_weapon_shotgun", true )
player:GiveWeapon( "ff_weapon_supershotgun", true )
player:GiveWeapon( "ff_weapon_assaultcannon", true )
end
if player:GetClass() == Player.kPyro then
player:GiveWeapon( "ff_weapon_shotgun", true )
player:GiveWeapon( "ff_weapon_flamethrower", true )
player:GiveWeapon( "ff_weapon_ic", true )
end
if player:GetClass() == Player.kMedic then
player:GiveWeapon( "ff_weapon_shotgun", true )
player:GiveWeapon( "ff_weapon_supershotgun", true )
player:GiveWeapon( "ff_weapon_supernailgun", true )
end
if player:GetClass() == Player.kSpy then
player:GiveWeapon( "ff_weapon_tranq", true )
player:GiveWeapon( "ff_weapon_supershotgun", true )
player:GiveWeapon( "ff_weapon_nailgun", true )
end
if player:GetClass() == Player.kSniper then
player:GiveWeapon( "ff_weapon_nailgun", true )
player:GiveWeapon( "ff_weapon_autorifle", true )
player:GiveWeapon( "ff_weapon_sniperrifle", true )
end
if player:GetClass() == Player.kEngineer then
player:GiveWeapon( "ff_weapon_railgun", true )
player:GiveWeapon( "ff_weapon_supershotgun", true )
end
end
end
function GetCap( team )
if GetEntityByName( "team1_cap" ) then return GetEntityByName( "team1_cap" ) end
if GetEntityByName( "team2_cap" ) then return GetEntityByName( "team2_cap" ) end
if TEAM1 == Team.kRed then
if GetEntityByName( "red_cap" ) then return GetEntityByName( "red_cap" ) end
elseif TEAM1 == Team.kBlue then
if GetEntityByName( "blue_cap" ) then return GetEntityByName( "blue_cap" ) end
elseif TEAM1 == Team.kGreen then
if GetEntityByName( "green_cap" ) then return GetEntityByName( "green_cap" ) end
elseif TEAM1 == Team.kYellow then
if GetEntityByName( "yellow_cap" ) then return GetEntityByName( "yellow_cap" ) end
end
if TEAM2 == Team.kRed then
if GetEntityByName( "red_cap" ) then return GetEntityByName( "red_cap" ) end
elseif TEAM2 == Team.kBlue then
if GetEntityByName( "blue_cap" ) then return GetEntityByName( "blue_cap" ) end
elseif TEAM2 == Team.kGreen then
if GetEntityByName( "green_cap" ) then return GetEntityByName( "green_cap" ) end
elseif TEAM2 == Team.kYellow then
if GetEntityByName( "yellow_cap" ) then return GetEntityByName( "yellow_cap" ) end
end
end
Last edited by squeek.; 10-19-2009 at 10:07 PM.
|