if (g_arena == nil) then g_arena = nil g_GameTime = nil -- To store team Build Points g_BuildPoints = { } g_BuildPoints["Collective Navy"] = 500 g_BuildPoints["Titan Navy"] = 500 -- To keep track of transactions g_Transactions = { } g_Transactions["Collective Navy"] = { } g_Transactions["Titan Navy"] = { } -- For wormholes to work g_CollectiveWormholeAlpha = { false, nil } g_CollectiveWormholeBeta = { false, nil } g_TitanWormholeAlpha = { false, nil } g_TitanWormholeBeta = { false, nil } -- To keep track of the last time a player withdrew Build Points g_PlayerGetTimes = { } end function Reload() dofile("../Fleet_Resources/fleet2.lua") end -- Player statistics for each game -- 1 = kills -- 2 = deaths -- 3 = eljacium asteroids harvested -- 4 = resource deposited -- 5 = vehicles destroyed -- 6 = structures destroyed -- 7 = resources withdrawn -- How do I know when the game has ended? For now I'll display the last games stats when this game begins function PlayerBreakdown(player) player:message("Breakdown of Statistics:") player:message("Total Game Time: " .. os.time() - g_GameTime .. " seconds") player:message("! Kills: " .. player:getStat(1)) player:message("! Deaths: " .. player:getStat(2)) player:message("! Asteroids Harvested: " .. player:getStat(3)) player:message("! Resource Efficiency: " .. (player:getStat(4) - player:getStat(7))) player:message("! Capitals Destroyed: " .. player:getStat(5)) player:message("! Structures Destroyed: " .. player:getStat(6)) end function Arena_OnCreate(arena) g_arena = arena math.randomseed(os.time()) end function Player_OnJoin(player) player:message("Welcome to Fleet " .. player.m_name .. "") InitialisePlayerStats(player) RemovePlayerBuildPoints(player) end function Msg_OnCommand(player, command, payload, recipient, msg_type) if ((command == "?give") and (player:spectator() == false) and (payload ~= "") and (tonumber(payload) ~= nil)) then local amount = player:inventory_find("Build Points") payload = tonumber(payload) if (amount <= 0) then player:message("You have no Build Points to deposit") return elseif (payload > amount) then player:message("You do not have that many Build Points to deposit") return elseif (payload > 0) then player:message("" .. payload .. " Build Points deposited for the " .. player:getTeam().m_name .. ", there are now " .. (g_BuildPoints[player:getTeam().m_name] + payload) .. " deposited.") player:inventory_modify("Build Points",-payload) g_BuildPoints[player:getTeam().m_name] = g_BuildPoints[player:getTeam().m_name] + payload table.insert( g_Transactions[player:getTeam().m_name], "" .. command .. " " .. payload .. " - " .. player.m_name .."" ) player:setStat(4, player:getStat(4) + payload) return end elseif ((command == "?give") and (player:spectator() == false) and (payload == "")) then local amount = player:inventory_find("Build Points") if (amount > 0) then player:message("" .. amount .. " Build Points deposited for the " .. player:getTeam().m_name .. ", there are now " .. (g_BuildPoints[player:getTeam().m_name] + amount) .. " deposited.") player:inventory_modify("Build Points",-amount) g_BuildPoints[player:getTeam().m_name] = g_BuildPoints[player:getTeam().m_name] + amount table.insert( g_Transactions[player:getTeam().m_name], "" .. command .. " " .. amount .. " - " .. player.m_name .."" ) player:setStat(4, player:getStat(4) + amount) return end elseif ((command == "?get") and (player:spectator() == false) and (payload ~= "") and (tonumber(payload) ~= nil)) then local amountFree = g_BuildPoints[player:getTeam().m_name] payload = tonumber(payload) if (amountFree <= 0) then player:message("Your team has no Build Points") return elseif (payload > amountFree) then player:message("Your team does not have this many Build Points, there are currently " .. g_BuildPoints[player:getTeam().m_name] .. " deposited") return elseif ((payload >= 50) and (payload <= 2200)) then if ( g_PlayerGetTimes[player.m_name] == nil ) then g_PlayerGetTimes[player.m_name] = os.time() elseif ( (os.time() - g_PlayerGetTimes[player.m_name]) < 20 ) then local seconds = (os.time() - g_PlayerGetTimes[player.m_name]) player:message("You're attempting to withdraw Build Points too quick, please wait another " .. (20-seconds) .. " seconds") return else g_PlayerGetTimes[player.m_name] = os.time() end player:message("" .. payload .. " Build Points withdrawn from the " .. player:getTeam().m_name .. ", there are now " .. (g_BuildPoints[player:getTeam().m_name] - payload) .. " deposited.") g_BuildPoints[player:getTeam().m_name] = g_BuildPoints[player:getTeam().m_name] - payload player:inventory_modify("Build Points",payload) table.insert( g_Transactions[player:getTeam().m_name], "" .. command .. " " .. payload .. " - " .. player.m_name .."" ) player:setStat(7, player:getStat(7) + payload) elseif (payload > 2200) then player:message("You are only allowed to withdraw up to 2200 BP") elseif (payload < 50) then player:message("You are only allowed to withdraw a minimum of 50 BP") end elseif ((command == "?get") and (player:spectator() == false) and (payload == "")) then local amountFree = g_BuildPoints[player:getTeam().m_name] if (amountFree >= 50) then if ( g_PlayerGetTimes[player.m_name] == nil ) then g_PlayerGetTimes[player.m_name] = os.time() elseif ( (os.time() - g_PlayerGetTimes[player.m_name]) < 20 ) then local seconds = (os.time() - g_PlayerGetTimes[player.m_name]) player:message("You're attempting to withdraw Build Points too quick, please wait another " .. (20-seconds) .. " seconds") return else g_PlayerGetTimes[player.m_name] = os.time() end player:message("" .. 50 .. " Build Points withdrawn from the " .. player:getTeam().m_name .. ", there are now " .. (g_BuildPoints[player:getTeam().m_name] - 50) .. " deposited.") g_BuildPoints[player:getTeam().m_name] = g_BuildPoints[player:getTeam().m_name] - 50 player:inventory_modify("Build Points",50) table.insert( g_Transactions[player:getTeam().m_name], "" .. command .. " " .. 50 .. " - " .. player.m_name .."" ) player:setStat(7, player:getStat(7) + 50) end elseif ((command == "?history") and (player:spectator() == false)) then local total = table.getn( g_Transactions[player:getTeam().m_name] ) if (total > 9) then for i = total-9, total do player:message("*" .. g_Transactions[player:getTeam().m_name][i] .. "") end else for i = 1, total do player:message("*" .. g_Transactions[player:getTeam().m_name][i] .. "") end end elseif ((command == "?resources") and (player:spectator() == false)) then player:message("" .. g_BuildPoints[player:getTeam().m_name] .. " Build Points currently stored") elseif (command == "?view") then local target = g_arena:getPlayer(recipient) if (target:valid() == true) then if (player:getTeam().m_name == target:getTeam().m_name) then player:message("*" .. target.m_name .. " has " .. target:inventory_find("Build Points") .. " Build Points") end end elseif (command == "?viewall") then local team = player:getTeam().m_name for i = 1, g_arena:num() do local target = g_arena:get(i) if ((target:getTeam().m_name == team) and (target:inventory_find("Build Points") >= 200) and (player.m_name ~= target.m_name)) then player:message("*" .. target.m_name .. " has " .. target:inventory_find("Build Points") .. " Build Points") end end elseif (command == "?breakdown") then PlayerBreakdown(player) end end function Vehicle_OnDeath(vehicle, killer) local vid = nil vid = vehicle:vehicletypeid() if (vid == nil) then return true elseif (vid == 417) then c = vehicle:coords() local numOres = math.random(4,8) for i = 1, numOres do local xChange = math.random(-300, 300) local yChange = math.random(-300, 300) g_arena:item_create("Eljaycium Ore",1,(xChange + c.x),(yChange + c.y)) end if (killer:valid() == true) then killer:setStat(3, killer:getStat(3) + 1) end elseif (vid == 418) then -- Collective Wormhole Alpha g_CollectiveWormholeAlpha = { false, nil } if (killer:valid() == true) then killer:setStat(6, killer:getStat(6) + 1) end elseif (vid == 420) then -- Collective Wormhole Beta g_CollectiveWormholeBeta = { false, nil } if (killer:valid() == true) then killer:setStat(6, killer:getStat(6) + 1) end elseif (vid == 419) then -- Titan Wormhole Alpha g_TitanWormholeAlpha = { false, nil } if (killer:valid() == true) then killer:setStat(6, killer:getStat(6) + 1) end elseif (vid == 421) then -- Titan Wormhole Beta g_TitanWormholeBeta = { false, nil } if (killer:valid() == true) then killer:setStat(6, killer:getStat(6) + 1) end elseif ( (vid == 108) or (vid == 107) or (vid == 111) or (vid == 113) or (vid == 101) or (vid == 104) or (vid == 115) or (vid == 112) or (vid == 110) ) then --Collie cap ship destroyed if (killer:valid() == true) then killer:setStat(5, killer:getStat(5) + 1) end elseif ( (vid == 114) or (vid == 207) or (vid == 108) or (vid == 211) or (vid == 201) or (vid == 204) or (vid == 109) or (vid == 209) or (vid == 213) or (vid == 210) ) then --Titan cap ship destroyed if (killer:valid() == true) then killer:setStat(5, killer:getStat(5) + 1) end elseif ( (vid == 401) or (vid == 409) or (vid == 400) or (vid == 403) or (vid == 405) or (vid == 413) or (vid == 415) or (vid == 404) ) then --Collie base structure destroyed if (killer:valid() == true) then killer:setStat(6, killer:getStat(6) + 1) end elseif ( (vid == 411) or (vid == 406) or (vid == 407) or (vid == 408) or (vid == 410) or (vid == 414) or (vid == 416) or (vid == 412) ) then --Titan base structure destroyed if (killer:valid() == true) then killer:setStat(6, killer:getStat(6) + 1) end end return true end function On_FlagGameStart() g_BuildPoints["Collective Navy"] = 500 g_BuildPoints["Titan Navy"] = 500 g_Transactions["Collective Navy"] = { } g_Transactions["Titan Navy"] = { } g_CollectiveWormholeAlpha = { false, nil } g_CollectiveWormholeBeta = { false, nil } g_TitanWormholeAlpha = { false, nil } g_TitanWormholeBeta = { false, nil } g_PlayerGetTimes = { } g_GameTime = os.time() --// Clear Stats for i = 1, g_arena:num() do local player = g_arena:get(i) InitialisePlayerStats(player) if (player:spectator() == true) then RemovePlayerBuildPoints(player) end end end function Player_OnDeath(killer, victim) if (victim:valid() == true) then local amount = victim:inventory_find("Eljaycium Ore") if (amount >= 1) then local c = victim:coords() victim:inventory_modify("Eljaycium Ore",-amount) g_arena:item_create("Eljaycium Ore",amount,c.x,c.y) end end -- Increase number of deaths victim:setStat(2, victim:getStat(2) + 1) -- Increase number of kills if (killer:valid() == true) then if (killer.m_name ~= victim.m_name) then killer:setStat(1, killer:getStat(1) + 1) end end end function Vehicle_OnProduce(vehicle,user,menuitem) -- Produce Menu Item Reservations For Wormholes -- 13 - Collective Alpha Wormhole -- 14 - Collective Beta Wormhole -- 15 - Titan Alpha Wormhole -- 16 - Titan Beta Wormhole if (menuitem == 12) then -- Collective Alpha Wormhole if (g_CollectiveWormholeAlpha[1] == false) then user:message("Wormhole Activated") g_CollectiveWormholeAlpha[1] = true g_CollectiveWormholeAlpha[2] = user:coords() return false else if (g_CollectiveWormholeBeta[1] == false) then user:message("The other end of this wormhole is inactive or unstable") return false else local playerc = user:coords() g_arena:explosion_create("WarpEffectIn",playerc.x, playerc.y, 1) local c = g_CollectiveWormholeBeta[2] user:warp(c.x, c.y, 50) return true end end elseif (menuitem == 13) then -- Collective Beta Wormhole if (g_CollectiveWormholeBeta[1] == false) then user:message("Wormhole Activated") g_CollectiveWormholeBeta[1] = true g_CollectiveWormholeBeta[2] = user:coords() return false else if (g_CollectiveWormholeAlpha[1] == false) then user:message("The other end of this wormhole is inactive or unstable") return false else local playerc = user:coords() g_arena:explosion_create("WarpEffectIn",playerc.x, playerc.y, 1) local c = g_CollectiveWormholeAlpha[2] user:warp(c.x, c.y, 50) return true end end elseif (menuitem == 14) then -- Titan Alpha Wormhole if (g_TitanWormholeAlpha[1] == false) then user:message("Wormhole Activated") g_TitanWormholeAlpha[1] = true g_TitanWormholeAlpha[2] = user:coords() return false else if (g_TitanWormholeBeta[1] == false) then user:message("The other end of this wormhole is inactive or unstable") return false else local playerc = user:coords() g_arena:explosion_create("WarpEffectIn",playerc.x, playerc.y, 1) local c = g_TitanWormholeBeta[2] user:warp(c.x, c.y, 50) return true end end elseif (menuitem == 15) then -- Titan Beta Wormhole if (g_TitanWormholeBeta[1] == false) then user:message("Wormhole Activated") g_TitanWormholeBeta[1] = true g_TitanWormholeBeta[2] = user:coords() return false else if (g_TitanWormholeAlpha[1] == false) then user:message("The other end of this wormhole is inactive or unstable") return false else local playerc = user:coords() g_arena:explosion_create("WarpEffectIn",playerc.x, playerc.y, 1) local c = g_TitanWormholeAlpha[2] user:warp(c.x, c.y, 50) return true end end end return true end function InitialisePlayerStats(player) for i = 1, 7 do player:setStat(i, 0) end end function RemovePlayerBuildPoints(player) if (player:valid() == true) then local amount = player:inventory_find("Build Points") if (amount > 0) then player:inventory_modify("Build Points",-amount) end end end