-- *** Example buildings ***
-- Since: v0.4.2b
-- Make new block in current player position.

-- Don't require from directory scripts it need load from special folder modules or other folder
local STAGEC = require("modules.STAGEC")

local gamestate = 0
local new_block = {}
local ped = 0 

-- Wait update frame
while (GetGameFrame() == 0) do end 

-- Load STAGEC.SCR (Stage Constructor)
if (GetSCRName() ~= "data/STAGEC.SCR") then
	SetSCRName("data/STAGEC.SCR") 
end

while (true) do	
	wait(0)
	if (GetGameFrame() > 0) then
		if (gamestate == 0) then -- If start new game
			wait(100)
			gamestate = 1
		else
			if (IsKeyDown(0x35)) then -- Down key "5" for add block
				ped = GetPedStruct(1) -- Get ped struct (it player 1)
				local x, y, z = GetPedPos(ped)		
				new_block = STAGEC.CreateBlock(x + 1, y, z) -- Create block physics
				STAGEC.SetBlockSide(new_block, 1, 1, 1, 0, 0, 0, 2) -- Set wall tile
				STAGEC.SetBlockSide(new_block, 2, 1, 1, 0, 0, 0, 2)
				STAGEC.SetBlockSide(new_block, 3, 1, 1, 0, 0, 0, 2)
				STAGEC.SetBlockSide(new_block, 4, 1, 1, 0, 0, 0, 2)
				STAGEC.SetBlockType(new_block, 3, 0) -- Set ground tile
				STAGEC.SetBlockLID(new_block, 1, 0, 0, 90, 87) 
			end
			if (IsKeyDown(0x36)) then -- Down key "6" for delete block
				STAGEC.DeleteBlock(new_block, 1) -- Delete block physics
			end
		end
	else
		wait(100)
		gamestate = 0
	end
end