Page 1 of 1

onchunkgenerated event

Posted: Sun Apr 28, 2013 9:56 pm
by ficolas
A new event that is sended each time a chunk of terrain is generated, the table, should contain
event.position
event.position.upperright{x,y}
event.position.lowerleft{x,y}

This event would be usefull for world gen, I think I alredy said it on the forum, but I have made this topic to know if it will be soon, or it will be eventually, or never :S
Also because I had my third idea for world gen in my mod :S

Re: onchunkgenerated event

Posted: Mon Apr 29, 2013 12:21 am
by FreeER
Considering we know the size of a chunk (64x64 tiles) I think we could create our own event to do this...Something like:

Code: Select all

require "util"
require "defines"
chunk_gen = game.generateeventname()
game.onevent(defines.events.ontick, function(event)
if math.abs(game.player.character.position.x) > 64*7 and math.abs(game.player.character.position.x) % 64 == 0 then
    game.raiseevent(chunk_gen, {x=game.player.character.position.x,y=game.player.character.position.y})
end
end)
game.onevent(chunk_gen, function(event)
    game.player.print(tostring(event.x,event.y))
end)
Then it is just a matter of calculating where the corners of each chunk are. for example if you cross x=64 y=11 then the chunk would be {x=0,y=0},{x=64,y=64}, if you crossed x=128, y=200 then the chunk would be within {x=128,y=192},{x=192,y=256} (I think).

Assuming of course that chunks are static (best word I could think of) and not simply that any 64 tiles away from the player will be loaded if they are not already. IF that's the case then you would pretty much have to track whenever a player goes out further than he has before...but it would be difficult to save a table of the chunks that have been loaded if this is the case. While you could save the minimum and maximum x/y and assume that anything within that area would be loaded that only works while the player stays near spawn, once they go out a few hundred tiles in one direction to find creepers then this assumption would not longer be even close to accurate

Re: onchunkgenerated event

Posted: Mon Apr 29, 2013 3:01 pm
by rk84

Code: Select all

math.abs(game.player.character.position.x) % 64 == 0
You would need to stand in right spot on x-axel to that work.

You could divide coords with 64 and math.floor them (after you multiply them with 64 you get topleft corner)
You could store chunk status in matrix (tables inside table) and indexing it with those divided coords.

Re: onchunkgenerated event

Posted: Mon Apr 29, 2013 4:12 pm
by kovarex
Ok, I just added this event (onchunkgenerated), it has area which is bounding box (containing leftop, rightbottom).

Just be careful with that, as you could easily create chain reaction by adding entities on the border of the chunk (that would cause the neighbour chunk to generate etc).

Maybe the lua entity creation shouldn't trigger chunk generation I'm not sure.

Re: onchunkgenerated event

Posted: Mon Apr 29, 2013 8:59 pm
by ficolas
Ok thanx!
u guys are so awesome :)
Making an awesome game and with an awesome modding support :)

Also, will we be able to change entities' force in 0.4?