Jump to content

Grzanek

Members
  • Posts

    12
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

Grzanek's Achievements

Square

Square (6/54)

0

Reputation

  1. I have this script, it should spawn npc but they don't appear, no errors in DB3 CODE REMOVED BY IIYAMA
  2. Zna ktoś rozwiązanie tego problemu? https://imgur.com/j0NVq5a
  3. this is the script that connects the server to the database Database = {} Database.__index = Database function Database:new(...) local instance = {} setmetatable(instance, Database) if instance:constructor(...) then return instance end return false end function Database:constructor(...) self.database = arg[1] self.host = arg[2] self.username = arg[3] self.password = arg[4] self.func = {} self.func.queryAsyncResponse = function(...) self:queryAsyncResponse(...) end self.func.queryAsyncMultiselectResponse = function(...) self:queryAsyncMultiselectResponse(...) end if self:connect() then return true else return false end end function Database:connect() setRuleValue("dbname", self.database) setRuleValue("dbhost", self.host) setRuleValue("dbuser", self.username) setRuleValue("dbpass", self.password) self.connection = dbConnect("mysql", string.format("dbname=%s;host=%s;unix_socket=/var/run/mysqld/mysqld.sock", self.database, self.host), self.username, self.password, "share=1;multi_statements=1") if self.connection then outputDebugString(string.format("[MYSQL] Connected to the database (%s)", self.database)) self:updateNames() return true else outputDebugString(string.format("[MYSQL] Cannot connect to the database (%s)", self.database), 3, 255, 0, 0) return false end end function Database:query(...) local qh = dbQuery(self.connection, dbPrepareString(self.connection, ...)) if not qh then return false end local result, num_affected_rows, last_insert_id = dbPoll(qh, -1, true) if not result then dbFree(qh) end return result, num_affected_rows, last_insert_id end function Database:queryAsync(data, ...) dbQuery(self.func.queryAsyncResponse, {{data}}, self.connection, dbPrepareString(self.connection, ...)) end function Database:queryAsyncWithoutResponse(...) dbQuery(function(qh) dbPoll(qh, 0, true) end, {}, self.connection, dbPrepareString(self.connection, ...)) end function Database:queryAsyncResponse(qh, data) local result, num_affected_rows, last_insert_id = dbPoll(qh, 0, true) triggerEvent(data[1].callback, resourceRoot, data[1], result, num_affected_rows, last_insert_id) end function Database:queryAsyncMultiselect(data, ...) dbQuery(self.func.queryAsyncMultiselectResponse, {{data}}, self.connection, dbPrepareString(self.connection, ...)) end function Database:queryAsyncMultiselectResponse(qh, data) local result, num_affected_rows, last_insert_id = dbPoll(qh, 0, true) triggerEvent(data[1].callback, resourceRoot, data[1], result, num_affected_rows, last_insert_id) end function Database:queryMultiselect(...) local qh = dbQuery(self.connection, dbPrepareString(self.connection, ...)) if not qh then return false end local result, num_affected_rows, last_insert_id = dbPoll(qh, -1, true) if not result then dbFree(qh) end return result, num_affected_rows, last_insert_id end function Database:updateNames() self:query("SET NAMES utf8") end local connection function createMysql() connection = Database:new("database", "host", "username", "password") end function query(...) local query, rows, lastID = connection:query(...) return query, rows, lastID end function queryMultiselect(...) local time = getTickCount() local query, rows, lastID = connection:queryMultiselect(...) addDevData(getResourceName(sourceResource), getTickCount() - time, #query) return query, rows, lastID end function queryAsync(callback, ...) connection:queryAsync(callback, ...) end function queryAsyncMultiselect(callback, ...) connection:queryAsyncMultiselect(callback, ...) end function queryAsyncWithoutResponse(...) connection:queryAsyncWithoutResponse(...) end -- Export to dev admin data function addDevData(resourceName, time, results) exports.TR_admin:addMysqlInfo(string.format("Resource: %s Time: %d tick Results: %d", resourceName, time, results)) end createMysql()
  4. Panel logowania przy próbie rejestracji wyświetla komunikat o już istniejącym użytkowniku a przy próbie logowania wyświetla komunikat o błędnym haśle, baza danych podłączona nie tworzą się konta w bazie local settings = { spawnPositions = { [1] = "1722.05,-1710.48,13.5,0,0", [2] = "1718.54,-1712.46,13.5,0,0", [3] = "1725.54,-1712.46,13.5,0,0", }, coroutines = {} } function getUpdates(limit) local updates = exports.NL_mysql:querry("SELECT text FROM `nl_updates` ORDER BY `ID` DESC LIMIT ?", limit + 5) if updates and updates[1] then triggerClientEvent(client, "updateLoginUpdates", resourceRoot, updates) else triggerClientEvent(client, "updateLoginUpdates", resourceRoot, {{text = "Nie udało się pobrać listy zmian"}}) end end addEvent("getUpdates", true) addEventHandler("getUpdates", resourceRoot, getUpdates) function getBanData() local banData = exports.NL_mysql:querry("SELECT ID, nl_accounts.username as username, nl_penalties.serial, reason, time, timeEnd, admin FROM `nl_penalties` LEFT JOIN nl_accounts ON nl_accounts.UID = nl_penalties.plrUID WHERE nl_penalties.serial = ? AND timeEnd > NOW() AND type = 'ban' AND takenBy IS NULL LIMIT 1", getPlayerSerial(client)) if banData and banData[1] then triggerClientEvent(client, "setPlayerBanData", resourceRoot, false, banData[1]) else triggerClientEvent(client, "setPlayerBanData", resourceRoot, false) end end addEvent("getBanData", true) addEventHandler("getBanData", resourceRoot, getBanData) function checkBanAccount(plrUID) if not username then return false end local banData = exports.NL_mysql:querry("SELECT ID FROM `nl_penalties` WHERE plrUID = ? AND timeEnd > NOW() AND type = 'ban' LIMIT 1", plrUID) if banData and banData[1] then return true end return false end function registerAccount(login, password, email, reference) local checkUsername = exports.NL_mysql:querry("SELECT UID FROM `nl_accounts` WHERE `login` = ? LIMIT 1", login) if checkUsername and checkUsername[1] then triggerClientEvent(client, "loginResponseServer", resourceRoot, "Użytkownik o takim loginie już istnieje.", "error") return end local serial = getPlayerSerial(client) local checkSerial = exports.NL_mysql:querry("SELECT UID FROM `nl_accounts` WHERE `serial` = ? LIMIT 2", serial) if checkSerial and #checkSerial == 2 then triggerClientEvent(client, "loginResponseServer", resourceRoot, "Wykorzystałeś już limit zakładania kont na jednym serialu (2).", "error") return end local checkEmail = exports.NL_mysql:querry("SELECT UID FROM `nl_accounts` WHERE `email` = ? LIMIT 1", email) if checkEmail and checkEmail[1] then triggerClientEvent(client, "loginResponseServer", resourceRoot, "Ten email jest już przypisany do jednego konta.", "error") return end local referenceUID = false if reference then referenceUID = teaDecodeBinary(reference, "XayDpN36bGKGvfbD") if tonumber(referenceUID) == nil or string.len(referenceUID) < 1 then triggerClientEvent(client, "loginResponseServer", resourceRoot, "Kod referencyjny jest nieprawidłowy.", "error", "reference") return end end exports.NL_mysql:querry("INSERT INTO `nl_accounts` (`login`, `password`, `email`, `serial`, `createIP`, `position`, `referencedPlayer`, `money`, `phoneBlocked`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, '[[]]')", login, passwordHash(password, "bcrypt", {"salt"}), email, getPlayerSerial(client), getPlayerIP(client), settings.spawnPositions[math.random(1, #settings.spawnPositions)], referenceUID and referenceUID or false, referenceUID and 500 or 0) triggerClientEvent(client, "loginResponseServer", resourceRoot, false, "success", "accountCreate") end addEvent("registerAccount", true) addEventHandler("registerAccount", resourceRoot, registerAccount) function loginAccount(login, password) local performLogin = exports.NL_mysql:querry("SELECT UID, password, username, tutorial FROM `nl_accounts` WHERE `login` = ? LIMIT 1", login) if performLogin and performLogin[1] then if passwordVerify(password, performLogin[1]["password"]) then if isPlayerLogged(performLogin[1]["UID"]) then triggerClientEvent(client, "loginResponseServer", resourceRoot, "Te konto jest już zalogowane.", "error") return end if checkBanAccount(performLogin[1]["UID"]) then triggerClientEvent(client, "loginResponseServer", resourceRoot, "Te konto jest zbanowane i nie możesz się na nie zalogować.", "error") return end if performLogin[1].username then setPlayerName(client, performLogin[1].username) end setElementData(client, "tempUID", performLogin[1].UID) exports.NL_mysql:querry("UPDATE nl_accounts SET isOtrine = 1, lastOtrine = NOW() WHERE `UID` = ? LIMIT 1", performLogin[1].UID) triggerClientEvent(client, "loginPlayer", resourceRoot, performLogin[1].username, performLogin[1].tutorial) local serial = getPlayerSerial(client) local ip = getPlayerIP(client) exports.NL_mysql:querry("INSERT INTO `nl_logs` (player, text, serial, ip, type) VALUES (?, ?, ?, ?, ?)", performLogin[1].UID, "Pomyślnie zalogowano na konto.", serial, ip, "login") exports.NL_mysql:querry("UPDATE `nl_accounts` SET `lastOtrine` = NOW() WHERE UID = ? LIMIT 1;", performLogin[1].UID) else triggerClientEvent(client, "loginResponseServer", resourceRoot, "Wpisane hasło jest niepoprawne.", "error") exports.NL_mysql:querry("INSERT INTO `nl_logs` (player, text, serial, ip, type) VALUES (?, ?, ?, ?, ?)", performLogin[1].UID, "Podano błędne hasło.", serial, ip, "login") end else triggerClientEvent(client, "loginResponseServer", resourceRoot, "Taki użytkownik nie istnieje.", "error") end end addEvent("loginAccount", true) addEventHandler("loginAccount", resourceRoot, loginAccount) function checkPlayerPremium(UID) local rank = exports.NL_mysql:querry("SELECT CASE WHEN `diamond` > NOW() THEN 'diamond' WHEN `gold` > NOW() THEN 'gold' ELSE NULL END as 'rank' FROM nl_accounts WHERE UID = ? LIMIT 1", UID) if rank and rank[1] then return rank[1].rank end return false end function onLoadCharacterData(data, plrData) local client = data.plr removeElementData(client, "tempUID") setElementData(client, "characterUID", data.plrUID) local pos = split(data.respawnPos or plrData[1].position, ",") spawnPlayer(client, pos[1], pos[2], pos[3], data.respawnRot or 0, 0, 0) setElementInterior(client, pos[4]) setElementDimension(client, pos[5]) setTimer(setElementRotation, 100, 1, client, 0, 0, data.respawnRot or 0) if tonumber(plrData[1].skin) ~= nil then setElementModel(client, tonumber(plrData[1].skin)) setElementData(client, "customModel", nil) else setElementModel(client, 0) setElementData(client, "customModel", tostring(plrData[1].skin)) end setElementHealth(client, tonumber(plrData[1].health)) setPlayerName(client, plrData[1].username) local data = { skin = tostring(plrData[1].skin), premium = checkPlayerPremium(data.plrUID), money = plrData[1].money, licence = plrData[1].licence and fromJSON(plrData[1].licence) or {}, bankcode = plrData[1].bankcode or false, enterTime = getTickCount() } setElementData(client, "characterData", data) setElementData(client, "characterPoints", tonumber(plrData[1].jobPoints)) local features = {} for i, v in pairs(split(plrData[1].features, ",")) do features[i] = tonumber(v) end setElementData(client, "characterFeatures", features) setPedStat(client, 22, (features[2] or 0) * 10) setPedStat(client, 225, (features[2] or 0) * 10) if plrData[1].usernameRP then setElementData(client, "usernameRP", plrData[1].usernameRP) end if plrData[1].ticketPrice then setElementData(client, "ticketPrice", tonumber(plrData[1].ticketPrice)) end if plrData[1].bwTime then triggerClientEvent(client, "openBW", resourceRoot, plrData[1].bwTime) else triggerEvent("updatePlayerMask", resourceRoot, client) end triggerEvent("setPlayerID", resourceRoot, client) triggerEvent("updatePlayerWeather", resourceRoot, client) triggerEvent("updatePlayerPhone", resourceRoot, client) triggerEvent("loadPlayerAchievements", resourceRoot, client) triggerClientEvent(client, "loadSpawnSelectCharacter", resourceRoot, tonumber(plrData[1].tutorial) == 1 and true or nil) end addEvent("onLoadCharacterData", true) addEventHandler("onLoadCharacterData", root, onLoadCharacterData) function spawnPlayerCharacter(respawnPos, respawnRot) if not client then return end local plrUID = getElementData(client, "tempUID") if not plrUID then return end exports.NL_mysql:querryAsync({ callback = "onLoadCharacterData", plr = client, respawnPos = respawnPos, respawnRot = respawnRot, plrUID = plrUID, }, "SELECT username, usernameRP, skin, health, position, money, bankcode, licence, bwTime, ticketPrice, features, jobPoints FROM `nl_accounts` WHERE `UID` = ? LIMIT 1", plrUID) end addEvent("spawnPlayerCharacter", true) addEventHandler("spawnPlayerCharacter", root, spawnPlayerCharacter) function loadPlayerData(plr, plrUID) if not plr or not plrUID then return end local plrData = exports.NL_mysql:querry("SELECT skin, money, licence FROM `nl_accounts` WHERE `UID` = ? LIMIT 1", plrUID) local data = { skin = tonumber(plrData[1].skin), premium = checkPlayerPremium(plrUID), money = plrData[1].money, licence = plrData[1].licence and fromJSON(plrData[1].licence) or {}, enterTime = getTickCount() } setElementData(plr, "characterData", data) end addEvent("loadPlayerData", true) addEventHandler("loadPlayerData", resourceRoot, loadPlayerData) function updatePlayerOrganization(plr, plrUID) local orgPlr = exports.NL_mysql:querry("SELECT nl_organizations.ID as ID, name, nl_organizations.type as type, moneyBonus, gangType FROM nl_organizations INNER JOIN nl_organizationsPlayers ON nl_organizations.ID = nl_organizationsPlayers.orgID WHERE playerUID = ? AND nl_organizations.removed IS NULL LIMIT 1", plrUID) if orgPlr and orgPlr[1] then setElementData(plr, "characterOrg", orgPlr[1].name) setElementData(plr, "characterOrgID", orgPlr[1].ID) setElementData(plr, "characterOrgType", orgPlr[1].type) setElementData(plr, "characterOrgMoneyPercent", orgPlr[1].moneyBonus) setElementData(plr, "characterGangType", orgPlr[1].gangType) else removeElementData(plr, "characterOrg") removeElementData(plr, "characterOrgID") removeElementData(plr, "characterOrgType") removeElementData(plr, "characterOrgMoneyPercent") removeElementData(plr, "characterGangType") end end -- Utils function isPlayerLogged(uid) local isOtrine = exports.NL_mysql:querry("SELECT UID FROM nl_accounts WHERE `UID` = ? AND isOtrine IS NOT NULL LIMIT 1", uid) if isOtrine and isOtrine[1] then return true end return false end function checkUsernameFree(username) local isFree = exports.NL_mysql:querry("SELECT UID FROM `nl_accounts` WHERE `username` = ? LIMIT 1", username) if isFree and isFree[1] then triggerClientEvent(client, "checkUsernameValid", resourceRoot, username) else triggerClientEvent(client, "checkUsernameValid", resourceRoot, username, true) end end addEvent("checkUsernameFree", true) addEventHandler("checkUsernameFree", root, checkUsernameFree) function setPlayerUsername(username) local uid = getElementData(client, "tempUID") if not uid then return end exports.NL_mysql:querry("UPDATE `nl_accounts` SET username = ? WHERE UID = ? LIMIT 1", username, uid) triggerClientEvent(client, "loginPlayer", resourceRoot, username, true) end addEvent("setPlayerUsername", true) addEventHandler("setPlayerUsername", root, setPlayerUsername) function teaDecodeBinary(data, key) return base64Decode(teaDecode(data, key)) end function openPlayerSpawnSelect() local uid = getElementData(client, "tempUID") if not uid then return end loadPlayerData(client, uid) updatePlayerOrganization(client, uid) local orgID = getElementData(client, "characterOrgID") local panelData = {} local playerData = exports.NL_mysql:querry("SELECT skin, position, bwTime, prisonData FROM `nl_accounts` WHERE UID = ? LIMIT 1", uid) panelData.lastPos = playerData[1].position panelData.bwTime = playerData[1].bwTime if playerData[1].prisonData then local prisonData = fromJSON(playerData[1].prisonData) if prisonData then prisonData.position = exports.NL_jail:getFreePrizonPosition(prisonData.prisonIndex) panelData.prisonData = prisonData setElementData(client, "prisonIndex", tonumber(prisonData.prisonIndex)) end end if orgID then local playerHouses = exports.NL_mysql:querry("SELECT pos, ownedOrg FROM `nl_houses` WHERE (owner = ? OR ownedOrg = ?) AND date > NOW()", uid, orgID) panelData.houses = playerHouses else local playerHouses = exports.NL_mysql:querry("SELECT pos, ownedOrg FROM `nl_houses` WHERE owner = ? AND date > NOW()", uid) panelData.houses = playerHouses end panelData.rentHouses = exports.NL_mysql:querry("SELECT nl_houses.pos, nl_houses.ownedOrg FROM `nl_houses` LEFT JOIN nl_housesRent ON nl_houses.ID = nl_housesRent.houseID WHERE nl_housesRent.plrUID = ? AND nl_houses.date > NOW()", uid) local fractionData = exports.NL_mysql:querry("SELECT fractionID FROM `nl_fractionsPlayers` WHERE playerUID = ? LIMIT 1", uid) if fractionData and fractionData[1] then panelData.fractionID = fractionData[1].fractionID end triggerClientEvent(client, "createSpawnSelect", resourceRoot, playerData[1].skin, panelData) end addEvent("openPlayerSpawnSelect", true) addEventHandler("openPlayerSpawnSelect", root, openPlayerSpawnSelect)
  5. Hi, my login panel does not save players to the database and when I want to register I get a message that such a player already exists function registerAccount(login, password, email, reference) local checkUsername = exports.nl_mysql:query("SELECT UID FROM `nl_accounts` WHERE `login` = ? LIMIT 1", login) if checkUsername and checkUsername[1] then triggerClientEvent(client, "loginResponseServer", resourceRoot, "A user with this login already exists.", "error") return end
  6. The script has errors in these lines local checkUsername = exports.nl_mysql:querry("SELECT UID FROM `nl_accounts` WHERE `login` = ? LIMIT 1", login) local checkSerial = exports.nl_mysql:querry("SELECT UID FROM `nl_accounts` WHERE `serial` = ? LIMIT 2", serial) local checkEmail = exports.nl_mysql:querry("SELECT UID FROM `nl_accounts` WHERE `email` = ? LIMIT 1", email) https://imgur.com/SHna2gp
  7. https://imgur.com/a/GOGNWsq The script that references this script has errors in these lines local checkUsername = exports.nl_mysql:querry("SELECT UID FROM `tr_accounts` WHERE `login` = ? LIMIT 1", login) local checkEmail = exports.nl_mysql:querry("SELECT UID FROM `tr_accounts` WHERE `email` = ? LIMIT 1", email) local checkSerial = exports.nl_mysql:querry("SELECT UID FROM `tr_accounts` WHERE `serial` = ? LIMIT 2", serial)
  8. Problem occur in these lines function query(...) local query, rows, lastID = connection:query(...) return query, rows, lastID end
  9. Hi, I have a problem with a script that connects a server to a database. Below I attach the script code and error content ERROR: nl_mysql\s.lua:98: attempt to index upvalue 'connection' (a boolean value) ERROR: nl_login\s.lua:24: call: failed to call 'TR_mysql:querry' [string "?"] Database = {} Database.__index = Database function Database:new(...) local instance = {} setmetatable(instance, Database) if instance:constructor(...) then return instance end return false end function Database:constructor(...) self.database = arg[1] self.host = arg[2] self.username = arg[3] self.password = arg[4] self.func = {} self.func.queryAsyncResponse = function(...) self:queryAsyncResponse(...) end self.func.queryAsyncMultiselectResponse = function(...) self:queryAsyncMultiselectResponse(...) end if self:connect() then return true else return false end end function Database:connect() setRuleValue("xddd", self.database) setRuleValue("localhost", self.host) setRuleValue("xddd", self.username) setRuleValue("xdddd", self.password) self.connection = dbConnect("mysql", string.format("dbname=%s;host=%s;unix_socket=/var/run/mysqld/mysqld.sock", self.database, self.host), self.username, self.password, "share=1;multi_statements=1") if self.connection then outputDebugString(string.format("[MYSQL] Connected to the database (%s)", self.database)) self:updateNames() return true else outputDebugString(string.format("[MYSQL] Cannot connect to the database (%s)", self.database), 3, 255, 0, 0) return false end end function Database:query(...) local qh = dbQuery(self.connection, dbPrepareString(self.connection, ...)) if not qh then return false end local result, num_affected_rows, last_insert_id = dbPoll(qh, -1, true) if not result then dbFree(qh) end return result, num_affected_rows, last_insert_id end function Database:queryAsync(data, ...) dbQuery(self.func.queryAsyncResponse, {{data}}, self.connection, dbPrepareString(self.connection, ...)) end function Database:queryAsyncWithoutResponse(...) dbQuery(function(qh) dbPoll(qh, 0, true) end, {}, self.connection, dbPrepareString(self.connection, ...)) end function Database:queryAsyncResponse(qh, data) local result, num_affected_rows, last_insert_id = dbPoll(qh, 0, true) triggerEvent(data[1].callback, resourceRoot, data[1], result, num_affected_rows, last_insert_id) end function Database:queryAsyncMultiselect(data, ...) dbQuery(self.func.queryAsyncMultiselectResponse, {{data}}, self.connection, dbPrepareString(self.connection, ...)) end function Database:queryAsyncMultiselectResponse(qh, data) local result, num_affected_rows, last_insert_id = dbPoll(qh, 0, true) triggerEvent(data[1].callback, resourceRoot, data[1], result, num_affected_rows, last_insert_id) end function Database:queryMultiselect(...) local qh = dbQuery(self.connection, dbPrepareString(self.connection, ...)) if not qh then return false end local result, num_affected_rows, last_insert_id = dbPoll(qh, -1, true) if not result then dbFree(qh) end return result, num_affected_rows, last_insert_id end function Database:updateNames() self:query("SET NAMES utf8") end local connection function createMysql() connection = Database:new("database", "host", "username", "password") end function query(...) local query, rows, lastID = connection:query(...) return query, rows, lastID end function queryMultiselect(...) local time = getTickCount() local query, rows, lastID = connection:queryMultiselect(...) addDevData(getResourceName(sourceResource), getTickCount() - time, #query) return query, rows, lastID end function queryAsync(callback, ...) connection:queryAsync(callback, ...) end function queryAsyncMultiselect(callback, ...) connection:queryAsyncMultiselect(callback, ...) end function queryAsyncWithoutResponse(...) connection:queryAsyncWithoutResponse(...) end -- Export to dev admin data function addDevData(resourceName, time, results) exports.TR_admin:addMysqlInfo(string.format("Resource: %s Time: %d tick Results: %d", resourceName, time, results)) end createMysql()
×
×
  • Create New...