Kelly003 Posted June 26, 2021 Share 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() Link to comment
SpecT Posted June 26, 2021 Share 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 Link to comment
Kelly003 Posted June 27, 2021 Author Share Posted June 27, 2021 There is an exported function in xml, but I don't know how to use it in the new file Link to comment
Yamamoto Posted June 27, 2021 Share 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 Link to comment
saluta Posted June 27, 2021 Share 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") Link to comment
Hydra Posted June 27, 2021 Share 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) Link to comment
Kelly003 Posted June 28, 2021 Author Share Posted June 28, 2021 Neither of these work. subject still not spinning Link to comment
Hydra Posted June 28, 2021 Share Posted June 28, 2021 If you want your object to spin use moveObject() instead moveObject(theObject, timer, x, y, z, rotX, rotY, rotZ) Link to comment
Kelly003 Posted June 28, 2021 Author Share Posted June 28, 2021 in the loop is supposed to spin Link to comment
Moderators IIYAMA Posted June 28, 2021 Moderators Share 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 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