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's a working version:
Code:
IncludeScript("base_teamplay")
-----------------------------------------------------------------------------
-- set class limits
-----------------------------------------------------------------------------
function startup()
SetGameDescription("Fly!")
-- set up team limits on each team
SetPlayerLimit(Team.kBlue, 0)
SetPlayerLimit(Team.kRed, 0)
SetPlayerLimit(Team.kYellow, -1)
SetPlayerLimit(Team.kGreen, -1)
local team = GetTeam(Team.kBlue)
team:SetClassLimit(Player.kCivilian, -1)
team = GetTeam(Team.kRed)
team:SetClassLimit(Player.kCivilian, -1)
end
-----------------------------------------------------------------------------
-- Player spawn: give full health, armor, and ammo
-----------------------------------------------------------------------------
function player_spawn( player_entity )
local player = CastToPlayer( player_entity )
player:AddHealth( 400 )
player:AddArmor( 400 )
player:AddAmmo( Ammo.kNails, 400 )
player:AddAmmo( Ammo.kShells, 400 )
player:AddAmmo( Ammo.kRockets, 400 )
player:AddAmmo( Ammo.kCells, 400 )
end
-----------------------------------------------------------------------------
-- Spawn functions
-----------------------------------------------------------------------------
redspawn = { validspawn = redallowedmethod }
bluespawn = { validspawn = blueallowedmethod }
greenspawn = { validspawn = greenallowedmethod }
yellowspawn = { validspawn = yellowallowedmethod }
resupply_settings = {
resupply_interval = 1, -- in seconds
reload_clips = true,
health = 0,
armor = 0,
grenades = 0, -- blue/green pipes
shells = 0,
nails = 0,
rockets = 0,
cells = 0,
detpacks = 0,
mancannons = 0,
gren1 = 0,
gren2 = 0
}
-- utility function to return a list of all players in the server
function resupply_getallplayers()
local players = {}
for index=1,22 do
local player = GetPlayerByID(index)
if (player ~= nil) then
table.insert( players, player );
end
end
return players
end
-- so we don't overwrite startup
local resupply_savedfuncs = {}
resupply_savedfuncs.startup = startup
function startup()
-- check to make sure the saved function is actually a function
if type(resupply_savedfuncs.startup) == "function" then
-- call the saved function
resupply_savedfuncs.startup()
end
-- start resupply schedule
AddScheduleRepeating( "resupply_schedule", resupply_settings.resupply_interval, resupply_scheduled );
end
function resupply_scheduled()
local players = resupply_getallplayers();
for i,player in pairs(players) do
resupply( player )
end
end
function resupply( player )
if IsPlayer( player ) then
-- reload clips
if resupply_settings.reload_clips == true then player:ReloadClips() end
-- give player health and armor
if resupply_settings.health ~= nil then player:AddHealth( self.health ) end
if resupply_settings.armor ~= nil then player:AddArmor( self.armor ) end
-- give player ammo
if resupply_settings.nails ~= nil then player:AddAmmo(Ammo.kNails, self.nails) end
if resupply_settings.shells ~= nil then player:AddAmmo(Ammo.kShells, self.shells) end
if resupply_settings.rockets ~= nil then player:AddAmmo(Ammo.kRockets, self.rockets) end
if resupply_settings.cells ~= nil then player:AddAmmo(Ammo.kCells, self.cells) end
if resupply_settings.detpacks ~= nil then player:AddAmmo(Ammo.kDetpack, self.detpacks) end
if resupply_settings.mancannons ~= nil then player:AddAmmo(Ammo.kManCannon, self.mancannons) end
if resupply_settings.gren1 ~= nil then player:AddAmmo(Ammo.kGren1, self.gren1) end
if resupply_settings.gren2 ~= nil then player:AddAmmo(Ammo.kGren2, self.gren2) end
end
end
-- so we don't overwrite the function
local nodamage_savedfuncs = {}
nodamage_savedfuncs.player_ondamage = player_ondamage
function player_ondamage( player, damageinfo )
-- check to make sure the saved function is actually a function
if type(nodamage_savedfuncs.player_ondamage) == "function" then
-- call the saved function
nodamage_savedfuncs.player_ondamage( player, damageinfo )
end
-- if no damageinfo do nothing
if not damageinfo then return end
-- set damage to zero
damageinfo:SetDamage(0)
end
Changes I made:
- Removed team:SetClassLimit(Player.kSniper, SNIPER_LIMIT) lines in startup() as SNIPER_LIMIT wasn't defined and therefore broke things (error in console was [SCRIPT] Error calling startup (no overload of 'Team:SetClassLimit' matched the arguments (Team, number, nil) candidates are: Team:SetClassLimit(number, number))
- Fixed indenting because it bothered me
- Removed the four SetPlayerLimit() calls outside of startup because they shouldn't exist
- Included base_teamplay as its just a good idea in general unless you really know what you're doing
Last edited by squeek.; 08-20-2012 at 07:04 AM.
|