Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 26/11/18 in all areas

  1. 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.
    1 point
  2. Regeneration (health) This resource lets you regenerate player and vehicle* health. It is not an unique idea, I know... but there weren't good implementations for it at the community resource list. So that's why I share this with YOU. * Vehicle regeneration for the driver only. Version 1.0.0 Not compiled! Smooth health regeneration No UI, just the manager Settings (Admin panel) Settings Regeneration [on/off] (player/vehicle) Regeneration value (player/vehicle) Regeneration delay (player/vehicle) Regeneration [on/off] while the vehicle is burning Download link: https://community.multitheftauto.com/?p=resources&s=details&id=15757 Take a quick look into the source code (v1.0.0) Client Server Meta
    1 point
  3. I made an algorithm for you. It looks working good. (I'm sure there is a better solution. But this is also a viable solution.) function calculateRows(text, font, fontSize, rectangeWidth) local line_text = "" local line_count = 1 for word in text:gmatch("%S+") do local temp_line_text = line_text .. " " .. word local temp_line_width = dxGetTextWidth(temp_line_text, fontSize, font) if temp_line_width >= rectangeWidth then line_text = word line_count = line_count + 1 else line_text = temp_line_text end end return line_count end local font = "default" local size = 1 local rectangeWidth = 200 local text = "akosdk sadpdfksdfw eporksdopf sdkopfks dopfkopewkop fksdopmgfdio opfgsdopfk sdopfks dopkfowerop mkopdfmdopgmop mwropfmsdopfmsdop gmiterogmopsefm, opsdmfop meoprgm sdfopgm" local fontHeight = dxGetFontHeight(size, font) local height = calculateRows(text, font, size, rectangeWidth) * fontHeight addEventHandler("onClientRender", root, function() dxDrawText(text, 500,200,500+rectangeWidth,200+height, tocolor(255,255,255,255), size, font, "left", "top", false, true) dxDrawRectangle(500,200,rectangeWidth,height,tocolor(0,0,0,150)) end)
    1 point
  4. Not a bad one ilyama its a best resource +1
    1 point
  5. Você pode usar um setTimer para destruir o veículo após tantos segundos que ele ficou vazio e também pode cancelar esse timer quando alguém entrar no veículo. No entanto, não existe uma função que detecta quando um veículo é criado. Se o player criar o veículo e não entrar nele, o timer não será criado. server-side vehTimer = {} addEventHandler ("onVehicleExit", getRootElement(), function (thePlayer, seat, jacker, forcedByScript) local counter = 0 for seat, player in pairs(getVehicleOccupants(source)) do counter = counter + 1 end if counter == 0 then -- Se o veículo ficou vazio após esse player sair dele, então: vehTimer[source] = setTimer (destroyElement, 5000, 1, source) -- destroi o veículo após 5 segundos que alguém saiu dele. end end) addEventHandler ("onVehicleEnter", getRootElement(), function (thePlayer, seat, jacked) if isTimer (vehTimer[source]) then killTimer (vehTimer[source]) end end)
    1 point
  6. انظر ياصديقي . . لايوجد شئ صعب مادام انك تتبع نفسك وماتبي تصير احد ثاني ماتبي تصير شخصية اخري! لأن كل شخص يبرع في " مجاله " فحدد مجالك ابدأ بالاساسيات ومهما كانت اللغة البرمجية لاتستهن بالاساسيات خذ وقتك جدا في تعلم الاساسيات حتي تتمكن من الاساس كليًا. بعدها تعلم المجال الذي تريد تعلمه في اللغه ! ولا تستبق الاحداث وتنظر الي النتائج . . . لا تسأل كثيُرا فقد اقرأ وتعلم من ما تقرأه.
    0 points
  7. 0 points
×
×
  • Create New...