knightscript Posted August 17, 2018 Share Posted August 17, 2018 (edited) Hello, I am trying to export a function called "getRandomLoot", which is in a resource name NTTC_Tables, I am trying to export this function to be able to use it on another resource, the function: function getRandomLoot(location) local number = table.random(locations_for_items_and_spawns) --outputServerLog( number[1]..","..number[2]..","..number[3] ) local x,y,z = number[1], number[2], number[3] local position = getZoneName ( x, y, z, true ) table = [] table['x'] = x table['y'] = y table['z'] = z return table end <meta> <script src="async.lua" type="shared" /> <script src="client.lua" type="client" cache="false"/> <script src="locations.lua" type="server"/> <script src="server.lua" type="server"/> <export function="getRandomLoot" type="server" /> <export function="spawntables" type="server" /> </meta> This function returns what I want it to when I call it on the same file, but when I try to call this function from another resource: local checkres = exports["NTTC_Tables"]:getRandomLoot("Los Santos") --doesnt work ERROR: ERROR: [NTTC]/NTTC_Account_Management/server.lua:78: attempt to call a nil value [09:06:41] ERROR: [NTTC]/NTTC_Account_Management/server.lua:75: call: failed to call 'NTTC_Tables:getRandomLoot' [string "?"] Line 79 is a timer: function test() local checkres = exports["NTTC_Tables"]:getRandomLoot("Los Santos") --<<<<< line 75 --outputServerLog("X = "..checkres['x']..", Y = "..checkres['y']..", Z ="..checkres['z']) end setTimer( test, 500, 5) --<<<< line 78 I have no idea what is wrong, im running Ubuntu 18.04.1 LTS Thanks in advance EDIT: Found out that the problem is on my function "getRandomLoot" for some reason, it works in the resource no problem but when trying to call it, it shows the error message listed above, im trying to fix it on my own, will edit if I manage to fix it and will post the fix EDIT2: Tried removing the _ from the resource name, didnt fix Edited August 17, 2018 by knightscript added more info #2 Link to comment
Discord Moderators Pirulax Posted August 17, 2018 Discord Moderators Share Posted August 17, 2018 Is the script you're trying to call the export from on server-side? Is the script where 'getRandomLoot' is on server-side? Link to comment
knightscript Posted August 17, 2018 Author Share Posted August 17, 2018 2 minutes ago, Pirulax said: Is the script you're trying to call the export from on server-side? Is the script where 'getRandomLoot' is on server-side? Yes, yes, just figured out that it seems I cant send a table through an export, I tried this: outputServerLog("X = "..exports["NTTC_Tables"]:getRandomLoot("Los Santos")) and on my function function getRandomLoot(location) local number = table.random(locations_for_items_and_spawns) --outputServerLog( number[1]..","..number[2]..","..number[3] ) return "x,y,z" end result: Link to comment
Discord Moderators Pirulax Posted August 17, 2018 Discord Moderators Share Posted August 17, 2018 You should be able to send thru a table without a problem. Link to comment
knightscript Posted August 17, 2018 Author Share Posted August 17, 2018 Just now, Pirulax said: You should be able to send thru a table without a problem. I tried to, wasnt able, was just able to send a string, the table I was trying to send was for example: table = [] table['x'] = x table['y'] = y table['z'] = z return table['x'],table['y'],table['z'] Link to comment
Discord Moderators Pirulax Posted August 17, 2018 Discord Moderators Share Posted August 17, 2018 The table constructor is '{}' not '[]". But, back on topic, I'm sure you can pass a table thru without a problem. If for some reason you really can't, then use toJSON and fromJSON. Link to comment
knightscript Posted August 17, 2018 Author Share Posted August 17, 2018 18 minutes ago, Pirulax said: The table constructor is '{}' not '[]". But, back on topic, I'm sure you can pass a table thru without a problem. If for some reason you really can't, then use toJSON and fromJSON. Thanks, made it work local spawn = exports["NTTC_Tables"]:getRandomLoot("Los Santos") local spawn = exports["NTTC_Tables"]:getRandomLoot("Los Santos") LV = {} LS = {} SF = {} Other = {} function displayLoadedRes ( res ) i = 1 for k,v in pairs(spawntables()) do local zone = getZoneName( v[1],v[2],v[3], true ) if (zone == "Los Santos") then LS[i] = tostring(v[1]..","..v[2]..","..v[3]) i = i+1 end end end addEventHandler ( "onResourceStart", getRootElement(getThisResource( )), displayLoadedRes ) function getRandomLoot(location) --local x,y,z = number[1], number[2], number[3] if (location == "Los Santos") then table = spawntables()[math.random ( #LS )] return table else return "other" end --return LS end Maybe its useful to someone. 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