I'm making a script to get the closest integer position (on both X and Y axis) to the cursor position, when this clicks. But doesn't work (any object gets created). No debug errors.
if entity and getElementType (entity) == "object" then
local objX,objY,objZ = getElementPosition (entity)
local objects = getElementsByType("object")
local n = table.getn(objects)
blocks[n+1] = createObject (model,objX,objY,objZ+1.15)
if sounds == 1 then
playSound3D ("placing.mp3",objX,objY,objZ+1.3,false)
end
else
local intX,decX = math.modf(posX)
local intY,decY = math.modf(posY)
if decX >= -0.6 then
if decY >= -0.6 then
local objects = getElementsByType("object")
local n = table.getn(objects)
blocks[n+1] = createObject (model,intX,intY,posZ+0.5)
if sounds == 1 then
playSound3D ("placing.mp3",intX,intY,posZ,false)
end
elseif decY < -0.6 then
local objects = getElementsByType("object")
local n = table.getn(objects)
blocks[n+1] = createObject (model,intX,intY+20,posZ+0.5)
if sounds == 1 then
playSound3D ("placing.mp3",intX,intY+20,posZ,false)
end
end
elseif decX < -0.6 then
if decY >= -0.6 then
local objects = getElementsByType("object")
local n = table.getn(objects)
blocks[n+1] = createObject (model,intX+20,intY,posZ+0.5)
if sounds == 1 then
playSound3D ("placing.mp3",intX+20,intY,posZ,false)
end
elseif decY > -0.6 then
local objects = getElementsByType("object")
local n = table.getn(objects)
blocks[n+1] = createObject (model,intX+20,intY+20,posZ+0.5)
if sounds == 1 then
playSound3D ("placing.mp3",intX+20,intY+20,posZ,false)
end
end
end
end