Kelly003 Posted June 26, 2021 Posted June 26, 2021 I want to export a function that rotates the object, this is what the function looks like: function rotateobj() local orx, ory, orz = getElementRotation(obj) setElementRotation(obj, orx, ory, orz+1) end addEventHandler("onClientRender", root, rotateobj) and i want to export this function to another script and i don't know how to do it i tried to do something but i can't get it local obj = createObject(1947, 193.71983, -105.13480, 1.54872-1) exports["rotobj"]:rotateobj()
SpecT Posted June 26, 2021 Posted June 26, 2021 Hey, Did you define the exported function in the meta.xml file ? Check the page with documentation about calling functions from other resources: https://wiki.multitheftauto.com/wiki/Call
Kelly003 Posted June 27, 2021 Author Posted June 27, 2021 There is an exported function in xml, but I don't know how to use it in the new file
Yamamoto Posted June 27, 2021 Posted June 27, 2021 (edited) 19 hours ago, Kelly003 said: I want to export a function that rotates the object, this is what the function looks like: function rotateobj() local orx, ory, orz = getElementRotation(obj) setElementRotation(obj, orx, ory, orz+1) end addEventHandler("onClientRender", root, rotateobj) and i want to export this function to another script and i don't know how to do it i tried to do something but i can't get it local obj = createObject(1947, 193.71983, -105.13480, 1.54872-1) exports["rotobj"]:rotateobj() first you need to add the variable in your function function rotateobj(obj) local orx, ory, orz = getElementRotation(obj) setElementRotation(obj, orx, ory, orz+1) end and then export local obj = createObject(1947, 193.71983, -105.13480, 1.54872-1) exports["rotobj"]:rotateobj(obj) Edited June 27, 2021 by Yamamoto
saluta Posted June 27, 2021 Posted June 27, 2021 19 hours ago, Kelly003 said: Я хочу экспортировать функцию, которая вращает объект, вот как выглядит функция: функция rotateobj () локальный orx, ory, orz = getElementRotation (obj) setElementRotation (obj, orx, ory, orz + 1 ) конец addEventHandler ( "onClientRender" , корень , rotateobj) и я хочу экспортировать эту функцию в другой скрипт, и я не знаю, как это сделать, я пытался что-то сделать, но не могу этого понять local obj = createObject ( 1947 , 193.71983 , - 105.13480 , 1.54872 - 1 ) экспорт [ "rotobj" ]: rotateobj () exports.rotobj:rotateobj("obj")
Hydra Posted June 27, 2021 Posted June 27, 2021 You forgot to put the rotation arguments in the function: function rotateobj(obj, rx, ry, rz) setElementRotation(obj, rx, ry, rz) end Make sure you put the function in the meta.xml too <export function="rotateobj" type="shared" /> Type can be: client, server or shared local abc = exports.yourResource --// This is more easy than to put exports.resource:function local building = createObject(18002, 0, 0, 5) function rotatingObject() abc:rotateobj(building, 0, 0, 5) end addCommandHandler("rotatemyobj", rotatingObject) Social Media: Discord: Gabriel45#6859 Instagram: https://www.instagram.com/_gabriel_455/ YouTube: Hydra45 (https://www.youtube.com/c/Hydra45/)
Kelly003 Posted June 28, 2021 Author Posted June 28, 2021 Neither of these work. subject still not spinning
Hydra Posted June 28, 2021 Posted June 28, 2021 If you want your object to spin use moveObject() instead moveObject(theObject, timer, x, y, z, rotX, rotY, rotZ) Social Media: Discord: Gabriel45#6859 Instagram: https://www.instagram.com/_gabriel_455/ YouTube: Hydra45 (https://www.youtube.com/c/Hydra45/)
Moderators IIYAMA Posted June 28, 2021 Moderators Posted June 28, 2021 2 hours ago, Kelly003 said: in the loop is supposed to spin Try this: local elementList = {} function rotateobj(obj) elementList[#elementList + 1] = obj end function rotateElementsInList (timeSlice) local normalizedSpeed = timeSlice / 16.66667 -- based on 60 fps (1000 / 60) -- Other method: getTickCount() % 360 = 0 t/m 359 for i=1, #elementList do local element = elementList[i] local rotX, rotY, rotZ = getElementRotation(element) setElementRotation(element, rotX, rotY, rotZ + normalizedSpeed) end end addEventHandler("onClientPreRender", root, rotateElementsInList) local obj = createObject(1947, 193.71983, -105.13480, 1.54872-1) exports["rotobj"]:rotateobj(obj) 1 Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
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