içine gel ve altta verdiğim kodu arat.
connection = dbConnect( "sqlite", "teams.db" )
dbExec( connection, "CREATE TABLE IF NOT EXISTS teams( teamName TEXT, rgb TEXT )")
function splitTeam( teamRGB )
local t = split( teamRGB, "," )
return t[1], t[2], t[3]
end
function loadTeams( )
local selection = dbQuery( connection, "SELECT * FROM teams" )
local poll = dbPoll( selection, -1 )
if (poll) then
for i, v in ipairs(poll) do
local team, rgb = v.teamName, v.rgb
local r, g, b = splitTeam( rgb )
createTeam( team, r, g, b )
end
end
end
addEventHandler( "onResourceStart", resourceRoot, loadTeams )
addEvent ( "aTeam", true )
addEventHandler ( "aTeam", _root, function ( action, name, r, g, b )
if checkClient( "command."..action, source, 'aTeam', action ) then return end
if ( hasObjectPermissionTo ( source, "command."..action ) ) then
mdata = tostring ( data )
mdata = ""
if ( action == "createteam" ) then
local success = false
if ( tonumber ( r ) ) and ( tonumber ( g ) ) and ( tonumber ( b ) ) then
success = createTeam ( name, tonumber ( r ), tonumber ( g ), tonumber ( b ) )
else
success = createTeam ( name )
end
dbExec( connection, "INSERT INTO teams( teamName, rgb ) VALUES(?,?)", name, tostring(r..","..g..","..b))
if ( not success ) then
action = nil
outputChatBox ( "Team \""..name.."\" could not be created.", source, 255, 0, 0 )
end
elseif ( action == "destroyteam" ) then
local team = getTeamFromName ( name )
if ( getTeamFromName ( name ) ) then
destroyElement ( team )
else
action = nil
end
dbExec( connection, "DELETE FROM teams WHERE teamName=?", name )
else
action = nil
end
if ( action ~= nil ) then aAction ( "server", action, source, false, mdata, mdata2 ) end
return true
end
outputChatBox ( "Access denied for '"..tostring ( action ).."'", source, 255, 168, 0 )
return false
end )