Gothem Posted October 15, 2008 Share Posted October 15, 2008 well im creating a object placement with the cursor. but the problem is... than the worldX , worldY and worldZ parameters of OnCursorMove dont are totally correct. so i have a problem. i tried something for fix it but now is a lower error. here is the code if someone know how fix it. function MapaC() if MComandante == true then MComandante = false showCursor ( false ) toggleCameraFixedMode ( false ) showPlayerHudComponent ("radar", true ) unbindKey ( "arrow_u", "down", MovCam ) unbindKey ( "arrow_d", "down", MovCam ) unbindKey ( "arrow_l", "down", MovCam ) unbindKey ( "arrow_r", "down", MovCam ) else MComandante = true toggleCameraFixedMode ( true ) x,y,z = getElementPosition ( getLocalPlayer() ) setTimer(setCameraPosition,200,1, x, y, 75) setTimer(setCameraLookAt,500,1, x, y, z) objeto = createObject ( 3434, x, y, z) showCursor(true) showPlayerHudComponent ("radar", false ) bindKey ( "arrow_u", "down", MovCam ) bindKey ( "arrow_d", "down", MovCam ) bindKey ( "arrow_l", "down", MovCam ) bindKey ( "arrow_r", "down", MovCam ) end end function MovCam ( key ) if key == "arrow_u" then x,y,z = getCameraPosition () setCameraPosition( x, y+1, z) setTimer(setCameraLookAt,250,1, x, y+1, getGroundPosition(x,y,z)) elseif key == "arrow_d" then x,y,z = getCameraPosition () setCameraPosition( x, y-1, z) setTimer(setCameraLookAt,250,1, x, y-1, getGroundPosition(x,y,z)) elseif key == "arrow_l" then x,y,z = getCameraPosition () setCameraPosition( x-1, y, z) setTimer(setCameraLookAt,250,1, x-1, y, getGroundPosition(x,y,z)) elseif key == "arrow_r" then x,y,z = getCameraPosition () setCameraPosition( x+1, y, z) setTimer(setCameraLookAt,250,1, x+1, y, getGroundPosition(x,y,z)) end end function Construccion(cursorX, cursorY, absoluteX, absoluteY, worldX, worldY, worldZ) if MComandante == true then Z = getGroundPosition(worldX,worldY,worldZ) + getElementDistanceFromCentreOfMassToBaseOfModel(objeto) * 2 outputChatBox ( "Variables: X="..worldX.."Y="..worldY.."Z="..Z ) setElementPosition ( objeto, worldX, worldY, Z) end end addEventHandler("onClientCursorMove",getRootElement(),Construccion) if someone know how fix it thx PD: you need to add MapaC() in a command or something Link to comment
Ace_Gambit Posted October 15, 2008 Share Posted October 15, 2008 I did something with object dragging in one of my earlier resources. https://community.multitheftauto.com/index.php?p= ... ils&id=137 Link to comment
Gothem Posted October 15, 2008 Author Share Posted October 15, 2008 I did something with object dragging in one of my earlier resources.https://community.multitheftauto.com/index.php?p= ... ils&id=137 i will see it EDIT: i saw the code but can you explain me it a little? Link to comment
Ace_Gambit Posted October 15, 2008 Share Posted October 15, 2008 I've simplified things a bit by taking the part that should interest you the most. It's easier to read now . local selectedElement = false local screenX, screenY = guiGetScreenSize() function onClientCursorMove(cursorX, cursorY) local worldX, worldY, worldZ = 0, 0, 0 local rotX, rotY, rotZ = 0, 0, 0 local depth = 0 local distance = 0 cursorX = screenX * (cursorX / 1) cursorY = screenY * (cursorY / 1) depth = (math.abs(cursorY - screenY) / screenY) * 100 depth = 50.0 * ((depth / 100) * (depth / 100)) worldX, worldY, worldZ = getWorldFromScreenPosition(cursorX, cursorY, depth) collision, pX, pY, pZ, element = processLineOfSight(worldX, worldY, worldZ + 5.0, worldX, worldY, -100, true, true, true, true, false, true, true, true, nil) if (selectedElement) then distance = getElementDistanceFromCentreOfMassToBaseOfModel(selectedElement) if (collision and getKeyState("lshift")) then worldZ = pZ + distance end if (getElementType(selectedElement) == "vehicle") then setVehicleFrozen(selectedElement, true) end setElementPosition(selectedElement, worldX, worldY, worldZ) end end addEventHandler("onClientCursorMove", getRootElement(), onClientCursorMove, true) Link to comment
Gothem Posted October 15, 2008 Author Share Posted October 15, 2008 I've simplified things a bit by taking the part that should interest you the most. It's easier to read now . local selectedElement = false local screenX, screenY = guiGetScreenSize() function onClientCursorMove(cursorX, cursorY) local worldX, worldY, worldZ = 0, 0, 0 local rotX, rotY, rotZ = 0, 0, 0 local depth = 0 local distance = 0 cursorX = screenX * (cursorX / 1) cursorY = screenY * (cursorY / 1) depth = (math.abs(cursorY - screenY) / screenY) * 100 depth = 50.0 * ((depth / 100) * (depth / 100)) worldX, worldY, worldZ = getWorldFromScreenPosition(cursorX, cursorY, depth) collision, pX, pY, pZ, element = processLineOfSight(worldX, worldY, worldZ + 5.0, worldX, worldY, -100, true, true, true, true, false, true, true, true, nil) if (selectedElement) then distance = getElementDistanceFromCentreOfMassToBaseOfModel(selectedElement) if (collision and getKeyState("lshift")) then worldZ = pZ + distance end if (getElementType(selectedElement) == "vehicle") then setVehicleFrozen(selectedElement, true) end setElementPosition(selectedElement, worldX, worldY, worldZ) end end addEventHandler("onClientCursorMove", getRootElement(), onClientCursorMove, true) thx i will see if it works to me EDIT: well i see than it works better than before but when the cursor is in the buttom of the screen the position of the object start to fail Link to comment
Ace_Gambit Posted October 15, 2008 Share Posted October 15, 2008 In what way is it failing? Link to comment
Gothem Posted October 15, 2008 Author Share Posted October 15, 2008 In what way is it failing? well i have the camera like GTA 2 and when i try to make the object at the bottom of the screen it cant go there Link to comment
Ace_Gambit Posted October 15, 2008 Share Posted October 15, 2008 In what way is it failing? well i have the camera like GTA 2 and when i try to make the object at the bottom of the screen it cant go there Obviously because the code above takes the screen depth into account. The closer you get to the bottom of the screen the closer the object moves towards you. That's what it is supposed to do. It's not working for "bird view". Link to comment
Gothem Posted October 15, 2008 Author Share Posted October 15, 2008 In what way is it failing? well i have the camera like GTA 2 and when i try to make the object at the bottom of the screen it cant go there Obviously because the code above takes the screen depth into account. The closer you get to the bottom of the screen the closer the object moves towards you. That's what it is supposed to do. It's not working for "bird view". so what need to do for make it working? Link to comment
Gothem Posted October 25, 2008 Author Share Posted October 25, 2008 sry for double post and revive the topic but i need to know how i can make it fully working Link to comment
Gamesnert Posted October 25, 2008 Share Posted October 25, 2008 Try removing birdview for a small while? Link to comment
Gothem Posted October 28, 2008 Author Share Posted October 28, 2008 Try removing birdview for a small while? i need it to be bird view. i like make it as warcraft for build things Link to comment
XetaQuake Posted October 28, 2008 Share Posted October 28, 2008 I think you need to remove the maths and the "depth" i like make it as warcraft for build things Oh well - i hope you release it 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