Jump to content

Bilal135

Members
  • Posts

    843
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by Bilal135

  1. As far as I know, there is no limit to the resources that you can run on a local server, and even if we assume that there was one, it would be much higher than 20. Your problem is certainly a very unusual one. Make sure that the new resources which you added have the correct meta.xml, and each resource does not have its files in sub folders.
  2. local vehicleSlotID = 0 addCommandHandler("car", function(source, cmd, vehicle) local acc = getAccountName(getPlayerAccount(source)) if isObjectInACLGroup("user."..acc, aclGetGroup("Admin")) then if not vehicle then return outputChatBox("/"..cmd.." [ID / VehicleName]", source) end local playerX, playerY, playerZ = getElementPosition(source) local vehID = tonumber(vehicle) and tonumber(vehicle) or getVehicleModelFromName(vehicle) -- do stuff else return false end end) This section is not for asking help. Next time, before posting, make sure you're doing it in the right section.
  3. Try, local myMarker = createMarker(1675.8000488281, -1004.5, 23.10000038147, 'cylinder', 1, 191, 148, 0, 255) -- create myMarker function MarkerHit(hitElement, matchingDimension) local elementType = getElementType(hitElement) if source == myMarker then outputChatBox("ASdasdasdasdasdasdasdasd") end end addEventHandler("onMarkerHit", root, MarkerHit)
  4. To understand what [1] and [2] are, first you must understand the basics of table. A table is like a container and you can put a lot of things in it, that can be accessed later on. For example, -- Example table local table = {"John", "David", "Abraham", "Adam"} You can insert any value in a table (e.g integers, strings etc). Every item in a table has an index value, which is basically an integer value that tells the position of its items. In this case, local table = {"John", "David", "Abraham", "Adam"} -- John has index value '1' because it is the first item in our table -- David's index value is 2, and so on. When we refer to any particular item in a table, we use the following format, tableName[indexNumber]; For example, if we wanted to output the value of David, we would do this, outputChatBox( table[2], sendToElement ) -- 'sendToElement' is the element which you want to send the message to, e.g root, source. When we did the for loop in the above source code, we actually looped through all the values in the table, e.g, for index, value in ipairs(table) do outputChatBox(value, sendToElement) end This would output all the values in our table. In other words, we would see John, David, Abraham and Adam outputted in chat box. In your source code, vehicles is a table that is returned by the function getElementsWithinRange, and obviously it has keys / indexes, and values. Values would be the player elements and keys / indexes would be the number that they are referred to in the table. local target = vehicles[1] ~= vehicle and vehicles[1] or vehicles[2] What we are essentially checking here is that the target is not going to be ourselves but someone else, so the missiles don't actually target us. In other words, vehicles[1] is the first player element in the vehicles table. Check if vehicle[1] is not our own vehicle, which is defined above as, local vehicle = getPedOccupiedVehicle(localPlayer). ------- About the debug error, it is because 'v' is not specifying an index i.e a player element, so if you replace it with 'v[1]', it should work. But then again, before doing this, add a check to ensure v[1] is not our own vehicle. I'm glad you figured it out on your own. Good luck.
  5. local vehicleID = 425; local projectileType = 20; local targetRange = 300; function shootProjectile() -- Ensure player is in a vehicle before trying to get the vehicle of player. if isPedInVehicle(localPlayer) then local vehicle = getPedOccupiedVehicle(localPlayer) if (vehicle and getElementModel(vehicle) == vehicleID) then local x, y, z = getElementPosition(vehicle) local targets = getElementsWithinRange(x, y, z, targetRange, "vehicle") -- Returns a table containing all the elements of the specified type within range. for k, v in pairs(targets) do -- Loop through the table. if v and isElement(v) then -- Here 'v' are our targets. Check if exists. createProjectile(vehicle, projectileType, x, y, z, v) -- Create projectiles that will target all of the players within targetRange. end end end else return false end end bindKey( "lshift", "down", shootProjectile)
  6. projectile createProjectile ( element creator, int weaponType [, float posX, float posY, float posZ, float force = 1.0, element target = nil, float rotX, float rotY, float rotZ, float velX, float velY, float velZ, int model ] ) You need to specify its 7th argument - target.
  7. -- replace line 3 with this if getVehicleID(vehicle) == 425 then EDIT: use getElementModel instead of getVehicleID. (I’m on mobile so can’t edit the snippet directly). Also add a check if vehicle exists or not.
  8. So I have a table called joinedPlayers and it looks something like this, joinedPlayers = { [key] = {source, posX, posY, posZ} } -- 'key' is generated automatically I inserted into the table in this way, local x, y, z = getElementPosition(source) table.insert(joinedPlayers, {source, x, y, z}) I was trying to find the key of a certain player but kept getting this error - 'end' expected near 'break'. function findPlayerKey(player) for k, v in pairs(joinedPlayers) do if v[1] == player then return k break else return false end end end
  9. Check if the same happens with GTA SA single player. If it does, then your game could be corrupted. See if reinstalling the game would fix the issue.
  10. You could use SQLite browser (application) to construct databases. You may find a few tutorials on YouTube. This tutorial may help you out, https://youtu.be/XWHHavDS_go
  11. dxCreateShader dxCreateTexture dxSetShaderValue engineApplyShaderToWorldTexture
  12. The problem could be with getPlayerAcc function in "Accounts" resource, or where you set the element data 'pCanistra'. Show us more.
  13. Yes, there is. You can create a local server and open ports (22003, 22005 and 22126) through your router settings, which would allow players to join your server. There are quite a few tutorials on YouTube about setting up a local server, so you can watch those.
  14. You can send local player to server as 3rd argument of triggerServerEvent. Can you explain in more detail what you're trying to achieve?
  15. 'playVideo' is not a built in function. Its a useful function that can be found on wiki but it has to be defined first. Copy and paste this above renderBSOD, function playVideo (posX, posY, width, height, url, duration, canClose, postGUI) if not posX or not posY or not width or not height or not url then return false end local webBrowser = false closeButton = guiCreateButton (0.97, 0, 0.03, 0.03, "X", true) guiSetAlpha (closeButton, 0.5) guiSetVisible (closeButton, false) if not isElement (webBrowser) then webBrowser = createBrowser (width, height, false, false) function createVideoPlayer () function webBrowserRender () dxDrawImage (posX, posY, width, height, webBrowser, 0, 0, 0, tocolor(255,255,255,255), postGUI) end loadBrowserURL (webBrowser, url) setTimer (function() addEventHandler ("onClientRender", getRootElement(), webBrowserRender) showChat (false) if canClose then guiSetVisible (closeButton, true) showCursor (true) end end, 500, 1) setElementFrozen (localPlayer, true) if duration then videoTimer = setTimer (function() removeEventHandler ("onClientRender", getRootElement(), webBrowserRender) setElementFrozen (localPlayer, false) guiSetVisible (closeButton, false) showCursor (false) showChat (true) destroyElement (webBrowser) end, duration, 1) end addEventHandler ("onClientGUIClick", closeButton, function (button, state) if button == "left" then if isTimer (videoTimer) then killTimer (videoTimer) videoTimer = nil removeEventHandler ("onClientRender", getRootElement(), webBrowserRender) setElementFrozen (localPlayer, false) guiSetVisible (closeButton, false) showCursor (false) showChat (true) destroyElement (webBrowser) end end end, false) end setTimer (createVideoPlayer, 500, 1) end end
  16. Now its downloading already downloaded vehicles and all vehicles every time. I changed quite a lot of stuff. 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" }, { model = 596, txd = "https://drive.google.com/uc?export=download&id=15zbo6U9wxVBzZHTkrM8wTlDDMfasWJn1", dff = "https://drive.google.com/uc?export=download&id=1qyJC2wAD7QAmvS29IDgIXMwf7vqVeFVy" } } -- OUTPUT local modelDataList = {} local modelDataListAll = {} -- local fileTypeLoadOrder = { "txd", "dff", "col" } 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 k == k2 then insert = false break; end end if insert then table.insert(ret, v) end end return ret end -- Server call back / client trigger addEvent("alreadyDownloadedFiles", true) addEventHandler("alreadyDownloadedFiles", resourceRoot, function(xmlFilePaths) local notDownloadedFiles = difference(links, xmlFilePaths) for k, v in pairs(notDownloadedFiles) do outputChatBox(""..k.."", root) end if notDownloadedFiles then local fileRequest = function(data, err, linkIndex, fileType) if not err.success then print(err.statusCode) end outputChatBox("Download started", root) local link = notDownloadedFiles[linkIndex] local model = link.model local modelData = modelDataList[model] if not modelData then modelData = { fileCountRemaining = link.fileCount } modelDataList[model] = modelData end modelData.model = model modelData[fileType] = data modelData.fileCountRemaining = modelData.fileCountRemaining - 1 if modelData.fileCountRemaining == 0 then modelData.fileCountRemaining = nil modelData.ready = true end end for i=1, #notDownloadedFiles do local link = notDownloadedFiles[i] local fileCount = 0 for j=1, #fileTypeLoadOrder do local fileType = fileTypeLoadOrder[j] local url = link[fileType] if url then fetchRemote(url, {}, fileRequest, {i, fileType}) fileCount = fileCount + 1 end end link.fileCount = fileCount end else return outputChatBox("Function is being returned", root) end end ) addEvent("downloadAllFiles", true) addEventHandler("downloadAllFiles", root, function() local fileRequest = function(data, err, linkIndex, fileType) if not err.success then print(err.statusCode) end outputChatBox("[No previous files found] Download started", root) local link = links[linkIndex] local model = link.model local modelData = modelDataListAll[model] if not modelData then modelData = { fileCountRemaining = link.fileCount } modelDataListAll[model] = modelData end modelData.model = model modelData[fileType] = data modelData.fileCountRemaining = modelData.fileCountRemaining - 1 if modelData.fileCountRemaining == 0 then modelData.fileCountRemaining = nil modelData.ready = true end end for i=1, #links do local link = links[i] local fileCount = 0 for j=1, #fileTypeLoadOrder do local fileType = fileTypeLoadOrder[j] local url = link[fileType] if url then fetchRemote(url, {}, fileRequest, {i, fileType}) fileCount = fileCount + 1 end end link.fileCount = fileCount end end ) addEventHandler("onPlayerJoin", root, function() if not modelDataList or not modelDataListAll then return end if modelDataList then triggerLatentClientEvent(source, "downloadVehicle", 10^7, true, resourceRoot, modelDataList) elseif modelDataListAll then triggerLatentClientEvent(source, "downloadVehicle_2", 10^7, true, resourceRoot, modelDataListAll) end end ) ----------------------- Tables ---------------------------------- filePaths = { [560] = { col = "files/560/mod.col", txd = "files/560/mod.txd", dff = "files/560/mod.dff" } } ----------------------- File Functions -------------------------- function txdCreateFilePath(id, txdpath) filePaths[id] = { txd = txdpath } end function dffCreateFilePath(id, dffpath) filePaths[id] = { dff = dffpath } end function colCreateFilePath(id, colpath) filePaths[id] = { col = colpath } end function txdUpdateFilePath(id, txdpath) filePaths[id].txd = txdpath end function dffUpdateFilePath(id, dffpath) filePaths[id].dff = dffpath end function colUpdateFilePath(id, colpath) filePaths[id].col = colpath end ----------------------------------------------------------------- addEventHandler("onClientResourceStart", resourceRoot, function () local xml = exports.xmlData local xmlFilePaths = xml:xmlLoadData("downloadedFiles_10", true) if not xmlFilePaths then return triggerEvent("downloadAllFiles_c", resourceRoot) end for model, v in pairs(xmlFilePaths) do local txd = v.txd if txd then local txd_loaded = engineLoadTXD("files/"..model.."/mod.txd") if txd_loaded then engineImportTXD(txd_loaded, model) txdUpdateFilePath(model, "files/"..model.."/mod.txd") outputChatBox("[old files] replacing txd") end end local dff = v.dff if dff then local dff_loaded = engineLoadDFF("files/"..model.."/mod.dff") if dff_loaded then engineReplaceModel(dff_loaded, model) txdUpdateFilePath(model, "files/"..model.."/mod.dff") end end local col = v.col if col then local col_loaded = engineLoadCOL("files/"..model.."/mod.col") if col_loaded then engineReplaceCOL(col_loaded, model) colUpdateFilePath(model, "files/"..model.."/mod.col") end end end triggerServerEvent("alreadyDownloadedFiles", resourceRoot, xmlFilePaths) end ) addEvent("downloadAllFiles_c", true) addEventHandler("downloadAllFiles_c", root, function() exports.xmlData:xmlSaveData("downloadedFiles_10", filePaths, true) triggerServerEvent("downloadAllFiles", resourceRoot) end ) addEvent("downloadVehicle", true) addEventHandler("downloadVehicle", resourceRoot, function (modelDataList) for model, v in pairs(modelDataList) do local txd = v.txd if txd then local file = fileCreate("files/"..model.."/mod.txd") fileWrite(file, txd) fileClose(file) local txd_loaded = engineLoadTXD(txd) if txd_loaded then engineImportTXD(txd_loaded, model) txdCreateFilePath(model, "files/"..model.."/mod.txd") outputChatBox("[downloadedFiles] replacing txd") end end local dff = v.dff if dff then local file = fileCreate("files/"..model.."/mod.dff") fileWrite(file, dff) fileClose(file) local dff_loaded = engineLoadDFF(dff) if dff_loaded then engineReplaceModel(dff_loaded, model) txdCreateFilePath(model, "files/"..model.."/mod.dff") outputChatBox("[downloadedFiles] replacing dff") end end local col = v.col if col then local file = fileCreate("files/"..model.."/mod.col") fileWrite(file, col) fileClose(file) local col_loaded = engineLoadCOL(col) if col_loaded then engineReplaceCOL (col_loaded, model) colCreateFilePath(model, "files/"..model.."/mod.col") outputChatBox("[downloadedFiles] replacing col") end end exports.xmlData:xmlSaveData("downloadedFiles_10", filePaths, true) end end ) addEvent("downloadVehicle_2", true) addEventHandler("downloadVehicle_2", resourceRoot, function (modelDataListAll) for model, v in pairs(modelDataListAll) do local txd = v.txd if txd then local file = fileCreate("files/"..model.."/mod.txd") fileWrite(file, txd) fileClose(file) local txd_loaded = engineLoadTXD(txd) if txd_loaded then engineImportTXD(txd_loaded, model) txdCreateFilePath(model, "files/"..model.."/mod.txd") outputChatBox("[downloadedFiles] replacing txd") end end local dff = v.dff if dff then local file = fileCreate("files/"..model.."/mod.dff") fileWrite(file, dff) fileClose(file) local dff_loaded = engineLoadDFF(dff) if dff_loaded then engineReplaceModel(dff_loaded, model) txdCreateFilePath(model, "files/"..model.."/mod.dff") outputChatBox("[downloadedFiles] replacing dff") end end local col = v.col if col then local file = fileCreate("files/"..model.."/mod.col") fileWrite(file, col) fileClose(file) local col_loaded = engineLoadCOL(col) if col_loaded then engineReplaceCOL (col_loaded, model) colCreateFilePath(model, "files/"..model.."/mod.col") outputChatBox("[downloadedFiles] replacing col") end end exports.xmlData:xmlSaveData("downloadedFiles_10", filePaths, true) end end ) --[[local txd = v.txd local dff = v.dff engineImportTXD(engineLoadTXD(txd), model) engineReplaceModel(engineLoadDFF(dff), model) if data == "txd" then engineImportTXD(engineLoadTXD(txd), model) elseif data == "dff" then engineReplaceModel(engineLoadDFF(dff), model) --]]
  17. -- Fixed this error. Working on another error.
  18. I've changed a few things. It outputs the following error, 'Error: \client.Lua:50: Error loading TXD @ 'engineLoadTXD' [files/560/mod.txd]' Client.Lua: ----------------------- Tables ---------------------------------- filePaths = {} ----------------------- File Functions -------------------------- function txdCreateFilePath(id, txdpath) filePaths[id] = { txd = txdpath } end function dffCreateFilePath(id, dffpath) filePaths[id] = { dff = dffpath } end function colCreateFilePath(id, colpath) filePaths[id] = { col = colpath } end function txdUpdateFilePath(id, txdpath) filePath[id].txd = txdpath end function dffUpdateFilePath(id, dffpath) filePath[id].dff = dffpath end function colUpdateFilePath(id, colpath) filePath[id].col = colpath end ----------------------------------------------------------------- addEventHandler("onClientResourceStart", resourceRoot, function () local xml = exports.xmlData local xmlFilePaths = xml:xmlLoadData("downloadedFiles", true) if not xmlFilePaths then xml:xmlSaveData("downloadedFiles", filePaths, true) xmlFilePaths = xml:xmlLoadData("downloadedFiles", true) end for model, v in pairs(xmlFilePaths) do local txd = v.txd if txd then local txd_loaded = engineLoadTXD("files/"..model.."/mod.txd") if txd_loaded then engineImportTXD(txd_loaded, model) txdUpdateFilePath(model, "files/"..model.."/mod.txd") end end local dff = v.dff if dff then local dff_loaded = engineLoadDFF("files/"..model.."/mod.dff") if dff_loaded then engineReplaceModel(dff_loaded, model) txdUpdateFilePath(model, "files/"..model.."/mod.dff") end end local col = v.col if col then local col_loaded = engineLoadCOL("files/"..model.."/mod.col") if col_loaded then engineReplaceCOL(col_loaded, model) colUpdateFilePath(model, "files/"..model.."/mod.col") end end end triggerServerEvent("alreadyDownloadedFiles", resourceRoot, xmlFilePaths) end ) addEvent("downloadVehicle", true) addEventHandler("downloadVehicle", resourceRoot, function (modelDataList) for model, v in pairs(modelDataList) do local txd = v.txd if txd then local txd_loaded = engineLoadTXD(txd) if txd_loaded then engineImportTXD(txd_loaded, model) local file = fileCreate("files/"..model.."/mod.txd") fileClose(file) txdCreateFilePath(model, "files/"..model.."/mod.txd") outputChatBox("[downloadedFiles] replacing txd") end end local dff = v.dff if dff then local dff_loaded = engineLoadDFF(dff) if dff_loaded then engineReplaceModel(dff_loaded, model) local file = fileCreate("files/"..model.."/mod.dff") fileClose(file) txdCreateFilePath(model, "files/"..model.."/mod.dff") outputChatBox("[downloadedFiles] replacing dff") end end local col = v.col if col then local col_loaded = engineLoadCOL(col) if col_loaded then engineReplaceCOL (col_loaded, model) local file = fileCreate("files/"..model.."/mod.col") fileClose(file) colCreateFilePath(model, "files/"..model.."/mod.col") outputChatBox("[downloadedFiles] replacing col") end end exports.xmlData:xmlSaveData("downloadedFiles", filePaths, true) end end ) Server.Lua: 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 = { "txd", "dff", "col" } 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 k == k2 then insert = false break; end end if insert then table.insert(ret, a[k].model) table.insert(ret, a[k].txd) table.insert(ret, a[k].dff) end end return ret end -- Server call back / client trigger addEvent("alreadyDownloadedFiles", true) addEventHandler("alreadyDownloadedFiles", resourceRoot, function(xmlFilePaths) local notDownloadedFiles = difference(links, xmlFilePaths) if notDownloadedFiles then local fileRequest = function(data, err, linkIndex, fileType) if not err.success then print(err.statusCode) end outputChatBox("Download started", root) local link = notDownloadedFiles[linkIndex] local model = link.model local modelData = modelDataList[model] if not modelData then modelData = { fileCountRemaining = link.fileCount } modelDataList[model] = modelData end modelData.model = model modelData[fileType] = data modelData.fileCountRemaining = modelData.fileCountRemaining - 1 if modelData.fileCountRemaining == 0 then modelData.fileCountRemaining = nil modelData.ready = true end end for i=1, #notDownloadedFiles do local link = notDownloadedFiles[i] local fileCount = 0 for j=1, #fileTypeLoadOrder do local fileType = fileTypeLoadOrder[j] local url = link[fileType] if url then fetchRemote(url, {}, fileRequest, {i, fileType}) fileCount = fileCount + 1 end end link.fileCount = fileCount end else return end end ) addEventHandler("onPlayerJoin", root, function() triggerLatentClientEvent(source, "downloadVehicle", 10^7, true, resourceRoot, modelDataList) end )
  19. So I don't need to write the files at all?
  20. @IIYAMA getting an error here, local txd = v.txd if txd then local txd_loaded = engineLoadTXD(txd) if txd_loaded then engineImportTXD(txd_loaded, model) local file = fileCreate("files/"..model.."/mod.txd") fileWrite(file, txd_loaded) fileClose(file) txdCreateFilePath(model, "files/"..model.."/mod.txd") outputChatBox("[downloadedFiles] replacing txd") end end Bad argument fileWrite, expected string at argument 2, got txd. Getting errors for cols, txds and dffs.
  21. I removed the files from the meta. Added the update functions. addEvent("alreadyDownloadedFiles", true) addEventHandler("alreadyDownloadedFiles", resourceRoot, function(filePaths) local notDownloadedFiles = difference(modelDataList, filePaths) modelDataList = notDownloadedFiles triggerLatentClientEvent(source, "downloadVehicle", 10^7, true, resourceRoot, modelDataList) end ) Tried debugging this code. 'notDownloadedFiles' does not return a usable value. Therefore, nothing is sent to the client with the triggerLatentClientEvent. That results in the files not being created in the first place, and thus, the error in debug, 'Error loading DFF' and 'Error loading TXD'. Its probably because modelDataList contains data and not the file paths while filePaths contains the file paths, and comparing them with 'difference' function does not return the values that are needed. So, I assume that another filePaths table has to be created server side, containing all the file paths of the files which are going to be downloaded. Then, use xmlLoadData to retrieve the client sided filePaths in server side. Comparing the two of them would give us the file paths of the files which are not downloaded in the client side, exactly what we need. But how does one use those file paths to trigger their download from links table? That is what I can't figure out. Is my approach correct? @IIYAMA
  22. @IIYAMA I did my best and this is what I came up with. Does not work. Outputs one error in debug. I added the mod files in meta.xml as well, should I do that or not? Client.Lua: ----------------------- Tables ---------------------------------- filePaths = { [560] = { col = "files/560/mod.col", txd = "files/560/mod.txd", dff = "files/560/mod.dff" }, [411] = { col = "files/411/mod.col", txd = "files/411/mod.txd", dff = "files/411/mod.dff" } } ----------------------- File Functions -------------------------- function txdCreateFilePath(id, txdpath) filePaths[id] = { txd = txdpath } end function dffCreateFilePath(id, dffpath) filePaths[id] = { dff = dffpath } end function colCreateFilePath(id, colpath) filePaths[id] = { col = colpath } end function txdUpdateFilePath(id, txdpath) filePath[id].txd = txdpath end function dffUpdateFilePath(id, dffpath) filePath[id].dff = dffpath end function colUpdateFilePath(id, colpath) filePath[id].col = colpath end ----------------------------------------------------------------- local xml = exports.xmlData addEventHandler("onClientResourceStart", resourceRoot, function () triggerServerEvent("alreadyDownloadedFiles", source, filePaths) local xmlFilePaths = xml:xmlLoadData("downloadedFiles", true) for model, v in pairs(xmlFilePaths) do local col = v.col if col then local col_loaded = engineLoadCOL("files/"..model.."/mod.col") if col_loaded then engineReplaceCOL(col_loaded, model) end end local txd = v.txd if txd then local txd_loaded = engineLoadTXD("files/"..model.."/mod.txd") if txd_loaded then engineImportTXD(txd_loaded, model) end end local dff = v.dff if dff then local dff_loaded = engineLoadDFF("files/"..model.."/mod.dff") if dff_loaded then engineReplaceModel(dff_loaded, model) end end end end ) addEvent("downloadVehicle", true) addEventHandler("downloadVehicle", resourceRoot, function (modelDataList) for model, v in pairs(modelDataList) do local col = v.col if col then local col_loaded = engineLoadCOL("files/"..model.."/mod.col") if col_loaded then engineReplaceCOL (col_loaded, model) local file = fileCreate("files/"..model.."/mod.col") fileWrite(file, col_loaded) fileClose(file) colCreateFilePath(model, "files/"..model.."/mod.col") outputChatBox("[downloadedFiles] replacing col") end end local txd = v.txd if txd then local txd_loaded = engineLoadTXD("files/"..model.."/mod.txd") if txd_loaded then engineImportTXD(txd_loaded, model) local file = fileCreate("files/"..model.."/mod.txd") fileWrite(file, txd_loaded) fileClose(file) txdCreateFilePath(model, "files/"..model.."/mod.txd") outputChatBox("[downloadedFiles] replacing txd") end end local dff = v.dff if dff then local dff_loaded = engineLoadDFF("files/"..model.."/mod.dff") if dff_loaded then engineReplaceModel(dff_loaded, model) local file = fileCreate("files/"..model.."/mod.dff") fileWrite(file, dff_loaded) fileClose(file) txdCreateFilePath(model, "files/"..model.."/mod.dff") outputChatBox("[downloadedFiles] replacing dff") end end xml:xmlSaveData("downloadedFiles", filePaths, true) end end ) server.Lua: 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 -- Server call back / client trigger addEvent("alreadyDownloadedFiles", true) addEventHandler("alreadyDownloadedFiles", resourceRoot, function(filePaths) local notDownloadedFiles = difference(modelDataList, filePaths) modelDataList = notDownloadedFiles triggerLatentClientEvent(source, "downloadVehicle", 10^7, true, resourceRoot, modelDataList) end ) meta.xml: <meta> <script src="server.Lua" type="server"/> <script src="client.Lua" type="client"/> <file src="files/560/mod.txd" download="false"/> -- I later removed these two files, still no effect. <file src="files/560/mod.dff" download="false"/> <min_mta_version>1.5.4-9.11342</min_mta_version> </meta> Error in debug: I do not know where to use the update functions. Not sure what I did above is even correct.
×
×
  • Create New...