Imposter Posted July 30, 2012 Share Posted July 30, 2012 Im making a furniture system based off of the housesystem_mysql by NoneAtMe and i changed many parts of it ( im using it because i dont really know how to link mysql with mta. I have an error at line 68 [2012-07-30 08:44:47] ERROR: [roleplay]\furniture\server.lua:68: attempt to index global 'furniture' (a nil value) Server Side ------------------------------------------- --------------MySQL Connection------------- ------------------------------------------- local hostip = "127.0.0.1" local username = "root" local password = "" local database = "db_furniture" local dbpTime = 500 ------------------------------------------- ------------Connect On Startup------------- ------------------------------------------- addEventHandler("onResourceStart", getResourceRootElement(), function() handler = dbConnect("mysql", "dbname="..database..";host="..hostip, username, password, "autoreconnect=1") if not(handler) then outputServerLog("[FurnitureSystem] Could not connect to the MySQL Server, shutting down...") outputChatBox("[FurnitureSystem] Could not connect to the MySQL Server, shutting down...") else outputServerLog("[FurnitureSystem] Successfully connected to the MySQL Server, loading...") outputChatBox("[FurnitureSystem] Successfully connected to the MySQL Server, loading...") furniture_onLoad() end end) ------------------------------------------- --------Create Furniture On Startup-------- ------------------------------------------- function furniture_onLoad() if(created == true) then error("The furniture has already been created upon execution!") return end buildStartTick = getTickCount() local query = dbQuery(handler, "SELECT * FROM objects;" ) local result, numrows = dbPoll(query, dbpTime) outputChatBox(tonumber(numrows)) total = tonumber(numrows) if (result) then if (numrows > 0) then for index, row in pairs(result) do local id = row['id'] local owner = row['owner'] local price = row['price'] local posx, posy, posz, rot = row['posx'], row['posy'], row['poz'], row['rot'] local int, dim = row['int'], row['dim'] -- loadFurniture(id, owner, price, posx, posy, posz, rot, int, dim) end dbFree(query) else error("Furniture Table is empty!") end else error("Furniture Table not Found!") end created = true setTimer(function() local elapsed = (buildEndTick-buildStartTick) outputServerLog("It took "..(elapsed/1000).." seconds to build all the furniture.") end, 1000, 1) end local function createFurniture(id, owner, price, posx, posy, posz, rot, int, dim) if(id) and (owner) and (posx) and (posy) and (posz) and (rot) and (price) and (int) and (dim) then furnitureID = id furniture[total+1] = createObject(id, posx, posy, posz, rot, 0, 0 ) -- This is the object furnitureData[id] = {} local furniture = furniture[id] -- I'm too lazy... setElementData(furniture, "furniture", true) -- Just for client code only setElementInterior(furniture, int) setElementDimension(furniture, dim) -- Set data for HOUSE -- furnitureData[id]["id"] = id furnitureData[id]["owner"] = owner furnitureData[id]["price"] = price furnitureData[id]["posx"] = posx furnitureData[id]["posy"] = posy furnitureData[id]["posz"] = posz furnitureData[id]["rot"] = rot furnitureData[id]["int"] = int furnitureData[id]["dim"] = dim setElementData(furniture, "id", id) setElementData(furniture, "owner", owner) setElementData(furniture, "price", price) setElementData(furniture, "posx", posx) setElementData(furniture, "posy", posy) setElementData(furniture, "posz", posz) setElementData(furniture, "rot", rot) setElementData(furniture, "int", int) setElementData(furniture, "dim", dim) outputServerLog("[FURNITURESYSTEM] Furniture with ID "..id.." created sucessfully!") buildEndTick = getTickCount() -- TRIGGER TO ALL CLIENTS THAT THE FURNITURE HAS BEEN CREATED -- -- setTimer(triggerClientEvent, 1000, 1, "onClientFurnitureSystemObjectMade", getRootElement(), furniture) else if not(id) then error("[FURNITURESYSTEM] Missing ID! Cannot create furniture!") else error("[FURNITURESYSTEM] Missing/Invalid Arguements") end end end function makeFurniture(thePlayer, command) local id = 2896 local owner = getAccountName(getPlayerAccount(thePlayer)) local price = math.random(100,200) local int = 1 local dim = 1 local posx, posy, posz = getElementPosition(thePlayer) local rot = getPedRotation(thePlayer) createFurniture(id, owner, price, posx, posy, posz, rot, int, dim) end addCommandHandler ( "makefurniture", makeFurniture ) Link to comment
Anderl Posted July 30, 2012 Share Posted July 30, 2012 This code is copied from other script, right? Because there isn't any table declared in your code. Link to comment
Imposter Posted July 30, 2012 Author Share Posted July 30, 2012 This code is copied from other script, right?Because there isn't any table declared in your code. How would i declare the table? Link to comment
Anderl Posted July 30, 2012 Share Posted July 30, 2012 lol, if you don't know this basic thing, start learning LUA. Link to comment
Imposter Posted July 30, 2012 Author Share Posted July 30, 2012 lol, if you don't know this basic thing, start learning LUA. Oh sorry im didn't understand what u meant, and BTW learnng lua is exactly what im doing, i just need this script because i dont know how to integrate MySQL into MTASA furniture = {} Link to comment
robhol Posted July 30, 2012 Share Posted July 30, 2012 No seriously, he's right. Read some basics on the language before you try doing anything. Cutting and pasting other people's scripts is not a good way to learn OR get anything done. Link to comment
Imposter Posted July 30, 2012 Author Share Posted July 30, 2012 No seriously, he's right. Read some basics on the language before you try doing anything. Cutting and pasting other people's scripts is not a good way to learn OR get anything done. I dont know where to start, should I do those wiki tutorials? Link to comment
Imposter Posted July 30, 2012 Author Share Posted July 30, 2012 But can you guys still tell me how to do it? Still no help? Link to comment
manve1 Posted July 30, 2012 Share Posted July 30, 2012 hey NooP, its me manve btw, try this: furnitureID = getID Link to comment
Imposter Posted July 30, 2012 Author Share Posted July 30, 2012 hey NooP, its me manve btw, try this: furnitureID = getID Where should i put it? LOL just noticed hope i see u there sometime Link to comment
manve1 Posted July 30, 2012 Share Posted July 30, 2012 put the lua code in line 68. change line 68 to this what i gave you, should work Link to comment
Imposter Posted July 30, 2012 Author Share Posted July 30, 2012 put the lua code in line 68. change line 68 to this what i gave you, should work but getID is not declared 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