Jump to content

Bilal135

Members
  • Posts

    843
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by Bilal135

  1. What about this? filePaths = { [560] = { txd = "files/470/sultan.txd", dff = "files/470/sultan.dff" }, [411] = { txd = "files/411/infernus.txd", dff = "files/411/infernus.dff" } } function createFilePath(id, txdpath, dffpath) filePaths[id] = { txd = txdpath, dff = dffpath } end function updateFilePath(id, txdpath, dffpath) for k, v in ipairs(filePaths) do filePath[id].txd = txdpath filePath[id].dff = dffpath end end
  2. I was working on it. Before your previous reply, this is the best I could come up with. It didn't work, nor did I expect it to. But I'd still like to know where am I going wrong with this. I'll look into the table format that you provided an example of. local xml = exports.xmlData addEvent("downloadNotDownloadedVehicles", true) addEventHandler ( "downloadNotDownloadedVehicles" , resourceRoot, function (modelDataList) for model, v in pairs(modelDataList) do print(model) local col = v.col if col then print(col) local col_loaded = engineLoadCOL (col) if col_loaded then engineReplaceCOL (col_loaded, model ) outputChatBox("replacing col") local colfile = fileCreate(model..".col") fileWrite(colfile, col_loaded) end end local txd = v.txd if txd then print(txd) local txd_loaded = engineLoadTXD(txd) if txd_loaded then engineImportTXD(txd_loaded, model) outputChatBox("replacing txd") local txdfile = fileCreate(model..".txd") fileWrite(txdfile, txd_loaded) end end local dff = v.dff if dff then print(dff) local dff_loaded = engineLoadDFF(dff) if dff_loaded then engineReplaceModel(dff_loaded, model) outputChatBox("replacing dff") local dfffile = fileCreate(model..".dff") fileWrite(dfffile, dff_loaded) end end xml.xmlSaveData("DownloadedFiles", modelDataList, true) end end ) function difference(a,b) -- This should put everything that is on table A and it isn't on table B into a new indexed table local ret = {} for k,v in pairs(a) do local insert = true for k2,v2 in pairs(b) do if v == v2 then insert = false break; end end if insert then table.insert(ret, v) end end return ret end addEvent("downloadVehicle", true) addEventHandler("downloadVehicle", resourceRoot, function (notDownloadedFilesTableData) local downloadedFilesXML = xml.xmlLoadData("DownloadedFiles", true) local downloadedFilesTable = difference(downloadedFilesXML, modelDataList) local notDownloadedFilesTable = difference(downloadedFilesTable, modelDataList) local notDownloadedFilesXML = xml.xmlSaveData("notDownloadedFiles", true) for model, fileType in pairs(notDownloadedFilesTableData) do local col = v.col if col then print(col) local col_loaded = engineLoadCOL(model..".col") if col_loaded then engineReplaceCOL (col_loaded, model) outputChatBox("[downloadedFiles] replacing col") end end local txd = v.txd if txd then print(txd) local txd_loaded = engineLoadTXD(model..".txd") if txd_loaded then engineImportTXD(txd_loaded, model) outputChatBox("[downloadedFiles] replacing txd") end end local dff = v.dff if dff then print(dff) local dff_loaded = engineLoadDFF(model..".dff") if dff_loaded then engineReplaceModel(dff_loaded, model) outputChatBox("[downloadedFiles] replacing dff") end end triggerServerEvent("notDownloadedFilesData", source, notDownloadedFilesTable) end end ) local links = { { model = 560, txd = "https://drive.google.com/uc?export=download&id=1XIlsWiphME11AXW94cQGtOGJl4hMEX9V", dff = "https://drive.google.com/uc?export=download&id=1exS-vr_kYp-tnD4xiCs8qW53zEAqT_S3" } } -- OUTPUT local modelDataList = {} -- local fileTypeLoadOrder = { "col", "txd", "dff" } do -- This is a temporary function. Only used for the initial state. local fileRequest = function (data, err, linkIndex, fileType) if not err.success then print(err.statusCode) end outputChatBox("Download started", root) local link = links[linkIndex] local model = link.model -- make a new container if not exist local modelData = modelDataList[model] if not modelData then modelData = { fileCountRemaining = link.fileCount } modelDataList[model] = modelData end -- save the data modelData.model = model modelData[fileType] = data modelData.fileCountRemaining = modelData.fileCountRemaining - 1 -- clean up if modelData.fileCountRemaining == 0 then modelData.fileCountRemaining = nil modelData.ready = true end end -- Loop through all the links for i=1, #links do local link = links[i] -- Keep track of the amount of files that need to be downloaded local fileCount = 0 -- Loop through all the file types in order. for j=1, #fileTypeLoadOrder do local fileType = fileTypeLoadOrder[j] local url = link[fileType] if url then -- If file type has an URL, then try to download it. fetchRemote(url, {}, fileRequest, {i, fileType}) fileCount = fileCount + 1 -- + file end end link.fileCount = fileCount end end function difference(a,b) -- This should put everything that is on table A and it isn't on table B into a new indexed table local ret = {} for k,v in pairs(a) do local insert = true for k2,v2 in pairs(b) do if v == v2 then insert = false break; end end if insert then table.insert(ret, v) end end return ret end addEvent("notDownloadedFilesData", true) addEventHandler("notDownloadedFilesData", resourceRoot, function(notDownloadedFilesTable) local notDownloadedFilesTableData = difference(notDownloadedFilesTable, modelDataList) triggerLatentClientEvent(source, "downloadVehicle", 10^7, true, resourceRoot, notDownloadedFilesTableData) end) addEventHandler('onPlayerJoin', root, function() triggerLatentClientEvent(source, 'downloadNotDownloadedVehicles', 10^7, true, resourceRoot, modelDataList) end)
  3. Can you elaborate the process in a step by step a bit more please so its easier to understand?
  4. I did. Turns out 'k' returns the value of model. While modelDataList is replaced by v. It works. I can see the new car model in game. That being said, next question is, is the file downloaded every time the player joins even if he has downloaded it before on his previous visits to the server? Because I wouldn't want player to wait 30 minutes before all files are downloaded every time he joins the server. EDIT: I think I've found the answer. It only downloads once which is very good. 2. Is it possible to show how much % of the file has been downloaded through onClientRender and dxDraw functions?
  5. Errors are gone but none of the test outputs appear upon reconnecting. addEvent("downloadVehicle", true) addEventHandler ( "downloadVehicle" , resourceRoot, function (modelDataList) for k, v in pairs(modelDataList) do local col = modelDataList.col if col then local col_loaded = engineLoadCOL (col) if col_loaded then engineReplaceCOL (col_loaded, model ) outputChatBox("replacing col") end end local txd = modelDataList.txd if txd then local txd_loaded = engineLoadTXD(txd) if txd_loaded then engineImportTXD(txd_loaded, model) outputChatBox("replacing txd") end end local dff = modelDataList.dff if dff then local dff_loaded = engineLoadDFF(dff) if dff_loaded then engineReplaceModel(dff_loaded, model) outputChatBox("replacing dff") end end end end )
  6. Something like this then? addEvent("downloadVehicle", true) addEventHandler ( "downloadVehicle" , resourceRoot, function (modelDataList) for k, v in pairs(modelDataList) do local model = modelDataList.model local data = modelDataList[fileType] if data == "txd" then outputChatBox("loading txd") engineImportTXD(engineLoadTXD(data), model) end if data == "dff" then outputChatBox("loading dff") engineReplaceModel(engineLoadDFF(data), model) end end end )
  7. I apologize I got a little confused between the two different implementations. Continuing @IIYAMA's code with @vicisdev's server side implementation, this is the final code. It still does not work tho. No errors in debug. Should I try restarting the server? EDIT: Actually there's an error. Attempt to concatenate global 'model', a nil value. Working on it. local links = { { model = 560, txd = "https://drive.google.com/uc?export=download&id=1XIlsWiphME11AXW94cQGtOGJl4hMEX9V", dff = "https://drive.google.com/uc?export=download&id=1exS-vr_kYp-tnD4xiCs8qW53zEAqT_S3" } } -- OUTPUT local modelDataList = {} -- local fileTypeLoadOrder = { "col", "txd", "dff" } do -- This is a temporary function. Only used for the initial state. local fileRequest = function (data, err, linkIndex, fileType) if not err.success then print(err.statusCode) end outputChatBox("Download started", root) local link = links[linkIndex] local model = link.model -- make a new container if not exist local modelData = modelDataList[model] if not modelData then modelData = { fileCountRemaining = link.fileCount } modelDataList[model] = modelData end -- save the data modelData.model = model modelData[fileType] = data modelData.fileCountRemaining = modelData.fileCountRemaining - 1 -- clean up if modelData.fileCountRemaining == 0 then modelData.fileCountRemaining = nil modelData.ready = true end end -- Loop through all the links for i=1, #links do local link = links[i] -- Keep track of the amount of files that need to be downloaded local fileCount = 0 -- Loop through all the file types in order. for j=1, #fileTypeLoadOrder do local fileType = fileTypeLoadOrder[j] local url = link[fileType] if url then -- If file type has an URL, then try to download it. fetchRemote(url, {}, fileRequest, {i, fileType}) fileCount = fileCount + 1 -- + file end end link.fileCount = fileCount end end addEventHandler('onPlayerJoin', root, function() triggerLatentClientEvent(source, 'downloadVehicle', 10^7, true, resourceRoot, model, data) end) addEvent("downloadVehicle", true) addEventHandler ( "downloadVehicle" , resourceRoot, function (model, data) if data == "txd" then engineImportTXD(engineLoadTXD(txd), model) elseif data == "dff" then engineReplaceModel(engineLoadDFF(dff), model) end end )
  8. This is the server side, -- INPUT local links = { { model = 560, txd = "http://drive.google.com/uc?export=download&id=1XIlsWiphME11AXW94cQGtOGJl4hMEX9V", dff = "http://drive.google.com/uc?export=download&id=1exS-vr_kYp-tnD4xiCs8qW53zEAqT_S3" } } -- OUTPUT local modelDataList = {} local fileModelList = { ["sultan.txd"] = { model = "560", fileType = "txd" }, ["sultan.dff"] = { model = "560", fileType = "dff" } } -- local fileTypeLoadOrder = { "col", "txd", "dff" } do -- This is a temporary function. Only used for the initial state. local fileRequest = function (data, err, linkIndex, fileType) if not err.success then print(err.statusCode) end outputChatBox("Download started", root) local link = links[linkIndex] local model = link.model -- make a new container if not exist local modelData = modelDataList[model] if not modelData then modelData = { fileCountRemaining = link.fileCount } modelDataList[model] = modelData end -- save the data modelData.model = model modelData[fileType] = data modelData.fileCountRemaining = modelData.fileCountRemaining - 1 -- clean up if modelData.fileCountRemaining == 0 then modelData.fileCountRemaining = nil modelData.ready = true end end -- Loop through all the links for i=1, #links do local link = links[i] -- Keep track of the amount of files that need to be downloaded local fileCount = 0 -- Loop through all the file types in order. for j=1, #fileTypeLoadOrder do local fileType = fileTypeLoadOrder[j] local url = link[fileType] if url then -- If file type has an URL, then try to download it. fetchRemote(url, {}, fileRequest, {i, fileType}) fileCount = fileCount + 1 -- + file end end link.fileCount = fileCount end end addEventHandler("onPlayerJoin", root, function() --triggerLatentClientEvent(source, "downloadFiles", 10^7, true, resourceRoot) --Even 10 MBytes didn't work setTimer(function() triggerClientEvent(source, "downloadFiles", resourceRoot) outputChatBox("Download triggered", root) end, 10000, 1) end)
  9. Messed around with triggerLatentClientEvent and triggerClientEvent but both didn't work. Added the files in the resource and changed the meta.xml just like you said, but the models still do not load. Tried debugging this way, addEventHandler("onClientFileDownloadComplete", resourceRoot, function(fileName, success) if not success then return outputChatBox("Download failed") end -- Later you should do something to handle failed downloads local model = fileModelList[fileName].model local type = fileModelList[fileName].fileType if type == "txd" then outputChatBox("Loading txd") engineImportTXD(engineLoadTXD(fileName), model) end if type == "dff" then outputChatBox("Loading dff") engineReplaceModel(engineLoadDFF(fileName), model) end fileModelList[fileName] = nil end) addEvent("downloadFiles", true) addEventHandler("downloadFiles", resourceRoot, downloadFiles) There's no output so it's not being triggered. Where could the problem lie?
  10. If you could show me your new implementation, that would be of great help. Would this be the right way to receive and load the data in client side? addEvent("downloadVehicle", true) addEventHandler ( "downloadVehicle" , resourceRoot, function (modelDataList) for k, v in ipairs(modelDataList) do local model = k outputChatBox(""..model.."") local txd = v.txd local dff = v.dff engineImportTXD(engineLoadTXD(txd), model) engineReplaceModel(engineLoadDFF(dff), model) setTimer(function() outputChatBox("Download complete") end, 10000, 1) end end) Also, it seems that the script would download the files every time the player joins. Is it possible to make the player download the files only once?
  11. I replaced the link with a direct link. Errors in debug script disappeared, but the texture still did not load. Also, how do I approach fetchRemote with tables? local links = { [560] = {txd = "https://cdn-20.anonfile.com/n9r7yfG3nd/e52c4b4d-1576530500/sultan.txd", dff = "https://cdn-07.anonfile.com/99u8y2G1n9/35d1852b-1576531060/sultan.dff"} } local vehicle_data fetchRemote('https://cdn-20.anonfile.com/n9r7yfG3nd/e52c4b4d-1576530500/sultan.txd', function(err, data) if (err) then print(err) end outputChatBox("Download started", root) vehicle_data = data end) addEventHandler('onPlayerJoin', root, function() triggerLatentClientEvent(source, 'downloadVehicle', resourceRoot, vehicle_data) end) addEventHandler ( "downloadVehicle" , resourceRoot, function (vehicle_data) engineImportTXD(engineLoadTXD(vehicle_data), 560) outputChatBox("Download complete") end)
  12. Tried this time with another link. Download did start, and it outputted some weird stuff in debug, but the texture was not loaded in game. Is there any problem with the trigger? -- server local vehicle_data fetchRemote('http://gofile.io/?c=f6vZuA', function(err, data) if (err) then print(err) end outputChatBox("Download started", root) vehicle_data = data end) addEventHandler('onPlayerJoin', root, function() triggerLatentClientEvent(source, 'downloadVehicle', resourceRoot, vehicle_data) end) -- client addEventHandler ( "downloadVehicle" , resourceRoot, function (vehicle_data) engineImportTXD(engineLoadTXD(vehicle_data), 560) outputChatBox("Download complete") -- this check failed end) Tried creating a file. Did not work. -- client addEventHandler ( "downloadVehicle" , resourceRoot, function (vehicle_data) local file = fileCreate("sultan.txd") fileWrite(file, vehicle_data) engineImportTXD(engineLoadTXD(file), 560) outputChatBox("Download complete") end)
  13. I'm trying to learn fetchRemote. Never used it before. For test purposes, I uploaded a file to 000webhost, and ran the code below, server: local vehicle_data fetchRemote('https://nightwalkersnw.000webhostapp.com/public_html/sultan.dff', function(err, data) if (err) then print(err) return end outputChatBox("Download started", root) vehicle_data = data end) addEventHandler('onPlayerJoin', root, function() triggerLatentClientEvent(source, 'downloadVehicle', resourceRoot, vehicle_data) end) client: addEventHandler ( "downloadVehicle" , resourceRoot , function (vehicle_data) engineReplaceModel ( engineLoadDFF ( vehicle_data ) , 560 ) outputChatBox("Download complete") end) Debugscript just outputs 'INFO: ERROR'. What could be the cause? Also, what if I wanted to download multiple vehicle files (dff and txd) without actually having to re-write this code for every file. I suppose making a table with all the links and looping through it?
  14. Tried it. It does not work as expected. When typing, nametag does not disappear. One thing to be noted is that when doing this, for i, v in pairs(my_player_list) do 'i' returns player element and not 'v'. Makes any difference in how the 'difference' function should operate? EDIT: Solved. Thank you @Platin - xNikoXD.
  15. addEventHandler("onClientRender", root, function() local playerTable = getElementsByType("player") rTable = difference(playerTable, my_player_list) for i, v in pairs(rTable) do if (v) then outputChatBox(""..getPlayerName(v).."") local px, py, pz, tx, ty, tz, dist px, py, pz = getCameraMatrix( ) tx, ty, tz = getElementPosition( v ) dist = math.sqrt( ( px - tx ) ^ 2 + ( py - ty ) ^ 2 + ( pz - tz ) ^ 2 ) if dist < 60.0 then if isLineOfSightClear( px, py, pz, tx, ty, tz, true, false, false, true, false, false, false,localPlayer ) then local sx, sy, sz = getPedBonePosition( v, 6 ) local x,y = getScreenFromWorldPosition( sx, sy, sz + 0.2 ) local playerR, playerG, playerB = getPlayerNametagColor ( v ) if x then dxDrawBorderedText( string.gsub ( getPlayerName ( v ), "#%x%x%x%x%x%x", "" ).."", x, y, x, y, tocolor(playerR, playerG, playerB), 1.1, "default-bold", "center", "center" ) end else return end end end end end) How else would you approach this then? element datas maybe?
  16. I'm trying to find the difference between two tables. For e.g, if I have two tables, one with all players online in the server, and the other who are currently typing (have their chat box input active). I want to return a new table that would contain all players except the players who are typing. The code below should output the names of those players who are NOT typing at the moment, but it outputs names of even those players who are typing. I have already got the players who are typing, in a table, called 'my_player_list'. function difference(a, b) local aa = {} for k,v in pairs(a) do aa[v]=true end for k,v in pairs(b) do aa[v]=nil end local ret = {} local n = 0 for k,v in pairs(a) do if aa[v] then n=n+1 ret[n]=v end end return ret end addEventHandler("onClientRender", root, function() -- using onClientRender here because I'm going to use dxDraw functions here local playerTable = getElementsByType("player") rTable = difference(playerTable, my_player_list) -- my_player_list is a table which contains players who are typing for i, v in pairs(rTable) do if (v) then outputChatBox(""..getPlayerName(v).."") end end end) Thanks.
  17. I was wondering if it is possible to get just the first letter of a player's name. If it is, then how?
  18. Solved. Just replaced 'WHERE' with 'SET'. Thanks @JeViCo anyway.
  19. @JeViCo I checked the variable values and they're fine. What do you mean by wrong column types / length?
  20. I downloaded the database from the server and browsed the table and found no values in it. This is where I trigger 'updateMemoCallback' in client side. if (source == InfoPanel.button[2]) then text_changelog = guiGetText(InfoPanel.memo[1]) text_rules = guiGetText(InfoPanel.memo[2]) text_general = guiGetText(InfoPanel.memo[3]) triggerServerEvent("updateMemoCallback", resourceRoot, text_changelog, text_rules, text_general) -- on 'onClientGUIClick' event.
  21. @JeViCo Still not working. outputChatBox(""..tostring(text_c_changelog).."", root, 255, 255, 255) outputs 'nil' every time the resource is restarted.
  22. I do not want the query to be freed as I have to use its values. Can't use dbExec either because then I wouldn't be able to update the memo text with the same GUI button. Tried this, still not retrieving values, addEventHandler("onResourceStart", root, function() local db = exports.infopaneldb:getConnection() local dbquery = dbQuery(function(qh) local results = dbPoll(qh, 0) for index, textresults in pairs(results) do text_c_changelog = textresults.text_changelog text_c_rules = textresults.text_rules text_c_general = textresults.text_general triggerClientEvent(root, "updateMemoOnStart", resourceRoot, text_c_changelog, text_c_rules, text_c_general) outputChatBox(""..tostring(text_c_changelog).."", 255, 255, 255) -- this is a test end end, db, "SELECT * FROM text") end) This is how the wiki did it.
  23. Create a memo and a button which you would use to send the message on the client side. Upon hitting the button, get the text, then send it to server through triggerServerEvent. From there you could use outputChatBox with 'root' as its first argument to send it to every player.
  24. I know that it is definitely saving the text in the db because I got an error in debug after 5 minutes that '5 minutes have passed and data has not been retrieved from table (with correct data shown)' something like that. I'm not sure if I'm retrieving the data in the right way. Any help would be appreciated. server: function loadAllData(queryHandle) local results = dbPoll(queryHandle, 0) for index, textresults in pairs(results) do text_c_changelog = textresults.text_changelog text_c_rules = textresults.text_rules text_c_general = textresults.text_general triggerClientEvent(root, "updateMemoOnStart", resourceRoot, text_c_changelog, text_c_rules, text_c_general) end end addEventHandler("onResourceStart", root, function() local db = exports.infopaneldb:getConnection() dbQuery(loadAllData, db, "SELECT * FROM text") end) addEvent("updateMemoCallback", true) function memoCB(text_changelog, text_rules, text_general) local db = exports.infopaneldb:getConnection() dbQuery(db, "UPDATE text WHERE text_changelog = ?, text_rules = ?, text_general = ?;", text_changelog, text_rules, text_general) triggerClientEvent(root, "updateMemo", resourceRoot, text_changelog, text_rules, text_general) local players = getElementsByType("player") end addEventHandler("updateMemoCallback", root, memoCB) client: addEvent("updateMemo", true) addEventHandler("updateMemo", root, function(text_changelog, text_rules, text_general) guiSetText(InfoPanel.memo[1], text_changelog) guiSetText(InfoPanel.memo[2], text_rules) guiSetText(InfoPanel.memo[3], text_general) end) addEvent("updateMemoOnStart", true) addEventHandler("updateMemoOnStart", root, function(text_c_changelog, text_c_rules, text_c_general) guiSetText(InfoPanel.memo[1], text_c_changelog) guiSetText(InfoPanel.memo[2], text_c_rules) guiSetText(InfoPanel.memo[3], text_c_general) end) Also, while making the database in SQLite browser application, I could not set 'Auto increment' for all 3 of the table values - text_changelog, text_rules and text_general. Maybe this is the cause?
×
×
  • Create New...