2kristof2 Posted July 14, 2015 Share Posted July 14, 2015 Hi, I'm not a new scripter and know a bit lua but I've never made any server-sided script though. I'd like to know how to make a simple (I guess) script. For example when I type "/create" in chatbox the script checks which element is selected (in my editor in this case) and it creates an object with the same position and rotation what the selected element (object/vehicle). Thanks for any help regards, 2kristof2 Link to comment
iMr.Dawix~# Posted July 14, 2015 Share Posted July 14, 2015 objects = {} addCommandHandler("create",function (player,cmd,oid) if oid then local x,y,z = getElementPosition(player) local rx,ry,rz = getElementRotation(player) objects[player] = createObject(oid,x,y,z,rx,ry,rz) if isElement(objects[player]) then destroyElement(objects[player]) end end end ) Link to comment
2kristof2 Posted July 15, 2015 Author Share Posted July 15, 2015 It doesn't work for me. Link to comment
iMr.Dawix~# Posted July 15, 2015 Share Posted July 15, 2015 It doesn't work for me. you must type in console ( f8 ) like this oid Link to comment
GTX Posted July 15, 2015 Share Posted July 15, 2015 Which editor? Map editor? Do you want to copy an object? https://wiki.multitheftauto.com/wiki/Editor#Cloning Link to comment
2kristof2 Posted July 15, 2015 Author Share Posted July 15, 2015 you must type in console ( f8 ) like this oid I know but it doesn't work Which editor? Map editor? Do you want to copy an object? https://wiki.multitheftauto.com/wiki/Editor#Cloning Well I'm playing mta about 2 years so I know how to copy an object. This is what I want to do: https://www.youtube.com/watch?v=FSMRg4A ... e=youtu.be Link to comment
GTX Posted July 15, 2015 Share Posted July 15, 2015 Well, you did it, didn't you? iMr.Dawix~# provided you the code, which should work. objects = {} addCommandHandler("create", function (player,cmd,oid) if tonumber(oid) then if objects[player] then destroyElement(objects[player]) end local x,y,z = getElementPosition(player) local rx,ry,rz = getElementRotation(player) objects[player] = createObject(tonumber(oid),x,y,z,rx,ry,rz) end end ) /create [iD] Link to comment
2kristof2 Posted July 15, 2015 Author Share Posted July 15, 2015 Could you test it please? Because nothing happens when I type it. (btw I changed command because "/create" already exists) (video is a fake just to show you what I want to do) Link to comment
GTX Posted July 15, 2015 Share Posted July 15, 2015 I'm gonna give you functions which you need to use to make that. Try to make it and if you have errors, post here. exports.editor_main:getSelectedElement() -- To get element you selected in editor. getElementPosition -- Use it on exported function to get position of an element you selected. getElementRotation -- Use it on exported function to get rotation of an element you selected. addCommandHandler createObject exports.editor:import() -- To import back to editor if you wish. Link to comment
2kristof2 Posted July 15, 2015 Author Share Posted July 15, 2015 I have no idea how to make it... Just made script which has none sense: objects = {} addCommandHandler("cre",function (cmd, oid) local selectedElement = exports.editor_main:getSelectedElement() if oid then local x,y,z = exports.edf:edfGetElementPosition(selectedElement) local rx, ry, rz = exports.edf:edfGetElementRotation(selectedElement) objects[selectedElement] = createObject(oid,x,y,z,rx,ry,rz) if isElement(objects[selectedElement]) then destroyElement(objects[selectedElement]) end end end ) when I type "/cre ID" I noticed the following warnings: Link to comment
GTX Posted July 15, 2015 Share Posted July 15, 2015 I didn't give you EDF functions? What are you doing lol? objects = {} addCommandHandler("cre",function (cmd, oid) local selectedElement = exports.editor_main:getSelectedElement() if oid then local x,y,z = getElementPosition(selectedElement) local rx, ry, rz = getElementRotation(selectedElement) objects[selectedElement] = createObject(oid,x,y,z,rx,ry,rz) if isElement(objects[selectedElement]) then destroyElement(objects[selectedElement]) end end end ) Link to comment
2kristof2 Posted July 15, 2015 Author Share Posted July 15, 2015 I tried both options... Warnings for your code: Link to comment
2kristof2 Posted July 15, 2015 Author Share Posted July 15, 2015 Nothing happens and no errors Link to comment
GTX Posted July 15, 2015 Share Posted July 15, 2015 I've been fiddling with this case, I've tested out some methods and came to a solution: Client: addCommandHandler("cre", function(cmd, oid) local selectedElement = exports.editor_main:getSelectedElement() if getElementType(selectedElement) == "object" and tonumber(oid) then local x, y, z = getElementPosition(selectedElement) local rx, ry, rz = getElementRotation(selectedElement) triggerServerEvent("e:import", root, tonumber(oid), x, y, z, rx, ry, rz) end end ) Server: addEvent("e:import", true) addEventHandler("e:import", root, function(id, x, y, z, rx, ry, rz) local element = createObject(id, x, y, z, rx, ry, rz) exports.editor:import(element) destroyElement(element) end ) Link to comment
2kristof2 Posted July 15, 2015 Author Share Posted July 15, 2015 Thanks! Finally it works I really appreciate your time spent on helping me. I know a bit more about server-sided scripts now. 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