Ashford Posted September 10, 2016 Share Posted September 10, 2016 Hello guys, I just have a little question, I don't know if the title fits the subject, but I'm going to state my problem. I'm planning to make an in game house maker ( Not markers and stuff, a real house building ) and I'm just asking about.. positioning.. How to get the coordinates automatically, the house will surely be a square, and just wondering how to build the objects there automatically.. What I exactly want is, how to make the script get the exact coordinates that the player wants ( he'll decided it with his cursor "a house shape will be visible in the screen" ) and build it. Thanks in advance. Link to comment
Tails Posted September 10, 2016 Share Posted September 10, 2016 (edited) That's really easy stuff. https://wiki.multitheftauto.com/wiki/GetCursorPosition You can use that function to get the coordinates. You can use it onClientClick. Edited September 10, 2016 by Tails Link to comment
Ashford Posted September 10, 2016 Author Share Posted September 10, 2016 Explain more please Link to comment
KariiiM Posted September 10, 2016 Share Posted September 10, 2016 If I am not wrong. you want to get the player's current position coordinations, right? Link to comment
Tails Posted September 10, 2016 Share Posted September 10, 2016 The functions really speak for themselves. If you're planning to make an "in-game house maker" as you said, it's going to be a lot trickier in terms of position, rotation, placement and all that stuff. I can only help you a little bit with that but not that much, but I thought you just wanted to know how to get the coordinates? Link to comment
Ashford Posted September 10, 2016 Author Share Posted September 10, 2016 Just now, Tails said: The functions really speak for themselves. If you're planning to make an "in-game house maker" as you said, it's going to be a lot trickier in terms of position, rotation, placement and all that stuff. I can only help you a little bit with that but not that much, but I thought you just wanted to know how to get the coordinates? Well I'd like to get your help, I've already answered your question below. 2 minutes ago, KariiiM said: If I am not wrong. you want to get the player's current position coordinations, right? No, that's easy lol. I'm not a bad scripter, I'm actually an in training developer, I just need to know more about this. For example, there will be a GUI where a player can chose to build a house, he'll click on a button, which will attach a house to his Cursor ( with low alpha ) and he'll chose where to place it, more like Map Editor, but during the game. Link to comment
Tails Posted September 10, 2016 Share Posted September 10, 2016 Can you be a little more specific in terms of what you need to know, what do you want us to explain to you exactly? Link to comment
Ashford Posted September 10, 2016 Author Share Posted September 10, 2016 (edited) I want to know, how to create the object and make it move with the cursor movement (Most thing I need) Edited September 10, 2016 by Ashford Link to comment
Tails Posted September 10, 2016 Share Posted September 10, 2016 (edited) You can create an object with CreateObject, then set its alpha with SetElementAlpha. Do that client-side (on player input). Tie it to the client's cursor using OnClientRenderand getCursorPostion and SetElementPosition. After that use onClientClick to trigger a server event to create an object at the same position as the low alpha object using GetElementPosition and TriggerServerEvent. Now remove the client object with DestroyElement. I've actually done something similar to this before. I can provide you some examples later if you want when I get back. Hope this helps. Edited September 10, 2016 by Tails Link to comment
Ashford Posted September 10, 2016 Author Share Posted September 10, 2016 well yea I'd need some examples Link to comment
Tails Posted September 11, 2016 Share Posted September 11, 2016 (edited) Just quickly wrote this with the help of some old code of mine. It's nothing fancy. Just trying to give you an idea of how you could do it. Hold ctrl to position and left click to place. This is client side: local objectID = 3877 local objectHeightOffset = 1.6 local objectInHand = createObject(objectID,0,0,0) setElementAlpha(objectInHand,170) function holdObject(objectID) if getKeyState("lctrl") then local cx,cy,cz = getCameraMatrix() local _,_,wx,wy,wz = getCursorPosition() local _,x,y,z = processLineOfSight(cx,cy,cz,wx,wy,wz,true,true,false,true,true,false,false,false,objectInHand) if x and y and z then setElementPosition(objectInHand,x,y,z+objectHeightOffset) end end end addEventHandler("onClientRender",root,holdObject) function toggleCursor(key,pressed) if key == "lctrl" then if pressed then showCursor(pressed) else showCursor(pressed) end end end addEventHandler("onClientKey",root,toggleCursor) function placeObject(button,state) if button == "left" and state == "up" and getKeyState("lctrl") then local x,y,z = getElementPosition(objectInHand) local rx,ry,rz = getElementRotation(objectInHand) triggerServerEvent("onClientPlaceObject",localPlayer,objectID,x,y,z,rx,ry,rz) --destroyElement(objectInHand) end end addEventHandler("onClientClick",root,placeObject) And this server side: function placeObject(id,x,y,z,rx,ry,rz) createObject(id,x,y,z,rx,ry,rz) outputChatBox(getPlayerName(source).. " has placed an object at "..x..", "..y..", "..z.."!") end addEvent("onClientPlaceObject",true) addEventHandler("onClientPlaceObject",root,placeObject) The rest you can probably figure out on your own. If not feel free to ask more questions, I'll do my best to answer them. Edited September 11, 2016 by Tails Link to comment
Ashford Posted September 12, 2016 Author Share Posted September 12, 2016 Couldn't figure out what to do next : [ My idea just blurred 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