Cuberite Forum

Full Version: Lua Challenge: the Catastrophes plugin
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6 7 8 9 10
I'm open to everything, but one thing I'll do for sure is acid rain (it's not a natural disaster but I want to do it)
One question: When using ForEachPlayer, what players are looped first? Is it random?
If it isnt, anyway to choose a random player fastly and easily?
Also, is there anyway to get a random x, y, z in a loaded chunk without loading it? (Only random between loaded chunks)
I'm guessing it's in the order the player's joined.

What you can do is get the number of players, create a random number between 0 and that number, and then take player <nr> from that number.
-- NumPlayers is for example 10
local RandomPlayer = math.random(NumPlayers)
local CurrentPlayer = 0
World:ForEachPlayer(
   function()
      CurrentPlayer = CurrentPlayer + 1
      if (CurrentPlayer == RandomPlayer) then
         --- Do things
         return true -- we did what we wanted with the player
      end
   end
)

Get a random x, y, z in a loaded chunk without loading it? Whut? Assuming you meant unloaded chunk. Can't you just use:
local X = math.random(15)
local Y = math.random(255)
local Z = math.random(15)
(05-22-2015, 02:46 AM)NiLSPACE Wrote: [ -> ]
Get a random x, y, z in a loaded chunk without loading it? Whut? Assuming you meant unloaded chunk. Can't you just use:
local X = math.random(15)
local Y = math.random(255)
local Z = math.random(15)
I meant getting random coordinates only inside loaded chunks
The only method that might work is cWorld:TryGetHeight. With that you can check if a chunk is loaded.
I suppose it's kinda working:
[Image: fd1318402c.jpg]

TOO MUCH!
[Image: 93d2f7d0f0.jpg]
There's currently no cWorld:ForEachChunk() API function which would help you, but it shouldn't be too difficult to add it.
Apache License 2.0 is allowed right?
That moment when you realize you are really cruel for the villagers:
[Image: e1f05996dc.jpg]

It really killed the performance though:
[Image: 7576860bde.png]

I'll have to randomize it, but it looks less good if I do that Sad

Btw, I had had a question about the license above here Wink
So, we need luajit! Smile
Pages: 1 2 3 4 5 6 7 8 9 10