12p Posted December 12, 2010 Posted December 12, 2010 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
Aibo Posted December 13, 2010 Posted December 13, 2010 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 -- this will never happen, not after «if decY >= -0.6» perhaps you meant < -0.6?
12p Posted December 13, 2010 Author Posted December 13, 2010 checking... EDIT: It works, thanks a lot! again
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now