View Single Post
Old 08-19-2012, 05:56 AM   #70
squeek.
Stuff Do-er
Lua Team
Wiki Team
Fortress Forever Staff
 
squeek.'s Avatar
 
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
Send a message via AIM to squeek.
Everytime someone asks for a continuous resupply script I come up with a different way to do it. Here's what I came up with this time. It's completely untested:

Code:
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
For no damage, also untested:

Code:
-- 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
__________________
#FF.Pickup ยค Fortress-Forever pickups

My Non-official Maps
Released FF_DM_Squeek - FF_2Mesa3_Classic - FF_Siege_Classic
Beta FF_Myth - FF_Redlight_Greenlight

Sick of the people on the internet, always moanin'. They just moan.
- Karl Pilkington

Last edited by squeek.; 08-19-2012 at 05:57 AM.
squeek. is offline   Reply With Quote