..:D&G:.. Posted February 3, 2015 Share Posted February 3, 2015 Hello everyone! I am trying to make a slot machine system that saves in SQLite and I would like to know how can I add an unique ID to each slot machine created? Here is the code I made for adding. function createSlotmachine(thePlayer, ...) if thePlayer and isObjectInACLGroup("user." .. getAccountName(getPlayerAccount(thePlayer)), aclGetGroup("Admin")) then local dimension = getElementDimension(thePlayer) local interior = getElementInterior(thePlayer) local x, y, z = getElementPosition(thePlayer) local rotation = getPedRotation(thePlayer) z = z - 0.3 local id = executeSQLQuery("INSERT INTO 'slotmachines'('id','x','y','z','rotation','interior','dimension') VALUES(?,?,?,?,?,?,?)", id, x, ,y, z, rotation, interior, dimension ) if (id) then local object = createSlotMachine(x, y, z+0.58, 0, 0, rotation-180, interior, dimension) setElementData(object, "dbid", id) local px = x + math.sin(math.rad(-rotation)) * 0.8 local py = y + math.cos(math.rad(-rotation)) * 0.8 local pz = z x = x + ((math.cos(math.rad(rotation)))*5) y = y + ((math.sin(math.rad(rotation)))*5) setElementPosition(thePlayer, x, y, z) outputChatBox("Slot machine created with ID #" .. id .. "!", thePlayer, 0, 255, 0) else outputChatBox("There was an error while creating a slot machine Try again.", thePlayer, 255, 0, 0) end end end addCommandHandler("addslotm", createSlotmachine) I tried to do something before, but when I look at it know it makes no sense Anyone know how to add an unique ID? Link to comment
Killer... Posted February 4, 2015 Share Posted February 4, 2015 I will try to help you. Link to comment
Killer... Posted February 4, 2015 Share Posted February 4, 2015 I think that this will function correctly. function createSlotmachine(thePlayer, ...) if thePlayer and isObjectInACLGroup("user." .. getAccountName(getPlayerAccount(thePlayer)), aclGetGroup("Admin")) then local dimension = getElementDimension(thePlayer) local interior = getElementInterior(thePlayer) local x, y, z = getElementPosition(thePlayer) local rotation = getPedRotation(thePlayer) z = z - 0.3 local slotID = exports.sql:query_insertid( "INSERT INTO slotmachine (x, y, z, rotation, interior, dimension) VALUES (" .. table.concat( { x, y, z, rotation, interior, dimension }, ", " ) .. ")" ) if slotID then local object = createSlotMachine(x, y, z+0.58, 0, 0, rotation-180, interior, dimension) setElementData(object, "dbid", slotID) local px = x + math.sin(math.rad(-rotation)) * 0.8 local py = y + math.cos(math.rad(-rotation)) * 0.8 local pz = z x = x + ((math.cos(math.rad(rotation)))*5) y = y + ((math.sin(math.rad(rotation)))*5) setElementPosition(thePlayer, x, y, z) outputChatBox("Slot machine created with ID #" .. slotID .. "!", thePlayer, 0, 255, 0) else outputChatBox("There was an error while creating a slot machine Try again.", thePlayer, 255, 0, 0) end end end addCommandHandler("addslotm", createSlotmachine) Link to comment
..:D&G:.. Posted February 4, 2015 Author Share Posted February 4, 2015 Um.. thanks for trying but WTF is that? You changed my SQLite line into the mysql one from mta paradise (doesn't even save an ID) and you replaced my "id" with "slotID" Thanks for trying to help anyway 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