Cuberite Forum
Lua Challenge: the Catastrophes plugin - Printable Version

+- Cuberite Forum (https://forum.cuberite.org)
+-- Forum: Plugins (https://forum.cuberite.org/forum-1.html)
+--- Forum: Plugin Discussion (https://forum.cuberite.org/forum-8.html)
+--- Thread: Lua Challenge: the Catastrophes plugin (/thread-1972.html)

Pages: 1 2 3 4 5 6 7 8 9 10


RE: Lua Challenge: the Catastrophes plugin - tonibm19 - 05-22-2015

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)


RE: Lua Challenge: the Catastrophes plugin - tonibm19 - 05-22-2015

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)


RE: Lua Challenge: the Catastrophes plugin - NiLSPACE - 05-22-2015

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)



RE: Lua Challenge: the Catastrophes plugin - tonibm19 - 05-22-2015

(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


RE: Lua Challenge: the Catastrophes plugin - NiLSPACE - 05-22-2015

The only method that might work is cWorld:TryGetHeight. With that you can check if a chunk is loaded.


RE: Lua Challenge: the Catastrophes plugin - NiLSPACE - 05-22-2015

I suppose it's kinda working:
[Image: fd1318402c.jpg]

TOO MUCH!
[Image: 93d2f7d0f0.jpg]


RE: Lua Challenge: the Catastrophes plugin - xoft - 05-22-2015

There's currently no cWorld:ForEachChunk() API function which would help you, but it shouldn't be too difficult to add it.


RE: Lua Challenge: the Catastrophes plugin - NiLSPACE - 05-22-2015

Apache License 2.0 is allowed right?


RE: Lua Challenge: the Catastrophes plugin - NiLSPACE - 05-23-2015

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


RE: Lua Challenge: the Catastrophes plugin - jan64 - 05-23-2015

So, we need luajit! Smile