Search the Community

Showing results for tags 'sqlite'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Multi Theft Auto: San Andreas 1.x
    • Support for MTA:SA 1.x
    • Open Source Contributors
    • Suggestions
  • General MTA
    • News
    • Media
    • Site/Forum/IRC/Mantis/Wiki related
    • MTA Chat
    • Other languages
  • community.mtasa.com
    • Scripting
    • Maps
    • Resources
    • Other Creations & GTA modding
    • Competitive gameplay
    • Servers
  • Other
    • General
    • Multi Theft Auto 0.5r2
    • Third party GTA mods
  • Archive
    • Archived Items
    • Trash
  • Private Bugtracker

Found 10 results

  1. So, i choose MTA over SAMP recently, to start learn scripting and developing my own server. Okay... I'm reading some scripts and by them, start browsing about the MTA's integrated systems that could help me develop an amazing or at least good experience, to my self and other players. The first thing that I've been facing is SQLite. I understood that it's a language of some kind to create a database, which could have: group names with their slots and store any change related with those; Items in market with fluctuating price; Car names, colors or price that are owned by the players; Inventory system, etc... But, when i read about SQlite i noticed that there's some features that could be invasive, since it can access third-party programs or CSV files to create analysis between variables. In resume, i want to know if all assets that i could use normally with SQlite is available on MTA:SA.
  2. [HELP] with time count sqlite

    so i have this code exports.scoreboard:addScoreboardColumn( 'time', root, 150 ) -- Online time is the element data local DB = dbConnect( "sqlite", "time.db" ) addEventHandler("onResourceStart", resourceRoot, function ( ... ) dbExec( DB, "CREATE TABLE IF NOT EXISTS online( playerACC, weeks,days, hours, minutes, secs )") for i, player in ipairs( getElementsByType("player") ) do local accountN = getAccountName( getPlayerAccount( player ) ) local getData = dbPoll( dbQuery( DB, "SELECT * FROM online WHERE playerACC=?", accountN), -1 ) if ( #getData == 0 ) then setPlayerTime( player, 0, 0, 0, 0, 0 ) else for i, data in ipairs( getData ) do local weeks = data.weeks or 0 local days = data.days or 0 local hours = data.hours or 0 local minutes = data.minutes or 0 local seconds = data.secs or 0 setPlayerTime( player, weeks ,days, hours, minutes, seconds ) end end setTimer( updatePlayerTime, 1000, 0, player ) end end) addEventHandler("onPlayerLogin", root, function ( ... ) local accountN = getAccountName( getPlayerAccount( source ) ) local getData = dbPoll( dbQuery( DB, "SELECT * FROM online WHERE playerACC=?", accountN), -1 ) if ( #getData == 0 ) then setPlayerTime( source, 0, 0, 0, 0, 0 ) else for i, data in ipairs( getData ) do local weeks = data.weeks or 0 local days = data.days or 0 local hours = data.hours or 0 local minutes = data.minutes or 0 local seconds = data.secs or 0 setPlayerTime( source, weeks ,days, hours, minutes, seconds ) end end setTimer( updatePlayerTime, 1000, 0, source ) end) function setPlayerTime( player, weeks ,days, hours, minutes, secs ) local accountN = getAccountName( getPlayerAccount( player ) ) if ( accountN ) then local dbe = dbQuery( DB, "SELECT * FROM online WHERE playerACC=?", accountN) local result = dbPoll( dbe, -1 ) local realTime = table.concat{ weeks.."w ",days.."d "..hours.."h ", minutes.."min.", secs.."s " } --", secs.."s " setElementData( player, "time", realTime ) if ( #result == 0 ) then dbExec( DB, "INSERT INTO online( playerACC, weeks, days, hours, minutes, secs ) VALUES( ?, ?, ?, ?, ?, ? ) ", accountN, tonumber( weeks ), tonumber( days ), tonumber( hours ), tonumber( minutes ), tonumber( secs ) ) else dbExec( DB, "UPDATE online SET playerACC=?, weeks=?, days=?, hours=?, minutes=?, secs=?", accountN, tonumber( weeks ), tonumber( days ), tonumber( hours ), tonumber( minutes ), tonumber( secs) ) end end end function updatePlayerTime( player ) local accountN = getAccountName( getPlayerAccount( player ) ) if ( accountN ) then local getData = dbPoll( dbQuery( DB, "SELECT * FROM online WHERE playerACC=?", accountN), -1 ) if ( getData ) then for index, data in ipairs( getData ) do data.secs = data.secs + 1 if ( data.secs == 5 ) then data.hours = data.hours + 1 data.secs = 0 elseif ( data.minutes == 60 ) then data.hours = data.hours + 1 data.minutes = 0 elseif ( data.hours == 24 ) then data.days = data.days + 1 data.hours = 0 elseif ( data.days == 7 ) then data.weeks = data.weeks + 1 data.days = 0 end setPlayerTime( player, data.weeks, data.days, data.hours, data.minutes, data.secs ) end end end end And i have 3problems and one question . 1st problem WARNING: [gameplay]/killcount-scoreboard/server.lua 62. bad argument @ 'getAccountName' [Expected element at argument 1] [DUP x11] . 2nd problem that it converts seconds 60sec to 1min i tried changing it and it worked but it can't convert second third and fourth only seconds. 3rd problem that it saves data only to one account for example there is 3players it should load time every player but it load 1st only acc for example on sqlite it shows: Dziugasc I 0weeks I 0days I 15hours I 35minutes I 45 seconds Dziugasc I 0weeks I 0days I 15hours I 35minutes I 45 seconds Dziugasc I 0weeks I 0days I 15hours I 35minutes I 45 seconds And question how to make that it would show only time that player was online for example he was online only 1d and 18hours and on scoreboard it would show 1d 18h in my scoreboard it shows 0w 0d 0h 15min. [I don't need 0 that way it would be nicer to look.
  3. so i tried to make saving system that saves kills and deaths but it doesn't save full script local root = getRootElement() local scoresRoot = getResourceRootElement(getThisResource()) local scoreColumns = {"Kills", "Deaths", "ratio", "status"} local isColumnActive = {} local KDR_DECIMAL_PLACES = 2 --http://lua-users.org/wiki/SimpleRound local function round(num, idp) local mult = 10^(idp or 0) return math.floor(num * mult + 0.5) / mult end local function setScoreData (element, column, data) if isColumnActive[column] then setElementData(element, column, data) end end local dbConnection = dbConnect("sqlite", "backupexprank.db") local qh = dbQuery( dbConnection,"CREATE TABLE IF NOT EXISTS scores (name text,Kills text,Deaths text)") dbFree( qh ) function saveScore(sourcePlayer) local account = getPlayerAccount(sourcePlayer) local name = getAccountName(account) local Kills = getAccountData(account, "Kills") local Deaths = getAccountData(account, "Deaths") local qh = dbQuery( dbConnection, "SELECT * FROM scores where name=?",name) local res = dbPoll(qh,-1) dbFree( qh ) if #res > 0 then dbExec( dbConnection, "UPDATE scores SET Deaths=? where name=? ", Deaths,name ) dbExec( dbConnection, "UPDATE scores SET Kills=? where name=? ", Kills,name ) outputChatBox ( "Saved account " .. name .. " with the Kills " .. Kills .. " with the Deaths" .. Deaths .. " to our database") else dbExec(dbConnection, "INSERT INTO scores VALUES(?, ?, ?)", name, Kills, Deaths) outputChatBox ( "Saved account " .. name .. " with the Kills " .. Kills .. " with the Deaths" .. Deaths .. " to our database") end end addCommandHandler("savestats", saveScore) local function resetScores (element) setScoreData(element, "Kills", 0) setScoreData(element, "Deaths", 0) local status = "" if isPedDead(element) then status = "Dead" end setScoreData(element, "status", status) end local function updateRatio (element) local Deaths = getElementData(element, "Deaths") if Deaths == 0 then setScoreData(element, "ratio", "-") else local kdr = round(getElementData(element, "Kills") / Deaths, KDR_DECIMAL_PLACES) setScoreData(element, "ratio", tostring(kdr)) end end function updateActiveColumns () for i, column in ipairs(scoreColumns) do if get(column) then isColumnActive[column] = true exports.scoreboard:addScoreboardColumn(column) elseif isColumnActive[column] then isColumnActive[column] = false exports.scoreboard:removeScoreboardColumn(column) end end end addEventHandler("onResourceStart", scoresRoot, function () updateActiveColumns() for i, player in ipairs(getElementsByType("player")) do resetScores(player) end end ) addEventHandler("onResourceStop", scoresRoot, function () for i, column in ipairs(scoreColumns) do if isColumnActive[column] then exports.scoreboard:removeScoreboardColumn(column) end end end ) addEventHandler("onPlayerJoin", root, function () resetScores(source) end ) addEventHandler("onPlayerWasted", root, function (ammo, killer, weapon) if killer then if killer ~= source then -- killer killed victim setScoreData(killer, "Kills", getElementData(killer, "Kills") + 1) setScoreData(source, "Deaths", getElementData(source, "Deaths") + 1) if isColumnActive["ratio"] then updateRatio(killer) updateRatio(source) end else -- victim killed himself setScoreData(source, "self", getElementData(source, "self") + 1) end else -- victim died setScoreData(source, "Deaths", getElementData(source, "Deaths") + 1) if isColumnActive["ratio"] then updateRatio(source) end end setScoreData(source, "status", "Dead") end ) addEventHandler("onPlayerSpawn", root, function () setScoreData(source, "status", "") end ) i need that it would save always without typing command like player died save to db
  4. MySQL internal dbs

    How can I change the MTA internal db (internal.db and registry.db) to MySQL, maintening the functions like getAccountData, getElementData ?
  5. Problemas com Database "sqlite"

  6. Hello fellows how are you ? Today i want to use database connections Into a simple script that im gonna make about user settings The script is simple a gui opens up and the user selects if he wants to enable disable some graphical settings (car reflection, water, detail, contrast, show fps counter etc blah blah) Script is made and works perfect but i want to save each user settings to database(sqlite for now since i don't want to have remote control of database for now so mysql is not needed) so when he logs on to server the settings he set before will be applied, and also if hes new user server will make a new list in database for that user with default settings (1(enable) for each setting)) anyway i don't need you to tell me how exaclty im gonna code that cause you will get through much work but i want to give me the idea how the hell am i gonna do this because the wiki is helpless in these things if you want some example how bad i am in scripting sql see below: playerSettings = {} function playerJoin() local settingsQuery = dbQuerry(connectionDb,"select * from settings") local settingsQueryResult = dbPoll(settingsQuery, -1) for i, user in pairs(settingsQueryResult) do local playerName = getAccountName(source) table.insert(playerSettings,playerName) end end addEventHandler("onPlayerJoin", resourceRoot, playerJoin) thanks in advance
  7. Hello guys, Yesterday I didn't have anything to do so I decided to convert MTA Paradise to SQLite, ( just the sql resource needs to be changed ). The resource has not all the capabilities of the original one like editing already existing columns, but the other features are working OK. Now you won't need any mySQL host or module http://www72.zippyshare.com/v/CeQ6O7FB/file.html
  8. UPDATE query

    When i try updating the database it does not work when using the WHERE clause... I get no errors. Here's all the code
  9. dbQuery Result?

    I have the following, which just gets "skin", "cash" and "wasWanted" from the DB function spawnOnLogin () playerName = getPlayerName(source) local findPlayer = dbQuery(db, "SELECT `skin`, `cash`, `wasWanted` FROM player_stuff WHERE name=?", playerName ) local dataresult = dbPoll ( findPlayer, -1 ) if dataresult[1] then local skin = dataresult["skin"] local cash = dataresult["cash"] local wasWanted = dataresult["wasWanted"] end end addEventHandler("onPlayerJoin", getRootElement(), spawnOnLogin) the variables "skin", "cash" and "wasWanted" all come back nil, since I can't work out the right way to get the result. Been looking for ages but can't find the right way to do it, can someone explain to me how I retrieve these values from the query result properly? Thanks
  10. SQLite de nuevo...

    Estoy creando un sistema de guardado de cuentas en SQLite pero tengo problemas. Con el código a continuación, cuando le doy a registrar, siempre me dice que hay una cuenta ya creada (cuando la .db está vacía) y cuando le doy a loguear, con lo que sea, puedo entrar. addEventHandler( "onResourceStart", resourceRoot, function( ) sql = dbConnect ( "sqlite" , "accounts.db" ) -- Create the connection playersTable = dbQuery ( sql , "CREATE TABLE IF NOT EXISTS accounts (account TEXT,password TEXT,serial TEXT)" ) if fileExists( "accounts.db" ) and sql and playersTable then outputDebugString( "Succefully connected SQLite resource" ) else outputDebugString( "Failed to connect SQLite" ) end end ) function tryRegister( player, username, password ) if username and password then local exists = dbQuery ( sql , "SELECT * FROM accounts WHERE account = ?", username ) local result = dbPoll( exists, 0 ) if result then triggerClientEvent( player, "loginPanel:executeMessage", player, "Account already exists" ) return else local serial = getPlayerSerial( player ) if serial then local qh = dbQuery ( sql , "INSERT INTO accounts (account,password,serial) VALUES (?,?,?)", username, password, serial ) local result = dbPoll( qh, -1 ) if result then triggerClientEvent( player, "loginPanel:executeMessage", player, "Succefully registered. Welcome" ) return true else triggerClientEvent( player, "loginPanel:executeMessage", player, "Error, contact with server admin" ) return end else triggerClientEvent( player, "loginPanel:executeMessage", player, "Fatal error. No serial found." ) return end end else triggerClientEvent( player, "loginPanel:executeMessage", player, "Type username and password" ) return end end function tryLogin( player, username, password ) if username and password then local exists = dbQuery ( sql , "SELECT * FROM accounts WHERE account = ? AND password = ?", username, password ) local result = dbPoll( exists, -1 ) if result then local x, y, z = 2272.0419921875, 2354.5302734375, 4.8202133178711 spawnPlayer( player, x, y, z ) triggerClientEvent(client, "onClientPlayerLogin", client) return true else triggerClientEvent( player, "loginPanel:executeMessage", player, "Account does not exists" ) return end else triggerClientEvent( player, "loginPanel:executeMessage", player, "Type username and password" ) return end end function performLogin (username, password, type) local account = getAccount( username, password ) if type == "login" then tryLogin( client, username, password ) elseif type == "register" then if username and #username > 3 then if password and #password > 8 then tryRegister( client, username, password ) else triggerClientEvent( client, "loginPanel:executeMessage", client, "Required password characters: 8" ) end else triggerClientEvent( client, "loginPanel:executeMessage", client, "Incorrect username. More than 3 characters" ) end elseif type == "leave" then kickPlayer ( client, "See you soon (Leaving)" ) end end addEvent("loginPanel:performLogin", true) addEventHandler("loginPanel:performLogin", root, performLogin ) ¿Me echan una mano? No sé como funciona correctamente el dbPoll y demás PD: Disculpad los dos temas, con el nuevo diseño no puedo borrar