maramizo Posted November 8, 2016 Share Posted November 8, 2016 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
Mr.Loki Posted November 9, 2016 Share Posted November 9, 2016 (edited) function getSideOfPlayer( player ) return player.matrix.position + player.matrix.right * math.random(.5,3) end local position = getSideOfPlayer(player) Enable OOP the position returned is in a Vector3 format Edited November 9, 2016 by loki2143 1 Link to comment
maramizo Posted November 9, 2016 Author Share Posted November 9, 2016 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
maramizo Posted November 9, 2016 Author Share Posted November 9, 2016 (edited) 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 November 9, 2016 by maramizo 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