Popup for "Pet Eggs"

So I’m sure we have all seen those pet eggs in most of the common simulator games. You walk up to them, a billboard UI appears giving information about the egg, you press a key and it opens.

Issue: Although this is probably simple I just don’t know a effective way of doing this, would making a separate billboard UI for every egg and then just find the closest egg when they press a key be effective? It seems there’s something I’m missing that would make this a whole lot easier, perhaps a element of billboard GUIs that I haven’t picked up on (I explored it on the wiki however and haven’t found anything). With my approach it would also have the issue of mobile players being unable to press a button so would I need a bunch of billboard ui’s and every one of them just changes the adornee??

5 Likes

Hey, I was the very first person to make one of these.

Most efficient way (and easiest long-term) to do this is to have a generalized read-only table that contains all the data about pets, eggs, currency, etc. Using a GridLayout, you can generate and sort GUI elements on a BillboardGui based on the data for each egg. Calculate when to draw the BillboardGui by measuring magnitude between player and egg capsule. I did my ‘button’ separately and it changes input depending on the platform the user it playing on. That’s the bulk of it.

My advice is to NOT do anything above because everyone in the world is also doing it. Do something refreshing! Spice it up a bit. :slight_smile:

11 Likes

You can have a template BillboardGui and once a player comes within a certain radius from an egg you clone the template, pull the data for that egg from a table like @BuildIntoGames mentioned, and apply that data to the cloned template. That way you only have to make one BillboardGui, and can adjust it based on the egg’s data.

Considering the layout is pretty much the same, you only need to change the text/values.

1 Like

Would that just being constantly checking the players magnitude ever frame?

Also people seem to dislike anything original :frowning: but maybe I can try something again

1 Like

Loop through all players, check for the closest egg by taking the magnitude between the player and an egg, and compare it to a set max distance. If they’re within the max distance (range) then display the BillboardGui for that egg.

1 Like

Yes. Iteratively loop through each egg capsule and check the magnitude. Pseudo code example:

while wait() do
	for _, eggCapsule in ipairs(eggCapsules:GetChildren()) do
		local magnitude = (eggCapsule.Position - player.Position).magnitude
		if(magnitude <= 8) then
			showDataForEggCapsule(eggCapsule)
			break
		end
	end
end
6 Likes

So here’s what I’m thinking: Module holds all the data from the pets
Server loops through all the players, find the magnitude of one player to be withing range, fires a event with the name of the egg

Client: Takes the event, finds the egg inside the module
Server: If player leaves range it fires a remote event to remove the ui?

Anyway is this effective or should I try something client sided

1 Like

I’d do all of this client-sided. It takes away the stress from the server.

1 Like

Did you mean loop through all eggs or am I comprehending this wrong

1 Like

The magnitude check, yes. In my first example I mixed up the words, meant to say loop through all eggs.

3 Likes