Code: Select all
function gadget:GetInfo()
return {
name = "Fail Gadget",
desc = "Various ways to kill stuff",
author = "eyu100 (Eric Yu)",
date = "2010-07-10",
license = "Public domain",
layer = 1,
enabled = true
}
end
local function Killall()
local units = Spring.GetAllUnits()
for _,unit in pairs(units) do
Spring.DestroyUnit(unit,true)
end
end
local function Kill(cmd, msg, words, player)
local teamToKill = msg[1]
Spring.Echo(teamToKill)
local unitsToKill = Spring.GetTeamUnits(teamToKill)
for _,unit in pairs(unitsToKill) do
Spring.DestroyUnit(unit,true)
end
end
local function Suicide(cmd, msg, words, player)
local _,_,_,teamToKill,_ = Spring.GetPlayerInfo(player)
local unitsToKill = Spring.GetTeamUnits(teamToKill)
for _,unit in pairs(unitsToKill) do
Spring.DestroyUnit(unit,true)
end
end
function gadget:Initialize()
gadgetHandler:AddChatAction("killall",Killall,"Kills all units")
gadgetHandler:AddChatAction("kill",Kill,"Kills stuff")
gadgetHandler:AddChatAction("suicide",Suicide,"Kills self")
end
--[[
function gadget:randomNumber()
local players = Spring.GetPlayerList()
local playerInfo, i = {}, 1
for index,playerID in pairs(players) do
playerInfo[i] = Spring.GetPlayerInfo(playerID)
end
end
--]]
Oddly, killall and suicide run twice and throw the error "LuaRules::RunCallIn: error = 2, RecvFromSynced, [string "LuaRules/Gadgets/failgadget.lua"]:[line number]:attempt to call field 'DestroyUnit' (a nil value)" (note that the error is only thrown once), while kill [team] only runs once. Any explanations? In case this helps, I tested this gadget by adding it to an unpacked (.sdd) version of the BA V7.11 mod archive and used /luarules reload to quickly test my changes.