Karain
Jack of all trades
Good morning/evening/afternoon ladies and gentlemen, Today you will witness my first contribution to this wonderful community (finally graduating from being a lurker.. ahem). I present to you:
HUNGER GAMES EVENT
HUNGER GAMES EVENT
Inspired from the minecraft mini-game of the same name, i've created this event back when TFS 0.4 was a thing, and after seeing some request for this event on otland, i have decided to convert it to the latest TFS 1.2 and publish it for all of you lovely users to use, modify and improve. it's time i pay back your generosities, yes?
Anyway, back on topic.
How does the game work?
Anyway, back on topic.
How does the game work?
firstly if a player decides to queue up to join the event, he'll simply type in "!join hunger games" and he'll be on the waiting list.
after a configurable amount of time and if there is enough players queued up for a round of hunger games, they will be teleported, have all their items moved safely into a configurable depot box.
on each map there will be chests that have a random chance to hold a bunch of items, the players need to find and collect items in order to survive and be the last player alive. winner gets configurable prizes, standard stuff.
Maps:
now that you have a solid idea about the event. let's get into the technicalities.
DOWNLOAD THE MAP HERE
(small note: i didn't create the maps, i've downloaded them from otland's map download section, if you are the creator of the map, please link me your download topic and you will receive full credits)
CODE:
globalevents/globalevents.xmlafter a configurable amount of time and if there is enough players queued up for a round of hunger games, they will be teleported, have all their items moved safely into a configurable depot box.
on each map there will be chests that have a random chance to hold a bunch of items, the players need to find and collect items in order to survive and be the last player alive. winner gets configurable prizes, standard stuff.
Maps:
now that you have a solid idea about the event. let's get into the technicalities.
DOWNLOAD THE MAP HERE
(small note: i didn't create the maps, i've downloaded them from otland's map download section, if you are the creator of the map, please link me your download topic and you will receive full credits)
CODE:
Code:
<globalevent type="startup" name="hunger" script="hunger.lua"/>
globalevents/scripts/hunger.lua
Code:
currentgameid = 201
killstreak = 60013
depotbox= {x=700,y=760,z=5} --location of a depot box, recommended to be accessible by players incase of bugs or crashes
game = {{name="Hunger Games Arena 1", cheststartid=60100, minplayers=8, maxplayers=16, chests=299, startpos={
{x = 814, y = 760, z = 7},
{x = 809, y = 758, z = 7},
{x = 807, y = 753, z = 7},
{x = 809, y = 748, z = 7},
{x = 814, y = 746, z = 7},
{x = 819, y = 748, z = 7},
{x = 821, y = 753, z = 7},
{x = 819, y = 758, z = 7},
{x = 811, y = 759, z = 7},
{x = 808, y = 756, z = 7},
{x = 808, y = 750, z = 7},
{x = 811, y = 747, z = 7},
{x = 817, y = 747, z = 7},
{x = 820, y = 750, z = 7},
{x = 820, y = 756, z = 7},
{x = 817, y = 759, z = 7}
}
},
{
name="Hunger Games Arena 2", cheststartid=61100, minplayers=2, maxplayers=4, chests=299, startpos={
{x = 1036, y = 910, z = 6},
{x = 1032, y = 906, z = 6},
{x = 1036, y = 902, z = 6},
{x = 1040, y = 906, z = 6}
}
},
{
name="Hunger Games Arena 3", cheststartid=62100, minplayers=4, maxplayers=8, chests=299, startpos={
{x = 1047, y = 1158, z = 7},
{x = 1048, y = 1158, z = 7},
{x = 1052, y = 1158, z = 7},
{x = 1053, y = 1158, z = 7},
{x = 1047, y = 1167, z = 7},
{x = 1048, y = 1167, z = 7},
{x = 1052, y = 1167, z = 7},
{x = 1053, y = 1167, z = 7}
}
}
}
availablearenas = {1,2,3} -- script starts with all arenas as "available"
gameplayers = {}
prize = {{2160,1},{5097,10},{2128,1}}
function Player:removeAllItems() -- function to clear the player's inventory
local depotpos = Tile(Position(depotbox.x, depotbox.y, depotbox.z)):getItemByType(ITEM_TYPE_DEPOT)
local depotid = getDepotId(depotpos:getUniqueId())
local depot = self:getDepotChest(depotid,true)
local box = depot:addItem(1988)
box:setAttribute(ITEM_ATTRIBUTE_NAME,"player gear box")
for i=1,10 do
local item = self:getSlotItem(i)
if item then
item:moveTo(box)
end
end
end
function Player:getBackItems() -- function to clear the player's inventory
local depotpos = Tile(Position(depotbox.x, depotbox.y, depotbox.z)):getItemByType(ITEM_TYPE_DEPOT)
local depotid = getDepotId(depotpos:getUniqueId())
local depot = self:getDepotChest(depotid,true)
local box = depot:getItem(0)
for i= box:getSize()-1, 0, -1 do
local item = box:getItem(i)
if item then
item:clone():moveTo(self)
end
end
box:remove()
end
local function teleportThing(seconds)
if seconds <= 0 and #queue >= 1 then
local looparenas = availablearenas -- preventing possible conflicts with looping
for a,b in pairs(looparenas) do
if #queue >= game[looparenas[a]].minplayers then
local p = 1
while p < game[looparenas[a]].maxplayers do
for i, pname in pairs(queue) do
local player = Player(pname)
if player then
player:setStorageValue(currentgameid, looparenas[a])
local pos = Position(game[looparenas[a]].startpos[p].x, game[looparenas[a]].startpos[p].y, game[looparenas[a]].startpos[p].z)
player:teleportTo(pos)
player:removeAllItems()
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Welcome to The Hunger Games, Your objective is to loot, kill and be the last man standing, Good luck!")
if gameplayers[looparenas[a]] == nil then
gameplayers[looparenas[a]] = {}
end
table.insert(gameplayers[looparenas[a]], player:getName())
table.remove(queue,i)
end
end
p = p+1
end
for i = game[looparenas[a]].cheststartid, game[looparenas[a]].cheststartid+game[looparenas[a]].chests do
Game.setStorageValue(i, -1)
end
Game.broadcastMessage(MESSAGE_EVENT_ADVANCE,"Hunger Games started in " ..game[looparenas[a]].name.."!")
for k,v in pairs(availablearenas) do
if v == r then
table.remove(availablearenas,i)
end
end
else
for _, player in pairs(queue) do
Player(player):sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Sorry, There is not enough players to start "..game[availablearenas[a]].name)
end
end
end
return teleportThing(3600)
end
if seconds == 60 then
for _, player in pairs(queue) do
Player(player):sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "The Hunger Games will begin in " .. seconds/60 .. " minute, Get Ready!")
end
elseif seconds % 60 == 0 and seconds ~= 60 and seconds ~= 300 and seconds < 300 then
for _, player in pairs(queue) do
Player(player):sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "The Hunger Games will begin in " .. seconds/60 .. " minutes!")
end
elseif seconds == 300 then
Game.broadcastMessage(MESSAGE_EVENT_ADVANCE,"The Hunger Games will begin in " .. seconds/60 .. " minutes! To join say /join hunger games")
end
if seconds ~= 0 then
addEvent(teleportThing, 60000, seconds - 60)
end
return true
end
function onStartup()
teleportThing(600)
return true
end
Last edited: