Hello, i was three days rewriting this based on the original code(HungerGames by Fankins).
PD: Never programmed in LUA, if have errors post it.
Features:
/editor - If you need edit the map or place chests
/startround - Starts the round
/restartround - Restarts the round
*Players can only break leaves.
*You need wait the protection time end for kill.
*If you die you have to wait until the round ends to enter again.
In the first load the plugin make a archive "Config.ini" there you can edit the times, chests, spawns, etc.
Group permissions: survivalgames.start, survivalgames.restart, survivalgames.editor.
Configuration:
[General]
(Timers on tick, default recommended)
BeforeTime=3505
StartTime=605
ProtectionTime=605
EndTime=12000
(MÃnimum players for start the game)
MinPlayers=3
(Number of chests on the map)
MaxChests=3
(Default spawn, before start the game and also end)
SpawnX=0
SpawnY=64
SpawnZ=0
(Spawn position for each player)
[Spawn]
X=0
Y=64
Z=0
(Position for each chest)
[Chest]
X=0
Y=64
Z=0
Installation:
Make a folder with the name "SurvivalGames" and paste the survivalgames.lua into.
Edit the file "settings.ini" from the server and add the line "Plugins=SurvivalGames" on "[Plugins]".
Source:
Download source: SurvivalGames
Original code: HungerGames
Sorry for my english... enjoy!
PD: Never programmed in LUA, if have errors post it.
Features:
/editor - If you need edit the map or place chests
/startround - Starts the round
/restartround - Restarts the round
*Players can only break leaves.
*You need wait the protection time end for kill.
*If you die you have to wait until the round ends to enter again.
In the first load the plugin make a archive "Config.ini" there you can edit the times, chests, spawns, etc.
Group permissions: survivalgames.start, survivalgames.restart, survivalgames.editor.
Configuration:
[General]
(Timers on tick, default recommended)
BeforeTime=3505
StartTime=605
ProtectionTime=605
EndTime=12000
(MÃnimum players for start the game)
MinPlayers=3
(Number of chests on the map)
MaxChests=3
(Default spawn, before start the game and also end)
SpawnX=0
SpawnY=64
SpawnZ=0
(Spawn position for each player)
[Spawn]
X=0
Y=64
Z=0
(Position for each chest)
[Chest]
X=0
Y=64
Z=0
Installation:
Make a folder with the name "SurvivalGames" and paste the survivalgames.lua into.
Edit the file "settings.ini" from the server and add the line "Plugins=SurvivalGames" on "[Plugins]".
Source:
--//===Remake by agusnat16===// ServerData = {}; ItemsIDToChest = { 280, 297, 265, 262, 266, 261, 268, 272, 260, 320, 332, 322, 267, 368, 268, 299, 300, 301, 263, 393, 358, 315, 316, 317, 319, 333, 264}; function Initialize(Plugin) --Plugin information PLUGIN = Plugin; Plugin:SetName("SurvivalGames"); Plugin:SetVersion(1); --Set Hooks cPluginManager.AddHook(cPluginManager.HOOK_WORLD_TICK, BeforeTime); cPluginManager.AddHook(cPluginManager.HOOK_WORLD_TICK, StartTime); cPluginManager.AddHook(cPluginManager.HOOK_WORLD_TICK, ProtectionTime); cPluginManager.AddHook(cPluginManager.HOOK_TICK, EndTime); cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_PLACING_BLOCK, OnPlayerPlacingBlock); cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_LEFT_CLICK, OnPlayerLeftClick); cPluginManager.AddHook(cPluginManager.HOOK_HANDSHAKE, OnHandshake); cPluginManager.AddHook(cPluginManager.HOOK_DISCONNECT, OnDisconnect); cPluginManager.AddHook(cPluginManager.HOOK_TAKE_DAMAGE, OnTakeDamage); cPluginManager.AddHook(cPluginManager.HOOK_KILLING, OnKilling); --Plugin commands ServerData.root = cRoot:Get(); PM = ServerData.root:GetPluginManager() PM:BindCommand("/restartround", "survivalgames.restart", RestartRound, " - Restart the round"); PM:BindCommand("/startround", "survivalgames.start", StartRound, " - Start the round"); PM:BindCommand("/editor", "survivalgames.editor", EditorMode, " - 1 = Activate / 0 = Desactivate"); LoadData(); MakeDatabase(); return true; end function LoadData() --Get General Settings local Folder = PLUGIN:GetLocalDirectory() .. "/Config.ini"; local Ini = cIniFile(); Ini:ReadFile(Folder); ServerData.beftime = Ini:GetValueSetI("General", "BeforeTime", 3505); ServerData.time = Ini:GetValueSetI("General", "StartTime", 605); ServerData.protime = Ini:GetValueSetI("General", "ProtectionTime", 605); ServerData.inttime = Ini:GetValueSetI("General", "EndTime", 12000); ServerData.minplayers = Ini:GetValueSetI("General", "MinPlayers", 3); ServerData.maxchests = Ini:GetValueSetI("General", "MaxChests", 3); ServerData.xspawn = Ini:GetValueSetI("General", "SpawnX", 0); ServerData.yspawn = Ini:GetValueSetI("General", "SpawnY", 64); ServerData.zspawn = Ini:GetValueSetI("General", "SpawnZ", 0); Ini:WriteFile(Folder); end function LoadChest() --Get chests positions and set the items local Folder = PLUGIN:GetLocalDirectory() .. "/Config.ini"; for i = 1, ServerData.maxchests do local Ini = cIniFile(); Ini:ReadFile(Folder); local chestx = Ini:GetValueSetI("Chest" .. i, "X", 0); local chesty = Ini:GetValueSetI("Chest" .. i, "Y", 64); local chestz = Ini:GetValueSetI("Chest" .. i, "Z", 0); Ini:WriteFile(Folder); ServerData.root:GetDefaultWorld():DoWithChestAt(tonumber(chestx), tonumber(chesty), tonumber(chestz), function (a_ChestEntity) a_ChestEntity:SetSlot(math.random(27), cItem(ItemsIDToChest[math.random(27)])); end ); end end function LoadSpawn() local SpawnPlayers = function(Player) for i = 0, ServerData.ptotal do local Folder = PLUGIN:GetLocalDirectory() .. "/Config.ini"; local Ini = cIniFile(); Ini:ReadFile(Folder); local spawnx = Ini:GetValueSetI("Spawn" .. i, "X", 0); local spawny = Ini:GetValueSetI("Spawn" .. i, "Y", 64); local spawnz = Ini:GetValueSetI("Spawn" .. i, "Z", 0); Ini:WriteFile(Folder); Player:TeleportToCoords(tonumber(spawnx),tonumber(spawny),tonumber(spawnz)); Player:Heal(100); Player:SetFoodLevel(20); local Inventory = Player:GetInventory(); Inventory:Clear(); Inventory:AddItem(cItem(297, 2)); Inventory:AddItem(cItem(268)); end end ServerData.root:ForEachPlayer(SpawnPlayers); end function BeforeTime() if not(CanBefore) then ServerData.beftime = ServerData.beftime - 1; if (ServerData.beftime == 3500) then ServerData.root:BroadcastChat(cChatColor.LightGray .. "[".. cChatColor.Rose .. "SG".. cChatColor.LightGray .. "]".. cChatColor.Yellow .. " 3 minutes before the start of the game."); end if (ServerData.beftime == 2400) then ServerData.root:BroadcastChat(cChatColor.LightGray .. "[".. cChatColor.Rose .. "SG".. cChatColor.LightGray .. "]".. cChatColor.Yellow .. " 2 minutes before the start of the game."); end if (ServerData.beftime == 1200) then ServerData.root:BroadcastChat(cChatColor.LightGray .. "[".. cChatColor.Rose .. "SG".. cChatColor.LightGray .. "]".. cChatColor.Yellow .. " 1 minute before the start of the game."); end if (ServerData.beftime == 600) then ServerData.root:BroadcastChat(cChatColor.LightGray .. "[".. cChatColor.Rose .. "SG".. cChatColor.LightGray .. "]".. cChatColor.Yellow .. " 30 seconds before the start of the game."); end if (ServerData.beftime == 0) then --Check if have required players if (ServerData.ptotal <= ServerData.minplayers) then ServerData.root:BroadcastChat(cChatColor.LightGray .. "[".. cChatColor.Rose .. "SG".. cChatColor.LightGray .. "]".. cChatColor.LightBlue .. " Waiting for players."); else ServerData.root:BroadcastChat(cChatColor.LightGray .. "[".. cChatColor.Rose .. "SG".. cChatColor.LightGray .. "]".. cChatColor.Blue .. " Waiting for players."); CanBefore = true; end end end end function StartTime() if (CanBefore) then ServerData.time = ServerData.time - 1; if not(CanMoving) then LoadSpawn(); end if (ServerData.time == 600) then ServerData.root:BroadcastChat(cChatColor.LightGray .. "[".. cChatColor.Rose .. "SG".. cChatColor.LightGray .. "]".. cChatColor.Yellow .. " 30 seconds for start the game."); end if (ServerData.time == 400) then ServerData.root:BroadcastChat(cChatColor.LightGray .. "[".. cChatColor.Rose .. "SG".. cChatColor.LightGray .. "]".. cChatColor.Yellow .. " 20 seconds for start the game."); end if (ServerData.time == 200) then ServerData.root:BroadcastChat(cChatColor.LightGray .. "[".. cChatColor.Rose .. "SG".. cChatColor.LightGray .. "]".. cChatColor.Yellow .. " 10 seconds for start the game."); end if (ServerData.time == 100) then ServerData.root:BroadcastChat(cChatColor.LightGray .. "[".. cChatColor.Rose .. "SG".. cChatColor.LightGray .. "]".. cChatColor.Yellow .. " 5 seconds for start the game."); end if (ServerData.time == 80) then ServerData.root:BroadcastChat(cChatColor.LightGray .. "[".. cChatColor.Rose .. "SG".. cChatColor.LightGray .. "]".. cChatColor.Yellow .. " 4 seconds for start the game."); end if (ServerData.time == 60) then ServerData.root:BroadcastChat(cChatColor.LightGray .. "[".. cChatColor.Rose .. "SG".. cChatColor.LightGray .. "]".. cChatColor.Yellow .. " 3 seconds for start the game."); end if (ServerData.time == 40) then ServerData.root:BroadcastChat(cChatColor.LightGray .. "[".. cChatColor.Rose .. "SG".. cChatColor.LightGray .. "]".. cChatColor.Yellow .. " 2 seconds for start the game."); end if (ServerData.time == 20) then ServerData.root:BroadcastChat(cChatColor.LightGray .. "[".. cChatColor.Rose .. "SG".. cChatColor.LightGray .. "]".. cChatColor.Yellow .. " 1 seconds for start the game."); end if (ServerData.time == 5) then ServerData.root:BroadcastChat(cChatColor.LightGray .. "[".. cChatColor.Rose .. "SG".. cChatColor.LightGray .. "]".. cChatColor.LightBlue .. " The game start, keep alive!"); CanMoving = true; LoadChest(); end end end function ProtectionTime() if (CanMoving and CanBefore) then ServerData.protime = ServerData.protime - 1; if (ServerData.protime == 600) then ServerData.root:BroadcastChat(cChatColor.LightGray .. "[".. cChatColor.Rose .. "SG".. cChatColor.LightGray .. "]".. cChatColor.LightBlue .. " 30 second protection."); end if (ServerData.protime == 400) then ServerData.root:BroadcastChat(cChatColor.LightGray .. "[".. cChatColor.Rose .. "SG".. cChatColor.LightGray .. "]".. cChatColor.LightBlue .. " 20 second protection."); end if (ServerData.protime == 200) then ServerData.root:BroadcastChat(cChatColor.LightGray .. "[".. cChatColor.Rose .. "SG".. cChatColor.LightGray .. "]".. cChatColor.LightBlue .. " 10 second protection."); end if (ServerData.protime == 100) then ServerData.root:BroadcastChat(cChatColor.LightGray .. "[".. cChatColor.Rose .. "SG".. cChatColor.LightGray .. "]".. cChatColor.LightBlue .. " 5 second protection."); end if (ServerData.protime == 80) then ServerData.root:BroadcastChat(cChatColor.LightGray .. "[".. cChatColor.Rose .. "SG".. cChatColor.LightGray .. "]".. cChatColor.LightBlue .. " 4 second protection."); end if (ServerData.protime == 60) then ServerData.root:BroadcastChat(cChatColor.LightGray .. "[".. cChatColor.Rose .. "SG".. cChatColor.LightGray .. "]".. cChatColor.LightBlue .. " 3 second protection."); end if (ServerData.protime == 40) then ServerData.root:BroadcastChat(cChatColor.LightGray .. "[".. cChatColor.Rose .. "SG".. cChatColor.LightGray .. "]".. cChatColor.LightBlue .. " 2 second protection."); end if (ServerData.protime == 20) then ServerData.root:BroadcastChat(cChatColor.LightGray .. "[".. cChatColor.Rose .. "SG".. cChatColor.LightGray .. "]".. cChatColor.LightBlue .. " 1 second protection."); end if (ServerData.protime == 0) then ServerData.root:BroadcastChat(cChatColor.LightGray .. "[".. cChatColor.Rose .. "SG".. cChatColor.LightGray .. "]".. cChatColor.LightBlue .. " Time protection ended!"); CanKill = true; end end end function EndTime() --Refresh the players online ServerData.ptotal = ServerData.root:GetServer():GetNumPlayers(); if (CanMoving and CanBefore and CanKill) then ServerData.inttime = ServerData.inttime - 1; if (ServerData.inttime == 6000) then ServerData.root:BroadcastChat(cChatColor.LightGray .. "[".. cChatColor.Rose .. "SG".. cChatColor.LightGray .. "]".. cChatColor.Gold .. " 5 minutes before the end of the round."); end if (ServerData.inttime == 3600) then ServerData.root:BroadcastChat(cChatColor.LightGray .. "[".. cChatColor.Rose .. "SG".. cChatColor.LightGray .. "]".. cChatColor.Gold .. " 3 minutes before the end of the round."); end if (ServerData.inttime == 1200) then ServerData.root:BroadcastChat(cChatColor.LightGray .. "[".. cChatColor.Rose .. "SG".. cChatColor.LightGray .. "]".. cChatColor.Gold .. " 1 minutes before the end of the round."); end if (ServerData.inttime == 200) then ServerData.root:BroadcastChat(cChatColor.LightGray .. "[".. cChatColor.Rose .. "SG".. cChatColor.LightGray .. "]".. cChatColor.Gold .. " 10 seconds before the end of the round."); end if (ServerData.inttime == 100) then ServerData.root:BroadcastChat(cChatColor.LightGray .. "[".. cChatColor.Rose .. "SG".. cChatColor.LightGray .. "]".. cChatColor.Gold .. " 5 seconds before the end of the round."); end if (ServerData.inttime == 80) then ServerData.root:BroadcastChat(cChatColor.LightGray .. "[".. cChatColor.Rose .. "SG".. cChatColor.LightGray .. "]".. cChatColor.Gold .. " 4 seconds before the end of the round."); end if (ServerData.inttime == 60) then ServerData.root:BroadcastChat(cChatColor.LightGray .. "[".. cChatColor.Rose .. "SG".. cChatColor.LightGray .. "]".. cChatColor.Gold .. " 3 seconds before the end of the round."); end if (ServerData.inttime == 40) then ServerData.root:BroadcastChat(cChatColor.LightGray .. "[".. cChatColor.Rose .. "SG".. cChatColor.LightGray .. "]".. cChatColor.Gold .. " 2 seconds before the end of the round."); end if (ServerData.inttime == 20) then ServerData.root:BroadcastChat(cChatColor.LightGray .. "[".. cChatColor.Rose .. "SG".. cChatColor.LightGray .. "]".. cChatColor.Gold .. " 1 second before the end of the round."); end if (ServerData.inttime == 0) then ServerData.root:BroadcastChat(cChatColor.LightGray .. "[".. cChatColor.Rose .. "SG".. cChatColor.LightGray .. "]".. cChatColor.Red .. " The game end, restarting."); RestartRound(); end end end function RestartRound() --Reset variables for Restart the round local SpawnPlayers = function(OtherPlayer) OtherPlayer:GetInventory():Clear(); OtherPlayer:TeleportToCoords(ServerData.xspawn, ServerData.yspawn, ServerData.zspawn); end ServerData.root:ForEachPlayer(SpawnPlayers); ServerData.root:BroadcastChat(cChatColor.LightGray .. "[".. cChatColor.Rose .. "SG".. cChatColor.LightGray .. "]".. cChatColor.LightGreen .. " Round restarted."); ServerData.beftime = 3505; ServerData.time = 605; ServerData.protime = 605; ServerData.inttime = 12000; CanBefore = false; CanMoving = false; CanKill = false; RegenerateBlocks(); return true; end function StartRound() --Set variables for Start the round if not(CanBefore) then ServerData.root:BroadcastChat(cChatColor.LightGray .. "[".. cChatColor.Rose .. "SG".. cChatColor.LightGray .. "]".. cChatColor.LightGreen .. " Round started."); ServerData.time = 105; ServerData.protime = 605; CanBefore = true; end return true; end function CheckWinner() --Check if any win if (CanBefore and ServerData.ptotal <= 1) then ServerData.Winner = "Unknown"; local ScanWinner = function(OtherPlayer) ServerData.Winner = OtherPlayer:GetName(); end ServerData.root:ForEachPlayer(ScanWinner) ServerData.root:BroadcastChat(cChatColor.LightGray .. "[".. cChatColor.Rose .. "SG".. cChatColor.LightGray .. "]".. cChatColor.Yellow .. " Congratulations to the winner of the nickname: ".. cChatColor.LightBlue .. ServerData.Winner .."".. cChatColor.Yellow .. "!!!"); ServerData.root:BroadcastChat(cChatColor.LightGray .. "[".. cChatColor.Rose .. "SG".. cChatColor.LightGray .. "]".. cChatColor.Rose .. " Survival games over!" ); RestartRound(); end end function OnTakeDamage(Receiver, TDI) --Only kill if the game start if not(CanKill) then return true; else if (TDI.FinalDamage <=1) then TDI.FinalDamage=TDI.FinalDamage*math.random(1, 2); end TDI.FinalDamage = TDI.FinalDamage/math.random(2, 3); end end function OnKilling(Victim, Killer) --Thunder on the dead player and broadcast if (Victim:IsPlayer()) then local PlayerPos = Victim:GetPosition(); Victim:GetWorld():CastThunderbolt(PlayerPos.x, PlayerPos.y, PlayerPos.z); ServerData.ptotal = ServerData.ptotal - 1; ServerData.root:BroadcastChat(cChatColor.LightGray .. "[".. cChatColor.Rose .. "SG".. cChatColor.LightGray .. "]".. cChatColor.Yellow .. " The remaining ".. ServerData.ptotal .." players."); local ClientHandle = Victim:GetClientHandle(); ClientHandle:Kick("You are dead!"); CheckWinner(); end end function OnDisconnect(Player) --Broadcast disconnected player if (CanBefore) then ServerData.ptotal = ServerData.ptotal - 1; ServerData.root:BroadcastChat(cChatColor.LightGray .. "[".. cChatColor.Rose .. "SG".. cChatColor.LightGray .. "]".. cChatColor.Yellow .. " The remaining ".. ServerData.ptotal .." players."); CheckWinner(); end end function OnHandshake(ClientHandle, UserName) local loopPlayers = function(Player) if (Player:GetName() == UserName) then ClientHandle:Kick("The user is already connected!"); return true; end end local loopWorlds = function (World) World:ForEachPlayer(loopPlayers); end ServerData.root:ForEachWorld(loopWorlds); --Dont join if the game started if (CanBefore) then ClientHandle:Kick("Wait until the game ends!"); return true; end end function OnPlayerPlacingBlock(Player) if not(EdtitorMode) then return true; end end function EditorMode(Split,Player) if (Split[2] == "1") then EdtitorMode = true; Player:SendMessage(cChatColor.LightGreen .. "Editor mode activated."); end if (Split[2] == "0") then EdtitorMode= false; Player:SendMessage(cChatColor.Red .. "Editor mode desactivated."); end return true; end --SQLITE function OnPlayerLeftClick(Player, BlockX, BlockY, BlockZ, BlockFace, Status, BlockMeta) if not(EdtitorMode) then local Blocks = {}; Blocks.world = Player:GetWorld(); Blocks.name = Blocks.world:GetName(); Blocks.type = Blocks.world:GetBlock(BlockX, BlockY, BlockZ); if (Blocks.type == E_BLOCK_LEAVES and CanBefore) then Blocks.sqlx = tonumber(BlockX); Blocks.sqly = tonumber(BlockY); Blocks.sqlz = tonumber(BlockZ); Blocks.pname = Player:GetName(); local TestDB, ErrCode, ErrMsg = sqlite3.open("survival.sqlite"); local sql = "INSERT INTO BlocksBroken (x, y, z, BF, BT, BM, WorldName, Owner) VALUES ('" .. Blocks.sqlx .. "', '" .. Blocks.sqly .. "', '" .. Blocks.sqlz .. "', '".. BlockFace .."', '".. Blocks.type .."', '".. Blocks.world:GetBlockMeta(BlockX, BlockY, BlockZ) .."', '".. Blocks.name .."', '".. Blocks.pname .."');"; local Res = TestDB:exec(sql, ShowRow, 'UserData'); if (Res ~= sqlite3.OK) then LOG("TestDB:exec() failed: " .. Res .. " (" .. TestDB:errmsg() .. ")"); end; TestDB:close(); return false; else return true; end end end function MakeDatabase() local TestDB, ErrCode, ErrMsg = sqlite3.open("survival.sqlite"); local sql = "CREATE TABLE IF NOT EXISTS BlocksBroken(x, y, z, BF, BT, BM, WorldName, Owner)" local Res = TestDB:exec(sql, ShowRow, 'UserData'); if (Res ~= sqlite3.OK) then LOG("TestDB:exec() failed: " .. Res .. " (" .. TestDB:errmsg() .. ")"); end; TestDB:close(); end function RegenerateBlocks() local Blocks = {}; Blocks.world = ServerData.root:GetDefaultWorld(); Blocks.name = Blocks.world:GetName(); Blocks.blocks = 0; local TestDB, ErrCode, ErrMsg = sqlite3.open("survival.sqlite"); local function ShowRow(UserData, NumCols, Values, Names) Blocks.blocks = Values[1]; end local sql = "SELECT COUNT(*) FROM BlocksBroken"; local Res = TestDB:exec(sql, ShowRow, 'UserData'); for i = 1, Blocks.blocks do local sqls = "SELECT * FROM BlocksBroken WHERE (rowid = '" .. i .. "')"; local function Parser(UserData, NumValues, Values, Names) Blocks.removedx = Values[1]; Blocks.removedy = Values[2]; Blocks.removedz = Values[3]; Blocks.removebf = Values[4]; Blocks.removedbt = Values[5]; Blocks.removedbm = Values[6]; end if (not(TestDB:exec(sqls, Parser))) then return false; end Blocks.world:FastSetBlock(Blocks.removedx, Blocks.removedy, Blocks.removedz, Blocks.removedbt, Blocks.removedbm); local sqlr = "DELETE FROM BlocksBroken WHERE (x = '" .. Blocks.removedx .. "') AND (y ='" .. Blocks.removedy .. "') AND (z ='" .. Blocks.removedz .. "') AND (WorldName ='" .. Blocks.name .. "')"; local Res = TestDB:exec(sqlr, ShowRow, 'UserData'); if (Res ~= sqlite3.OK) then LOG("TestDB:exec() failed: " .. Res .. " (" .. TestDB:errmsg() .. ")"); end; end TestDB:close(); end
Download source: SurvivalGames
Original code: HungerGames
Sorry for my english... enjoy!