handler = dbConnect("sqlite", "team.db")
dbExec(handler, "CREATE TABLE IF NOT EXISTS 'organizacje' (organizacja TEXT, wlasciciel TEXT, r INTEGER, g INTEGER, b INTEGER)")
function org()
local query = dbQuery(handler, "SELECT * FROM organizacje")
local result, num_rows, errormsg = dbPoll (query, -1)
for i,v in pairs(result) do
local team = createTeam(v["organizacja"] ,tonumber(v["r"]), tonumber(v["g"]), tonumber(v["b"]))
if team then
setElementData(team, "wlasciciel", v["wlasciciel"])
setPlayerTeam(, team)
end
end
end
addEventHandler("onResourceStart", getRootElement(), org)
function zapiszOrg()
for i,v in pairs(getElementsByType("team")) do
local owner = getElementData(v, "wlasciciel")
if owner then
local r, g, b = getTeamColor(v)
local team = getTeamName(v)
dbExec(handler, "INSERT INTO 'organizacje' (organizacja, wlasciciel, r, g, b) VALUES (?,?,?,?,?)", team, owner, r, g, b)
end
end
end
setTimer(zapiszOrg, 5000, 0)
addEventHandler("onResourceStop", getRootElement(), zapiszOrg)
function asd(plr, cmd, team, r, g, b)
if team and r and g and b then
local team = createTeam(team, r, g, b)
setElementData(team, "wlasciciel", getPlayerName(plr))
outputChatBox("Stworzyles team o nazwe: "..getTeamName(team).." Wlasciciel: "..getElementData(team, "wlasciciel").." aby dodac kogos wpisz /organizacja dodaj nick", plr, 255,255,255,true)
setPlayerTeam(plr,team)
else
outputChatBox("#ff0000Nie mozesz stworzyc organizacji.", plr, 255,255,255,true)
end
end
addCommandHandler("organizacja", asd)
function dodajlogin()
if getAccountData(plr, "organizacja") then
setElementData(plr, "organizacja", getAccountData(plr, "organizacja"))
end
end
addEventHandler("onPlayerLogin", getRootElement(), dodajlogin)
function wyjdz(plr)
if getElementData(plr, "organizacja") then
setAccountData(getAccountName(plr), "organizacja", getTeamName(getPlayerTeam(plr)))
end
end
addEventHandler("onPlayerQuit", getRootElement(), wyjdz)