Jump to content

Client sided Matrix returns nil.


maramizo

Recommended Posts

Function aims to get side of matrix co-ordinations (in this case player co-ords). Should return a modified X,Y,Z to get the side of the player, instead returns nil.

function getSideOfPlayer()
	local x,y,z = getElementPosition(localPlayer)
	local z = getGroundPosition(x,y,z)
	local rX, rY, rZ = getElementRotation(localPlayer)
	local eMatrix = (Matrix.create(x,y,z,rX,rY,rZ))
	return (Matrix.getPosition(eMatrix) + Matrix.getRight(eMatrix)*math.random(3)) -- Random slight reposition to the right side of the player.
end

Function is called by another function and stored in only three variables as follows:


		local x,y,z = getSideOfPlayer()

Why is it returning nil instead of actual co-ordinates? 

Thanks.

Link to comment

Alright, two quick questions;

1. How do you send an array from a client to the server using triggerServerEvent? This yields an error:

triggerServerEvent("ejectCase", resourceRoot, localPlayer, unpack(sentArray))
function gCreateEjectedCase(lArray)
  --code
end
addEvent("ejectCase", true)
addEventHandler("ejectCase", resourceRoot, gCreateEjectedCase)

Error is as follows:

ERROR: ejectCasings\ejectrS.lua:4: bad argument #1 to 'ipairs' (table expected, got userdata)

 

2. How do you destroy all objects within a class?

 

Thanks.

Link to comment
27 minutes ago, maramizo said:

Alright, two quick questions;

1. How do you send an array from a client to the server using triggerServerEvent? This yields an error:


triggerServerEvent("ejectCase", resourceRoot, localPlayer, unpack(sentArray))

function gCreateEjectedCase(lArray)  --codeendaddEvent("ejectCase", true)addEventHandler("ejectCase", resourceRoot, gCreateEjectedCase)

Error is as follows:


ERROR: ejectCasings\ejectrS.lua:4: bad argument #1 to 'ipairs' (table expected, got userdata)

 

Fixed this, silly mistake leaving the localPlayer arg there. Only the second question remains, I need to destroy all objects in a class to free up memory, given they're useless after a specific point in the code. How do I iterate through the metadata's index in the class defined as follows:

Casing = {}
Casing.__index = Casing
sentArray = {}
function Casing.create(x, y, z)
	if x ~= nil and y ~= nil and z ~= nil then
		local _casing = {}
		setmetatable(_casing,Casing)
        --etc.
		return _casing
	end
end

 

Edited by maramizo
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...