Skip to content

Instantly share code, notes, and snippets.

@matheusgimenez
Forked from anonymous/gist:26d8d036b20d74133867
Last active August 29, 2015 14:06
Show Gist options
  • Save matheusgimenez/4feed09d9cd62f06651b to your computer and use it in GitHub Desktop.
Save matheusgimenez/4feed09d9cd62f06651b to your computer and use it in GitHub Desktop.
gDB = dbConnect( "sqlite", "gangs.db" )
dbExec(gDB, "CREATE TABLE IF NOT EXISTS gangs (gang_name TEXT, gang_tag TEXT, gang_cor TEXT, gang_lider TEXT)")
function cCriar (player, cmd, cor, tag, ...)
local account = getPlayerAccount(player)
if cor and tag and {...} then
if tag:len() < 6 then
if not({...} == "") then
local name = table.concat({...}," ")
if checkTeamName(name) == false then
if hex2rgb(cor) then
createTeam(name, hex2rgb(cor))
outputChatBox ("Clã criado com sucesso!", player)
local leader = getAccountName(account)
dbExec(gDB, "INSERT INTO gangs (gang_name, gang_tag, gang_cor, gang_lider) VALUES(?,?,?,?)",name,tag,cor,leader)
-- ARMAZENAR TAG
-- ARMAZENAR NOME
-- ARMAZENAR COR
-- ARMAZENAR LÍDER
else
outputChatBox ("Código de cor inválido.", player)
end
else
outputChatBox ("Nome da gang já em uso.", player)
end
else
outputChatBox ("Mencione o nome do clã corretamente.", player)
end
else
outputChatBox ("Limite de caracteres da tag excedido. (Limite: 5)", player)
end
else
outputChatBox ("Alguns argumentos estão faltando.", player)
end
end
addCommandHandler ("ccriar", cCriar)
function teste(source)
local gangs = dbQuery(gDB,"SELECT * FROM gangs")
local gangs_table = dbPoll( gangs, 0 )
if gangs_table then
for _, row in ipairs ( gangs_table ) do
outputChatBox ( row["gang_name"] ) -- it will output the value of the column "column" in this certain row
end
end
end
addCommandHandler ("teste_gangs", teste)
function checkTeamName(name)
for i,t in ipairs(getElementsByType('team')) do
if name == getTeamName(t) then
return true
else
return false
end
end
end
function hex2rgb(hex)
hex = hex:gsub("#","")
return tonumber("0x"..hex:sub(1,2)), tonumber("0x"..hex:sub(3,4)), tonumber("0x"..hex:sub(5,6))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment