OrbTanT Posted November 28, 2016 Share Posted November 28, 2016 Good start with a gang system using sqlite to save the data, a part of creating a gang is working even more with future updates, I'm new using SQLite and I'm not able to do anything I like how to pull the player's level in the function GetPlayerGangLevel, I'm not sure how to check a table. You are experiencing the following error: ERROR: gangsystem\server.lua:33: attempt to call upvalue 'db' (a userdata value) local db = dbConnect("sqlite", "/testegang.db") dbExec(db, "CREATE TABLE IF NOT EXISTS gangues (name TEXT, leader TEXT, gangcolor TEXT)") dbExec(db, "CREATE TABLE IF NOT EXISTS ganguemembers (account TEXT, gangName TEXT, level TEXT)") addEventHandler ( "onResourceStart", resourceRoot, function ( ) exports.scoreboard:scoreboardAddColumn ( "Gang Level", getRootElement ( ), 90, "Gang Level", 12 ) for i, v in pairs ( getElementsByType ( "player" ) ) do local gangTeam = getElementData ( v, "Gang" ) if ( not gangTeam ) then setElementData ( v, "Gang", nil ) setElementData ( v, "Gang Level", nil) end if ( not getElementData ( v, "Gang Level" ) ) then setElementData ( v, "Gang Level", nil ) end end end ) local maxStr = 20 function gangIsLeader ( player, team ) local select = dbExec(db "SELECT leader FROM gangues WHERE name = '" ..team.. "' " ); if ( select[1]["leader"] == player ) then return true; else return false; end end function getPlayerGangLevel ( player ) local select = dbExec(db "SELECT account FROM ganguemembers WHERE account = '" ..player.. "' " ); if ( select[1]["account"] == player ) then return select["level"] else return false; end end function testePlayerLevel(player, commandName) mylevel = getPlayerGangLevel(player) outputChatBox("Meu level é: "..myLevel, player, 255, 255, 0, false) end addCommandHandler("getlevel", testePlayerLevel) function setPlayerGang ( player, team, level ) dbExec(db, "INSERT INTO ganguemembers VALUES (?, ?, ?)", getPlayerName(player), tostring(team), tostring(level)) setPlayerTeam(player, getTeamFromName(team)) setElementData(player, "Gang", getTeamFromName(team)) outputDebugString(getPlayerName(player).." entrou na gang "..team.." como: "..level) end function createGang(name, owner) local color = {math.random(255), math.random(255), math.random(255)} r, g, b = unpack(color) createTeam(name, r, g, b) dbExec(db, "INSERT INTO gangues VALUES (?, ?, ?)", name, getPlayerName(owner), toJSON(color)) outputDebugString(getPlayerName(owner).." criou a gang: "..name) end function criarGang ( source, commandName, teamName ) local getMoney = getPlayerMoney ( source ) if ( teamName ) then if ( getMoney < 400000 ) then outputChatBox ( "#F4A460[GANG]#F08080 Você não tem dinheiro suficiente para criar uma gang Valor 400000$", source, 255, 255, 255, true ) elseif ( string.len ( teamName ) > maxStr ) then outputChatBox ( "#1e90ff[GANG] #ffffff- O Nome da Gang nao pode ter mais de " .. maxStr .. " caracteres!", uPed, 255, 255, 255, true ); else createGang ( teamName, source ) takePlayerMoney ( source, 400000 ) setPlayerGang ( source, teamName, "Lider" ) setElementData(source, "Gang Level", "Lider") end else outputChatBox ( "#F4A460[GANG]#F08080 Uso correto: /fundargang [nome]", source, 255, 255, 255, true ) end end addCommandHandler ( "gangcriar", criarGang ) Link to comment
SheriFF Posted November 28, 2016 Share Posted November 28, 2016 You forgot to put a comma.In line 33 replace this : local select = dbExec(db "SELECT account FROM ganguemembers WHERE account = '" ..player.. "' " ); with this : local select = dbExec(db,"SELECT account FROM ganguemembers WHERE account = '" ..player.. "' " ); Link to comment
OrbTanT Posted November 28, 2016 Author Share Posted November 28, 2016 Ours, I searched and looked for the error and had not noticed, thank you Link to comment
OrbTanT Posted November 28, 2016 Author Share Posted November 28, 2016 Can you tell me which way to get information from the table, I'm trying to pull the player's level, but is giving error ERROR: gangsystem\server.lua:34: attempt to index local 'select' (a boolean value) function getPlayerGangLevel ( player ) local select = dbExec(db, "SELECT level FROM ganguemembers WHERE account = '" ..getPlayerName(player).. "' " ); return select["level"] end function testePlayerLevel(player, commandName) mylevel = getPlayerGangLevel(player) outputChatBox("Meu level é: "..myLevel, player, 255, 255, 0, false) end addCommandHandler("getlevel", testePlayerLevel) Link to comment
ViRuZGamiing Posted November 28, 2016 Share Posted November 28, 2016 37 minutes ago, Shinigami said: Can you tell me which way to get information from the table, I'm trying to pull the player's level, but is giving error ERROR: gangsystem\server.lua:34: attempt to index local 'select' (a boolean value) function getPlayerGangLevel ( player ) local select = dbExec(db, "SELECT level FROM ganguemembers WHERE account = '" ..getPlayerName(player).. "' " ); return select["level"] end function testePlayerLevel(player, commandName) mylevel = getPlayerGangLevel(player) outputChatBox("Meu level é: "..myLevel, player, 255, 255, 0, false) end addCommandHandler("getlevel", testePlayerLevel) you can't use select as variable name since it's LUA predefined Link to comment
OrbTanT Posted November 28, 2016 Author Share Posted November 28, 2016 So the code is working well? Just change the part of select? Nothing works, does not pull the ganguemembers table player level. function getPlayerGangLevel ( player ) local myLevel = dbExec(db, "SELECT level FROM ganguemembers WHERE account = '" ..getPlayerName(player).. "' " ); return myLevel[1]["level"] end function testePlayerLevel(player, commandName) mylevel = getPlayerGangLevel(player) outputChatBox("Meu level é: "..myLevel, player, 255, 255, 0, false) end addCommandHandler("getlevel", testePlayerLevel) Link to comment
ViRuZGamiing Posted November 28, 2016 Share Posted November 28, 2016 Try outputting your query result to see what you get Link to comment
OrbTanT Posted November 28, 2016 Author Share Posted November 28, 2016 It returned right in the outputDebugString, I should be using sqlite in the wrong way, I can not get the level that is stored there, as Leader or Member function getPlayerGangLevel ( player, commandName ) local myLevel = dbExec(db, "SELECT level FROM ganguemembers WHERE account = '" ..getPlayerName(player).. "' " ); if (myLevel) then return outputDebugString("meu level") else return outputDebugString("falha em puxar o level do jogador") end end addCommandHandler("getlevel", getPlayerGangLevel) Link to comment
pa3ck Posted November 29, 2016 Share Posted November 29, 2016 I have always used MySQL instead of SQLite, but don't you have to use dbPoll with SQLite as well? I would also recommend using dbQuery when reading from SQL and dbExec when writing. Link to comment
OrbTanT Posted November 29, 2016 Author Share Posted November 29, 2016 Thanks for the tips, I'll study more. Link to comment
OrbTanT Posted November 30, 2016 Author Share Posted November 30, 2016 Personal is happening next mistake, I do not understand what is wrong. WARNING: gangsystem\server.lua:2: dbExec failed; (1) AUTOINCREMENT is only allowed on an INTEGER PRIMARY KEY dbExec(db, "CREATE TABLE IF NOT EXISTS gangs (gang_cod INT PRIMARY KEY AUTOINCREMENT, name TEXT, owner TEXT, color TEXT)") Link to comment
SheriFF Posted November 30, 2016 Share Posted November 30, 2016 The error says that AUTOINCREMENT is compatible only with INTEGER PRIMARY KEY You declared gang_cod as an INT PRIMARY KEY AUTOINCREMENT , but this type doesn't exists Replace INT with INTEGER and the script should work 1 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