state = {} break_time = {} break_delay = {} place_time = {} place_delay = {} block_range = 90 pressed = 0 grass_block = 0 inventory = {} function grass_block_init(e) if first_grass == nil then first_grass = e end last_grass = e state[e] = "placed" --initial state of the block Scale(e,305) --size of block in world break_delay[e] = 0 break_time[e] = 300 --time till block is broken while pressing e place_delay[e] = 99999999999 place_time[e] = 1000 --time need to hold e to place a block (needs to be larger or smaller than the break time or u will do both) end function grass_block_main(e) Prompt("Grass blocks in inventory: " .. grass_block) if GetPlayerDistance(e) <= block_range then if state[e] == "placed" then CollisionOn(e) if breaking == 0 then breaking = 1 SetPosition(e,g_Entity[e]['x'],g_Entity[e]['y']+300,g_Entity[e]['z']) end PromptLocal(e,"Hold E to break block") if g_KeyPressE == 1 and pressed == 0 then pressed = 1 breaking = 2 break_delay[e] = GetTimer(e) + break_time[e] end --check for e first pressed (for timer) if g_KeyPressE == 1 and pressed == 1 and breaking == 2 and GetTimer(e) >= break_delay[e] then state[e] = "broken" Scale(e,50) --make block small to show it's broken state CollisionOff(e) --turn off it's collision so we can pass through it pressed = 2 end --check e is held down longer than timer elseif state[e] == "broken" then PromptLocal(e,"Press E to collect block") if g_KeyPressE == 1 and pressed == 0 then grass_block = grass_block + 1 inventory[grass_block] = e pressed = 1 Hide(e) state[e] = "inventory" --SetPosition(e,g_PlayerPosX,g_PlayerPosY,g_PlayerPosZ) --SetRotation(e,0,g_PlayerAngY,0) end end --state elseif state[e] == "inventory" then itemdist = 150 itemx=g_PlayerPosX itemz=g_PlayerPosZ itemy=g_PlayerPosY itemx = itemx+math.sin(math.rad(g_PlayerAngY))*itemdist itemz = itemz+math.cos(math.rad(g_PlayerAngY))*itemdist itemy = itemy-math.sin(math.rad(g_PlayerAngX))*itemdist SetPosition(e,itemx,itemy-15,itemz) SetRotation(e,0,g_PlayerAngY,0) if g_KeyPressE == 1 and pressed == 0 then pressed = 1 placing = 1 place_delay[e] = GetTimer(e) + place_time[e] end if g_KeyPressE == 1 and pressed == 1 and placing == 1 and breaking == 0 then Prompt("Placing block") Show(inventory[grass_block]) Scale(inventory[grass_block],305) if GetTimer(e) >= place_delay[e] then state[inventory[grass_block]] = "placed" Scale(inventory[grass_block],305) CollisionOn(inventory[grass_block]) Show(inventory[grass_block]) grass_block = grass_block - 1 pressed = 2 end --block placed end --holding e to place block --end --state = inventory end --player distance if g_KeyPressE == 0 then pressed = 0 placing = 0 breaking = 0 break_delay[e] = GetTimer(e) + break_time[e] place_delay[e] = GetTimer(e) + place_time[e] if grass_block > 0 then Hide(inventory[grass_block]) Scale(inventory[grass_block],50) end end --reset input if e is let go end --main