Jump to content

getElementPosition and setCameraMatrix


DRW

Recommended Posts

Hello, I'm using a camera movement script that I extracted from a login panel, here is the part of the client, the problem is:

WARNING: Bad argument @ 'getElementPosition' [Expected element at argument 1, got nil]

WARNING: Bad argument @ 'getElementPosition' [Expected element at argument 1, got nil]

WARNING: Bad argument @ 'setCameraMatrix' [Expected vector3 at argument 1, got boolean]

  
local sm = {} 
sm.moov = 1 
sm.object1,sm.object2 = nil,nil 
  
local function removeCamHandler() 
    if(sm.moov == 1)then 
        sm.moov = 0 
    end 
end 
  
  
local function camRender() 
    if (sm.moov == 1) then 
        x1,y1,z1 = getElementPosition(sm.object1) --The warning talks about this. 
        x2,y2,z2 = getElementPosition(sm.object2) --The warning talks about this. 
        setCameraMatrix(x1,y1,z1,x2,y2,z2) --The warning talks about this. 
    end 
end 
addEventHandler("onClientPreRender",root,camRender) 
  
  
function smoothMoveCamera(x1,y1,z1,x1t,y1t,z1t,x2,y2,z2,x2t,y2t,z2t,time) 
    if(sm.moov == 1)then return false end 
    sm.object1 = createObject(1337,x1,y1,z1) 
    sm.object2 = createObject(1337,x1t,y1t,z1t) 
    setElementAlpha(sm.object1,0) 
    setElementAlpha(sm.object2,0) 
    setObjectScale(sm.object1,0.01) 
    setObjectScale(sm.object2,0.01) 
    moveObject(sm.object1,time,x2,y2,z2,0,0,0,"InOutQuad") 
    moveObject(sm.object2,time,x2t,y2t,z2t,0,0,0,"InOutQuad") 
    sm.moov = 1 
    setTimer(removeCamHandler,time,1) 
    setTimer(destroyElement,time,1,sm.object1) 
    setTimer(destroyElement,time,1,sm.object2) 
    return true 
end 
  

Link to comment

I didn't realize there was that exact example in the wiki, but now there is another problem:

ERROR: Attempt to call global 'callClientFunction' (a nil value)

Serverside part calling that client function posted before.

addEventHandler("onPlayerJoin", getRootElement(), 
function() 
    fadeCamera(source, true) 
    --triggerClientEvent("onJoinPlayTrack",source) 
    --callClientFunction(source,"onJoinPlayTrack") 
    sX = math.random(-3000,3000)    -- start X 
    sY = math.random(-3000,3000)    -- start Y 
    sZ = math.random(50,100)        -- start Z 
    rX = math.random(90,270)        -- Rotation X 
    rY = math.random(90,270)        -- Rotation Y 
    rZ = 0                          -- Rotation Z 
    tX = math.random(-3000,3000)    -- Target X 
    tY = math.random(-3000,3000)    -- Target Y 
    tZ = sZ                         -- Target Z 
     
    callClientFunction(source,"smoothMoveCamera",sX,sY,sZ,rX,rY,rZ,tX,tY,tZ,rX,rY,rZ,100000) 
end) 

Link to comment

Did you add this?

In Server Lua:

function callClientFunction(client, funcname, ...) 
    local arg = { ... } 
    if (arg[1]) then 
        for key, value in next, arg do 
            if (type(value) == "number") then arg[key] = tostring(value) end 
        end 
    end 
    -- If the clientside event handler is not in the same resource, replace 'resourceRoot' with the appropriate element 
    triggerClientEvent(client, "onServerCallsClientFunction", resourceRoot, funcname, unpack(arg or {})) 
end 

andIn Client Lua:

function callClientFunction(funcname, ...) 
    local arg = { ... } 
    if (arg[1]) then 
        for key, value in next, arg do arg[key] = tonumber(value) or value end 
    end 
    loadstring("return "..funcname)()(unpack(arg)) 
end 
addEvent("onServerCallsClientFunction", true) 
addEventHandler("onServerCallsClientFunction", resourceRoot, callClientFunction) 

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...