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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 | --//===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!