Jump to content

Why doesn't this work?


12p

Recommended Posts

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 

Link to comment
  
     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? :P

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...