Jump to content

function export


Kelly003

Recommended Posts

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(1947193.71983, -105.134801.54872-1)
exports["rotobj"]:rotateobj()
Link to comment
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 by Yamamoto
Link to comment
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

 

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
  • Moderators
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)

 

  • Thanks 1
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...