Jump to content

problem with download function


John Smith

Recommended Posts

  • Replies 58
  • Created
  • Last Reply

Top Posters In This Topic

Preview?imageID=375&generatorTypeID=&panels=&text0=MTA%20noobs%20&text1=Y%20U%20NO%20USE%20fileWrite%3F&text2=&text3=

  
function createFile ( file ) 
local createdFile  = fileCreate(file)        
    if    createdFile  then   
        fileWrite( createdFile,file) 
                 fileClose( createdFile) 
    end  
 end 
       local resName = "YOURresourceName" 
            if not fileExists(":"..resName.."/model.txd") then 
       local file = fileOpen(":"..resName.."/model.txd",true) 
           if file then 
            local txdFile = fileRead ( file, fileGetSize(file) ) 
               fileClose(file) 
       createFile ( txdFile) 
        end   
end 
  

Edited by Guest
Link to comment
Preview?imageID=375&generatorTypeID=&panels=&text0=MTA%20noobs%20&text1=Y%20U%20NO%20USE%20fileWrite%3F&text2=&text3=
  
function createFile ( file ) 
local createdFile  = fileCreate(file)        
    if    createdFile  then   
        fileWrite( createdFile,file) 
                 fileClose( createdFile) 
    end  
 end 
       local resName = "YOURresourceName" 
            if not fileExists(":"..resName.."/model.txd") then 
       local file = fileOpen(":"..resName.."/model.txd",true) 
           if file then 
            local txdFile = fileRead ( file, fileGetSize(file) ) 
               fileClose(file) 
       createFile ( txdFile) 
        end   
end 
  

Y U NO STAY ON TOPIC

So, the problem was, there was no problem?!

Link to comment

Probably the problem was only that the 'onClientRender' was not working how he wished.

Ow and btw @Saml1er: That doesn't work, right? I mean. The files are server-sided, and you are now trying to load them client-sided? If so you will have to trigger from client to server, get the files and then trigger them back to client. :roll:

Link to comment
Probably the problem was only that the 'onClientRender' was not working how he wished.

Ow and btw @Saml1er: That doesn't work, right? I mean. The files are server-sided, and you are now trying to load them client-sided? If so you will have to trigger from client to server, get the files and then trigger them back to client. :roll:

Yes, you'll have to read those files from server side and send them back to client side. I did this in my lobby script and I had no problems with it.

@Bons: I stole your idea http://imgur.com/Xkfhe8q :twisted:

Link to comment

ohhh i just noticed it now,i forgot to make it like /mods folder path thing,i forgot about that sorry.

anyway could you just tell me 2 things?

1) what is this 3rd thing

loadMod(tableData[1], tableData[2], tableData[3]) 

tableData is for downloadFiles table and there are 2 files only so why must there be a third one?

or perhaps this is used because there are 3 arguments in loadMod function?

2) how could i exactly make more files?

something like this?

local downloadFiles = { 
    {"txd", "hunter.txd", 425}, 
    {"dff", "hunter.dff", 425}, 
    {"txd1", "infernus.txd", 411}, 
    {"dff1", "infernus.dff", 411}, 
} 

and it would work automatically or i have to add/edit some more things?

sorry for much questions, i just wanna know 100% how this script works so i could edit it later if needed

Link to comment

1.

*Cut ;) *

Hope that explanation was well enough to understand

2. And yes like that. The only thing you have to fill in:

*Cut ;) *

You can the script even let read meta.xml and check for 'file' childs and then check or 'download' is set to false. And if so, get that file name and put it in a table. And yes, I like fully automatically systems.

Edited by Guest
Link to comment

et-win im sorry but i didnt quite understand what u meant about what i have to fill in

if you have time, can you please please show me how this script(lines or full script) would look like if i had infernus in table with id 411 and then tried to check for it as well as checking for hunter file existance

sry for my english..

Link to comment

hey guys umm

i have tried now to make downloader in other way, without downloadFile function(for lower mta versions)

but i have no idea what i'm doing wrong

--server

dFiles = { 
{"test_server.lua"}, 
{"test_client.lua"}, 
} 
  
function someFileFunctionsFunction(thePlayer)   
outputChatBox("Function initiated!") 
   for _,dFiles in ipairs(dFiles) do 
      if not fileExists(":downloader/files/"..dFiles[1]) then 
         outputChatBox("Starting the download process...",thePlayer,0,255,0) 
           local files = fileOpen(":downloader/files/"..dFiles[1],true) 
                if files then 
                  local downloadFiles = fileRead (file,fileGetSize(file)) 
                        fileClose(files) 
                        triggerClientEvent("onStartDownload",thePlayer,downloadFiles,files) 
                         
                end 
       else 
       outputChatBox("even tho its not possible that player has downloaded already, he has!") 
       triggerClientEvent("onVehModRequest",thePlayer,"startMods") end 
    end 
end 
addCommandHandler("download",someFileFunctionsFunction) 

--client

addEvent("onStartDownload",true) 
  
function clientDownloaderFunction(downloadFiles,files) 
   if fileExists(files) then 
      fileCreate(files) 
      fileWrite(files,downloadFiles) 
      fileClose(files) 
      outputChatBox("Download has been finished!",0,0,255) 
   else outputChatBox("something went wrong") return end 
end 
addEventHandler("onStartDownload",root,clientDownloaderFunction) 

i dont have any errors except debug saying that onVehModRequest is not added client-side(as i didn't download files yet,should have been impossible to trigger that client function)

i dont know what to do now.

this isnt working, please help

Link to comment
Well,

first of all, in line 9, what file are you checking to exist there? You can only check files on the server in a serverside script.

Actually i wanted to replace table files with mod files which would load on client side,and im trying to download files which werent downloaded

Link to comment

So, when a player joins u send him a list with all file names.

Client checks if they are existing (actually you would also need to do some hashing e.g., to prevent manipulations).

Client adds all missing files to a table and sends it back to server.

Server opens each of that files, reads the content and send it to client.

Client creates that file and write the data into it.

After that u can load the mod.

Link to comment
  • 2 weeks later...

hi guys sorry for doublepost.

i have tried this:

replacing this line

if (source == getLocalPlayer()) then --line 60 

with this

for i,player in ipairs(getElementsByType("player")) do 
    if player then -- line 61 

would that work for other players too?

please someone.. sorry if im asking for too much but im just trying to understand whats problem in script

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...