Jump to content

help SQLite gang


OrbTanT

Recommended Posts

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

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
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

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...