Jump to content

question about 'fileWrite'


xTravax

Recommended Posts

i wanted to ask how couuld i do something like this

i got a file (e.g a script or just random file with text) and i don't have it in meta,but i want to use fileWrite to write it

so if the file was a e.g server-side script(server.lua) like this

  
function test() 
outputChatBox("server file") 
end 
addEventHandler("onVehicleEnter",root,test) 
  

how could i use 'fileWrite' to write it to player's disk?

i am getting confused about second argument 'string1' -- text which we want to write

and first argument would be a file e.g "server_s.lua"

so how could i write server.lua file to server_s.lua ?

how do i load the server.lua text ? that's confusing me

Link to comment

I think you need to do some research about these functions first, because it seems you didn't understand how they work.

The wiki has some nice examples.

To send some file from server to client, you need to read its data and send it. Then create a new file to write in.

Link to comment

i have tried to do this but i got a warning

writeScripts = { 
{"send_client.lua"}, 
{"send_server.lua"}, 
} 
  
function triggerWriting(filepath) 
if not fileExists(filepath) then 
outputChatBox("file doesn't exist, about to create and write it!") 
writeScriptsToDisk() 
outputChatBox("starting to write...") 
end 
end 
addEventHandler("onResourceStart",root,triggerWriting) 
  
function writeScriptsToDisk(filepath) 
   for i,v in ipairs(writeScripts) do 
      local theFile = fileCreate(v[1]) 
      local fileData = fileRead(theFile,120) 
      if theFile then 
         if fileData then 
            outputChatBox("file was creating, about to write data...") 
            fileWrite(theFile,fileData) 
            outputChatBox("writing...") 
            fileClose(theFile) 
            outputChatBox("Done!") 
         end 
      end 
   end 
end 

bad argument fileExists, expected string at argument 1, got resource-data

please have understanding that i am new to file functions,haven't used them before and i don't have good experience with it

Link to comment
  
function triggerWriting(filepath) 
if not fileExists(filepath) then 
outputChatBox("file doesn't exist, about to create and write it!") 
writeScriptsToDisk() 
outputChatBox("starting to write...") 
end 
end 
addEventHandler("onResourceStart",root,triggerWriting) 
  

This is kinda wrong. The event onResourceStart doesn't provide any filepath, it only gives you the resource that was started.

Also, most times its better to use resourceRoot instead of root, when working with this event.

Link to comment

Why do you wanna do this anyway?

Just put them in meta so they are downloaded automatically, if its not about maploading or anything that has to be updated.

As I said, read the data on server, send it to the client, and just write it into a new file.

fileRead -> triggerClientEvent -> fileWrite

Link to comment

i was using scripts just as example,actually i want to write big files like mods and so on, but i also have no idea how to pass data with triggerClientEvent even tho i readed that wiki page already

also im having problems with even detecting do the following scripts exist, so i can't even start on working your way

Link to comment
--Server-Side: 
table 
ipairs 
fileExists 
fileOpen 
fileRead 
triggerClientEvent 
fileClose 
  
--Client-Side: 
fileExists 
fileCreate 
fileWrite 
fileClose 
triggerServerEvent --(Trigger back to the server to request to start the resource) 
[url=https://wiki.multitheftauto.com/wiki/LoadScript]https://wiki.multitheftauto.com/wiki/LoadScript[/url] 

Not sure about the last link, not sure about how starting the script for client only.

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...