How do I make a disaster queue?

Currently I am working on a new disaster game and I want to try to keep things as clean as possible so it isn’t all a mess, and one of the things im trying to do is making it possible to queue disasters from a panel by pressing a button. I have tried to research a lot into this but I haven’t found anything that can help. I also want to make sure that if no one queues a disaster then it will choose a random disaster by default so public servers work (also making sure that every disaster has their own rarities). If I could get an idea of what I need to do then that would be great!

1 Like

If I understand what you mean correctly, a script like this should work.

local Disasters = {"Tornado","Hurricane","Earthquake","Blizzard"} --The possible disasters that could be randomly chosen.


function ChooseDisaster()
 	local ChosenDisaster = ""
 	if #Queue > 0 then --Detects if there is a queue.
 		ChosenDisaster = Queue[1]
 		table.remove(Queue,1)
 	else
	    	ChosenDisaster = Disasters[math.random(#Disasters)] --If there is no queue, it randomizes between one of the disasters in the disasters table.
 	 end
 	 print(ChosenDisaster)
end

function AddItemToQueue(item)
 	table.insert(Queue,item) --Adds an item to the queue
end
2 Likes

Sorry about the very late response but this is what im looking for but how would I make it possible to add onto the queue? Such as making the next disaster a Hurricane or a Blizzard by pressing a button so the next round it will 100% get the disaster chosen by someone with a panel.

Hi RetroDeveloper,

I’m not sure if you’re asking about how to use the code, or how to hook buttons to it. I’m also not sure what you mean by disaster rarities. Are you looking for a priority queue, where rarer disasters go first even though they enter the queue late?

If you use @Aevoeri’s code. You would simply call

AddItemToQueue(1) -- add disaster "Tornado"

You will have to follow the order of the table “Disasters”
1 for “Tornado”
2 for “Hurricane”

4 for “Blizzard”

To grab an event from the queue, or a random one if there is none, you would call

local disasterName = ChooseDisaster()
-- do stuff once you have the chosen disaster's name

For buttons, I think the simplest solution would be a ClickDetector.