Jump to content

Search the Community

Showing results for tags 'id system'.

  • 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
    • User Guides
    • Open Source Contributors
    • Suggestions
    • Ban appeals
  • General MTA
    • News
    • Media
    • Site/Forum/Discord/Mantis/Wiki related
    • MTA Chat
    • Other languages
  • MTA Community
    • 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

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Gang


Location


Occupation


Interests

Found 3 results

  1. Hello everybody! I'd like to introduce you my own-made systems based on internal.db for small gamemodes or simple servers. I was thinking about how good it'd be if we'd have an abillity to work with account's saved data better and faster only using standard MTA database. I've been looking for an information that could help me to put a lot of data (as player's position, skin, money and so on) in 1 key to internal.db account's data. As for me - this is the best way of using saveAccountData() for non-global servers because it reduces the amount of trash-files in database. I made some researches on that and found out that it doesn't affect the perfomance. Download: https://community.multitheftauto.com/index.php?p=resources&s=details&id=18786 Preview: ------------------------------- ----ACCOUNT ID SYSTEM UTILS---- ------------------------------- function getAccountDatabaseID( account ) if account and not isGuestAccount( account ) then accID = 0 -- Set account ID to default if getAccountData( account, "data" ) and getAccountData( account, "data" ) ~= nil then -- Check out for account's data table local data = fromJSON( getAccountData( account, "data" ) ) -- Get account's data table if data[ "ID" ] == nil then accID = 0 -- Set account ID to default in cause of ID == nil else accID = data[ "ID" ] -- Set account ID to account's data table ID end else accID = 0 -- Set account ID to default in cause of account's data table == nil end return accID -- Return account's ID end end function getFreeDatabaseID() local accounts = getAccounts() missedID = false -- Set an ID to default for operation for i, v in pairs( accounts ) do -- Start a loop for all server accounts if i ~= getAccountDatabaseID( v ) then missedID = i break end end if missedID ~= false then return missedID --[[ ETC: There were 5 accounts. The 3rd one have been deleted. To avoid dissolution of an ID after deleting account we look for the gap and fill it with new account. It means that new account, created afther the 5th, would get 3rd ID of deleted account. --]] else return #accounts + 1 -- There were no gaps in ID row, so we return ID as a count of all accounts + created one. end end ----------------------------------------- ----ACCOUNT ID SYSTEM UTILS ENDS HERE---- ----------------------------------------- -------------------------- ----ACCOUNT DATA TABLE---- -------------------------- function getAccountDataTable( account ) if account and not isGuestAccount( account ) then if getAccountData( account, "data" ) and getAccountData( account, "data" ) ~= nil then local data = fromJSON( getAccountData( account, "data" ) ) -- Get account data table local id = data[ "ID" ] -- Get account ID from data table local position = data[ "Position" ] -- Get account position from data table local skin = data[ "Skin" ] -- Get account skin from data table local money = data[ "Money" ] -- Get account money from data table return id, position, skin, money -- Return all collected data end end end function saveAccountDataTable( account, data ) if account and not isGuestAccount( account ) then setAccountData( account, "data", data ) end end addEvent( "saveAccountDataTable", true ) addEventHandler( "saveAccountDataTable", getRootElement(), saveAccountDataTable ) function getPlayerDataTable( player ) local x, y, z = getElementPosition( player ) -- Get player's position local rotx, roty, rotz = getElementRotation( player ) -- Get player's rotation local interior = getElementInterior( player ) -- Get player's current interior local dimension = getElementDimension( player ) -- Get player's current dimension local skin = getElementModel( player ) -- Get player's skin local money = getPlayerMoney( player ) -- Get player's money local accID = getElementData( player, "ID" ) or 0 -- Get player's account ID ---- local data = toJSON( { [ "ID" ] = accID, -- Prepare account ID to save [ "Position" ] = { x, y, z, rotz, interior, dimension }, -- Prepare player's position to save [ "Skin" ] = skin, -- Prepare skin to save [ "Money" ] = money, -- Prepare money to save } ) ---- return data -- Return all data that we've collected from the player end ------------------------------------ ----ACCOUNT DATA TABLE ENDS HERE---- ------------------------------------ ---------------------------------------- ----IMPLEMENT ALL STUFF THAT WE HAVE---- ---------------------------------------- addEventHandler( "onPlayerLogin", getRootElement(), function( _, account ) if account and not isGuestAccount( account ) then if getAccountData( account, "data" ) and getAccountData( account, "data" ) ~= nil then ---------------------------------------------------- ----Spawn player from saved account's data table---- ---------------------------------------------------- local ID, position, skin, money = getAccountDataTable( account ) spawnPlayer( source, position[ 1 ], position[ 2 ], position[ 3 ], position[ 4 ], skin, position[ 5 ], position[ 6 ] ) fadeCamera( source, true, 3 ) setCameraTarget( source, source ) setPlayerMoney( source, money, true ) setElementData( source, "ID", ID ) -- Apply player's ID outputChatBox( "Welcome back, "..getPlayerName( source ).."!", source, 255, 255, 255, true ) -- Output a welcome message outputChatBox( "Your ID: "..ID, source, 255, 255, 255, true ) -- Output a message to chat for logged player to make a sure that we've got the right ID else ------------------------------------------------------------------------------- ----Spawn player for the first time or in cause of data table reading error---- ------------------------------------------------------------------------------- local ID = getFreeDatabaseID() -- Get free ID for our player to apply it later spawnPlayer( source, 0, 0, 0, 0, 0, 0, 0 ) fadeCamera( source, true, 3 ) setCameraTarget( source, source ) setPlayerMoney( source, 0, true ) setElementData( source, "ID", ID ) -- Apply player's ID outputChatBox( "First time, "..getPlayerName( source ).."? Welcome!", source, 255, 255, 255, true ) -- Output a welcome message outputChatBox( "Your ID: "..ID, source, 255, 255, 255, true ) -- Output a message to chat for logged player to make a sure that we've got the right ID end end end) addEventHandler( "onPlayerLogout", getRootElement(), function( account, _ ) local data = getPlayerDataTable( source ) -- Get player's data to save it saveAccountDataTable( account, data ) -- Save player's data table on log out end) addEventHandler( "onPlayerQuit", getRootElement(), function() local account = getPlayerAccount( source ) local data = getPlayerDataTable( source ) -- Get player's data to save it saveAccountDataTable( account, data ) -- Save player's data table on exit end) P.S: I appreciate any opinion and advice, thank you!? You can use this script for any purpose - the code is opened! I've also tried to explain the whole script. I hope it'd help! Download: https://community.multitheftauto.com/index.php?p=resources&s=details&id=18786
  2. Yesterday evening, I started my apprenticeship with db, I always wanted to learn, because with it, I can do mods, which I could not do without. My introduction with Database was done by adapting a System ID to the DB in the login panel. I did this using the server-side of my login panel. The first thing we do, is to use dbConnect (Wiki), which will make the connection to the db file. local db = dbConnect("sqlite", "db/royalusers.db") It will create the "db" folder, in the resource files, and inside the folder, the "royalusers.db" file. After that, we create a table using the SQL functions. local newTable = dbExec(db, "CREATE TABLE IF NOT EXISTS RoyalUsers (id INT, name TEXT, login TEXT, pass TEXT, serial TEXT)") RoyalUsers - Table-name id INT, name TEXT, login TEXT, pass TEXT, serial TEXT - columns of the table. INT - INTERNAL NUMBER Now the part of using the table defined in the database. function registerPlayer(user, pass, conf) if user == "" then outputLoginMsg(source, "Preencha todos os campos!", "error") else if pass == "" then outputLoginMsg(source, "Preencha todos os campos!", "error") else if conf == "" then outputLoginMsg(source, "Preencha todos os campos!", "error") else if conf == pass then addAccount(tostring(user),tostring(pass)) triggerClientEvent(source, "onRoyalRegister", source) local query = dbPoll(dbQuery(db, "SELECT * FROM RoyalUsers WHERE login=?", user),-1) if #query == 0 then dbExec(db, "INSERT INTO RoyalUsers VALUES (?, ?, ?, ?, ?)", countIDs(), getPlayerName(source), user, pass, getPlayerSerial(source)) end outputLoginMsg(source, "Conta criada com sucesso! Aguarde...", "success") if not getAccount(user, pass) then outputLoginMsg(source, "Esta conta já está sendo utilizada!", "error") end else outputLoginMsg(source, "As senhas não estão iguais.", "error") end end end end end addEvent("onPlayerRequestRegister", true) addEventHandler("onPlayerRequestRegister", root, registerPlayer) function countIDs() local table = dbPoll(dbQuery(db, "SELECT * FROM RoyalUsers"), -1) local count = 1 for i, result in pairs(table) do count = count + 1 end return count end The login variable returns a table, it selects (SELECT) all the columns of the table, and checks if the login defined in the function does not exist in it, if it does not exist, it will add those information, the columns of the table RoyalUsers (INSERT INTO). VALUES (?, ?, ?, ?, ?) - "?" It is the amount of arguments that will be used to insert into the column. countIDs() - Function that returns the number of IDs in the table, and adds one more. getPlayerName(source) - Gets the player's name, and adds the "name" column of the table. user - Adds the user defined in the function, the column "login". pass - Adds the password set in the function, the "pass" column. getPlayerSerial(source) - Gets the player's serial, and adds the "serial" column of the table. Having the part in which the data that the player registers, are saved in the database, this part is ready. Now, just set the ID added to the database login, when the player logs in. function loginPlayer(source, user, pass) if user == "" then outputLoginMsg(source, "Preencha todos os campos!", "error") else if pass == "" then outputLoginMsg(source, "Preencha todos os campos!", "error") else local account = getAccount(user, pass) if account then logIn(source, account, pass) local queryTable = dbPoll(dbQuery(db, "SELECT * FROM RoyalUsers WHERE login='"..getAccountName(getPlayerAccount(source)).."'"), -1) for i, id in pairs(queryTable) do setElementData(source, "ID", id["id"]) end setTimer(setCameraTarget, 3000, 1, source, source) setTimer(triggerClientEvent, 14000, 1, source, "renderRoyalID", source) triggerClientEvent(source, "onRoyalLogin", source) outputLoginMsg(source, "Logado com sucesso! Aguarde...", "success") else outputLoginMsg(source, "Usuário ou senha incorretos!", "error") end end end end addEvent("onPlayerRequestLogin", true) The queryTable gets all the columns of the table, where the login = login of the player. After that, we loop the tables returned by the queryTable, and set the date "ID" to the player, according to the ID returned from the table defined in the loop. I want to make it clear that the tutorial did not go well explained, I just want to share, what I learned yesterday, and if I did something wrong, please let me know.
  3. Bom eu sou novo em .lua e eu estava aprendendo como colocar sistema de id so que o sistema de id que ele dava não salvava os id Exemplo Fulano entrou primeiro no servidor e ficou com id 1 Pelicano Entrou no servidor e ficou com id 2 Amoeba Entrou no servidor e ficou com id 3 C0DE Entrou no servidor e ficou com id 4 Ai Fulano sai e o Pelicano fica com id 1 e o resto modifica os id E eu não queria isso eu queria salva os id dos usuarios tipo Fulano Saiu e entrou um novo membro e o membro fica com id 5 em vez de fica com id 1 Ai quando o Fulano entrar ele continuar com ID 1
×
×
  • Create New...