From a53dac2929a2e8b4fa8b07840f0bf0f7a9e367b3 Mon Sep 17 00:00:00 2001 From: LNJ Date: Mon, 3 Apr 2017 13:00:40 +0200 Subject: [PATCH] Randomize drop pos --- lua/api.lua | 5 +++-- lua/helpers.lua | 10 ++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lua/api.lua b/lua/api.lua index bf8c8c8..dafb934 100755 --- a/lua/api.lua +++ b/lua/api.lua @@ -98,10 +98,11 @@ function drawers.drawer_on_dig(pos, node, player) local j = math.floor(count / stack_max) + 1 local i = 1 while i <= j do + rndpos = drawers.randomize_pos(pos) if not (i == j) then - core.add_item(pos, name .. " " .. stack_max) + core.add_item(rndpos, name .. " " .. stack_max) else - core.add_item(pos, name .. " " .. count % stack_max) + core.add_item(rndpos, name .. " " .. count % stack_max) end i = i + 1 end diff --git a/lua/helpers.lua b/lua/helpers.lua index 87adbae..3662da2 100755 --- a/lua/helpers.lua +++ b/lua/helpers.lua @@ -149,3 +149,13 @@ function drawers.spawn_visual(pos) end end end + +function drawers.randomize_pos(pos) + local rndpos = table.copy(pos) + local x = math.random(-50, 50) * 0.01 + local z = math.random(-50, 50) * 0.01 + rndpos.x = rndpos.x + x + rndpos.y = rndpos.y + 0.25 + rndpos.z = rndpos.z + z + return rndpos +end