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
|
Cool idea. However, there are better ways to allow maps to implement the script without having to edit the map's Lua directly.
sv_globalluascript is a server variable that will load a script on every map load from maps/globalscripts/<scriptname>.lua.
sv_mapluasuffix is another server variable that will load the Lua file from maps/mapname__<suffix>__.lua if it exists. For example, you could create a ff_dm__gungame__.lua and then have server owners use sv_mapluasuffix gungame to load it.
You can also use Lua tables to clean up your code (and remove the 20 weapon limit). Here's a quick rewrite (untested):
Code:
-- gungame by ddm
gungame = {}
weapons = {}
function player_spawn( player_id )
local player = GetPlayer(player_id)
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 )
player:AddAmmo( Ammo.kDetpack, 1 )
player:AddAmmo( Ammo.kManCannon, 1 )
player:RemoveAmmo( Ammo.kGren1, 4 )
player:RemoveAmmo( Ammo.kGren2, 4 )
player:RemoveAllWeapons()
-- if they don't have a weapon assigned yet, start with the first in the list
if gungame[player:GetId()] == nil then
gungame[player:GetId()] = 1
end
-- give them the current weapon
player:RemoveAllWeapons()
local weapon_index = gungame[player:GetId()]
if weapons[weapon_index] ~= nil then
player:GiveWeapon(weapons[weapon_index], true)
else
ConsoleToAll("[SCRIPT] Error: weapon not found in the table "..weapon_index)
end
end
function player_killed( player_id )
local killer = GetPlayer(killer)
local victim = GetPlayer(player_id)
-- if this isn't the last weapon in the list, move to next weapon in the list
if gungame[killer:GetId()] ~= # weapons then
gungame[killer:GetId()] = gungame[killer:GetId()] + 1
else
BroadCastMessage(killer:GetName().." has won!")
AddSchedule("restartgame", 3, restartgame)
end
end
function restartgame()
gungame = {}
ApplyToAll({AT.kRespawnPlayers, AT.kRemoveProjectiles, AT.kRemoveRagdolls, AT.kRemoveBuildables, AT.kStopPrimedGrens, AT.kRemovePacks})
end
AtoZ:
Code:
IncludeScript("ddm_dm_gungame")
weapons = {
"ff_weapon_assaultcannon",
"ff_weapon_autorifle",
"ff_weapon_deploydispenser",
"ff_weapon_deploysentrygun",
"ff_weapon_flamethrower",
"ff_weapon_grenadelauncher",
"ff_weapon_ic",
"ff_weapon_knife",
"ff_weapon_medkit",
"ff_weapon_nailgun",
"ff_weapon_pipelauncher",
"ff_weapon_railgun",
"ff_weapon_rpg",
"ff_weapon_shotgun",
"ff_weapon_sniperrifle",
"ff_weapon_supernailgun",
"ff_weapon_supershotgun",
"ff_weapon_tommygun",
"ff_weapon_tranq",
"ff_weapon_umbrella"
}
ddm:
Code:
IncludeScript("ddm_dm_gungame")
weapons = {
"ff_weapon_rpg",
"ff_weapon_supershotgun",
"ff_weapon_grenadelauncher",
"ff_weapon_sniperrifle",
"ff_weapon_ic",
"ff_weapon_railgun",
"ff_weapon_tranq",
"ff_weapon_autorifle",
"ff_weapon_flamethrower",
"ff_weapon_nailgun",
"ff_weapon_knife",
"ff_weapon_shotgun",
"ff_weapon_medkit",
"ff_weapon_deploysentrygun",
"ff_weapon_umbrella"
}
heavyweapons:
Code:
IncludeScript("ddm_dm_gungame")
weapons = {
"ff_weapon_railgun",
"ff_weapon_autorifle",
"ff_weapon_rpg",
"ff_weapon_supershotgun",
"ff_weapon_sniperrifle",
"ff_weapon_assaultcannon",
"ff_weapon_supernailgun",
"ff_weapon_grenadelauncher",
"ff_weapon_deploydetpack",
"ff_weapon_knife"
}
Glad to see someone making original Lua scripts.
Last edited by squeek.; 04-08-2013 at 01:24 AM.
|