12p Posted January 29, 2011 Share Posted January 29, 2011 Ok I'm actually working on Minecraft Classic gamemode. I can't make 1 thing, I have been working hours and hours and I can't find the solution to this problem. I don't know what code it's supposed I give you so you tell me with the following ideas of my script (because I may pass you an useless part and you-me don't want to show whole code): -Using a cursor "mode". -Clicking on a perfect 1x1x1 cube that is placed on a perfect 3D grid. -Checking cube's face. -Creating a cube next to that cube face. You tell me what I must show, I will do. Please help me, I can't progress with this damn script! Link to comment
SDK Posted January 30, 2011 Share Posted January 30, 2011 This is one way how you could do it: 1) Detect the click with onClientClick, it will give you the blockElement and the position clicked on (worldX, worldY, worldZ). 2) Calc the distances between the block's position and world position in x,y,z . 3) The biggest distance is the axis matching the face you clicked on 4) Now the direction is positive on the axis if that distance is +, it's negative on the axis if it's <0 addEventHandler('onClientClick', root, function(button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedCube) -- get the position of the clicked cube (assuming this is the center of the cube) local cubeX, cubeY, cubeZ = getElementPosition(clickedCube) -- calc the differences between the two points local difX, difY, difZ = worldX - cubeX, worldY - cubeY, worldZ - cubeZ -- see which face was clicked by checking the longest distance if math.abs(difX) >= math.abs(difY) and math.abs(difX) >= math.abs(difZ) then -- the click was one the x-axis, now look what direction on the axis if difX > 0 then createCube ( worldX + 1, worldY, worldZ ) else createCube ( worldX - 1, worldY, worldZ ) end elseif math.abs(difY) >= math.abs(difX) and math.abs(difY) >= math.abs(difZ) -- the click was one the y-axis, now look what direction on the axis if difY > 0 then createCube ( worldX , worldY + 1, worldZ ) else createCube ( worldX , worldY - 1, worldZ ) end elseif math.abs(difZ) >= math.abs(difX) and math.abs(difZ) >= math.abs(difY) -- the click was one the z-axis, now look what direction on the axis if difZ > 0 then createCube ( worldX , worldY, worldZ + 1 ) else createCube ( worldX , worldY, worldZ - 1 ) end end end ) Link to comment
12p Posted January 30, 2011 Author Share Posted January 30, 2011 Gonna test! OMG this was my script (basing myself on normal "minecraft block placing" without modifications "tweaks"): function getClearPosition (pl,px,py) local x,y = getElementPosition(pl) --Distances between X and Y points local = x - px local yd = y - py --If the distance between X or Y points is more than 1 player won't get bug with cube collision --The clear X or Y point is "zero - distance" divided by "the distance's absolute value" --This point returns a "1" integer that has the right type (negative or positive) if math.abs() > 1 then finalX = round(( / math.abs()) + px) --"+ px" because I want to put it next to the cube I click on. end if math.abs(yd) > 1 then finalY = round((yd / math.abs(yd)) + py) end if finalX and finalY then return finalX,finalY else return false,false end end Link to comment
SDK Posted January 30, 2011 Share Posted January 30, 2011 Yeah, that's another way of doing it, but I think it's less accurate ( could be wrong tho ) Link to comment
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