Random Chitchat 2012-2016
Shhhh don't tell anyone Smile

Here is another plugin I created. It allows you to execute a Lua script in the webadmin.[Image: 5CTew.png]
Thanks given by:
(12-06-2013, 12:30 AM)STR_Warrior Wrote: Look what I have created Smile Thanks LuaBig Grin
Nice. Is it safe to /regen , though? Are you using math.random(), or something different?

It seems you're really enjoying writing plugins Smile
Thanks given by:
Yea I'm using math.random() so if you use /regen you get other terrain.

I love seeing what I can do with plugins.
Thanks given by:
I think you can make it regen-safe by calling math.randomseed() with a number as the argument that is calculated from the chunk X and Z coords - for example:
math.randomseed((a_ChunkX % 1234567) + (a_ChunkZ % 7654321) * 321);
math.random();
This should provide the same random values for the same chunk repeatedly. The extra random() call is there because the first random number returned is "not random enough" - see http://lua-users.org/wiki/MathLibraryTutorial 's math.random section.
Thanks given by:
But that would mean I get the same height for every X, Z coordinate in the chunk? Would this work if I want to get a different height for every block?:
local CoordX = tonumber(ChunkX .. "." .. X)
local CoordZ = tonumber(ChunkZ .. "." .. Z)
math.randomseed(((CoordX % 1234567) + (CoordZ % 7654321) * 321));

Hurray I have something that actualy worksBig Grin
ChunkDesc:SetUseDefaultHeight(false)
for X=0, 15 do
	for Z=0, 15 do
		if ChunkDesc:GetBiome(X, Z) == biSwampland then
			ChunkDesc:SetUseDefaultFinish(false)
			local Calculation = math.sqrt(((ChunkX % 1234567) + (ChunkZ % 7654321) * ((X + 1) * (Z + 1)))) / (ChunkX + (X + 1)) / (ChunkZ + (Z + 1))
			math.randomseed(Calculation);
			math.random()
			local Height = math.random(60, 61)
			ChunkDesc:SetHeight(X, Z, Height)
			for Y=2, Height -3 do
				ChunkDesc:SetBlockTypeMeta(X, Y, Z, E_BLOCK_STONE, 0)
			end
			for Y=Height-3, Height-1 do
				ChunkDesc:SetBlockTypeMeta(X, Y, Z, E_BLOCK_DIRT, 0)
			end
			ChunkDesc:SetBlockTypeMeta(X, Height, Z, E_BLOCK_GRASS, 0)
			ChunkDesc:SetBlockTypeMeta(X, 1, Z, E_BLOCK_BEDROCK, 0)
			for Y=61, Height, -1 do
				local Block = ChunkDesc:GetBlockType(X, Y, Z)
				print(Y, Height)
				if Block == E_BLOCK_AIR then
					ChunkDesc:SetBlockTypeMeta(X, Y, Z, E_BLOCK_WATER, 0)
				elseif Block == E_BLOCK_GRASS and Y < Height then
					ChunkDesc:SetBlockTypeMeta(X, Y, Z, E_BLOCK_DIRT, 0)
				elseif Block ~= E_BLOCK_WATER then
					--break;
				end
			end
			Height = ChunkDesc:GetHeight(X, Z)
			local HighestBlock = ChunkDesc:GetBlockType(X, Height, Z)
			if HighestBlock == E_BLOCK_LILY_PAD then
				if ChunkDesc:GetBlockType(X, Height -1, Z) ~= E_BLOCK_WATER then
				end
				ChunkDesc:SetBlock(X, Height, Y, E_BLOCK_AIR, 0)
			end
		end
	end
end
[Image: 5D1RN.jpg]
Thanks given by:
You shouldn't call math.randomseed() for each column, but only once per chunk.
Thanks given by:
Realy? But how do I get a new height for each block then?
Thanks given by:
math.randomseed((ChunkX % 1234567) + (ChunkZ % 7654321) * 23);
math.random();
for X = 0, 15 do
    for Z = 0, 15 do
        if ChunkDesc:GetBiome(X, Z) == biSwampland then
            ChunkDesc:SetUseDefaultFinish(false);
            local Height = math.random(60, 61);
            ...
Thanks given by:
Because I can't find the problem about the pickups spawning, and a recompile doesn't work I have exported a .dmp file using "TaskInfo" and uploaded it: http://www.mediafire.com/download/bo6kto...287%29.zip
Thanks given by:
You know what would be cool? A MCS t-shirt to show off Smile I'm no graphic designer, so take it easy on me, but something like this? Me wants! SANTAAAA! I've been really good, look how many commits I've made this year! Smile
[Image: mcs%20tee.png]
Thanks given by:




Users browsing this thread: 18 Guest(s)