.:HyPeX:. Posted January 23, 2015 Share Posted January 23, 2015 Well, i want to make a download system in wich you would actually download images (With fetchRemote). But, having said that, can i just directly draw them with dxDrawImage? My idea was something like this: function() if fetch.id then return end if not fileExists(":avatars/saved/id.png") then fetchRemote("page/uploads/photo-id.png") fetch.id = true end end -- onClientRender dxDrawImage(":avatars/saved/id.png") My issue is: Can i actually store the file and leave it there? (To avoid re-downloads mostly) Else i would just make them re-download on each join but even thought most images are not big size, some can actually be 200kb, and said that it will be one for each player... i'd prefer to dont have to re-download them.. Link to comment
Castillo Posted January 23, 2015 Share Posted January 23, 2015 You can save the images to the client computer to avoid redownloading. Link to comment
.:HyPeX:. Posted January 23, 2015 Author Share Posted January 23, 2015 You can save the images to the client computer to avoid redownloading. How so? fetchRemote provides the material but not a way to save them.. Link to comment
Castillo Posted January 23, 2015 Share Posted January 23, 2015 fileCreate fileWrite fileClose Link to comment
.:HyPeX:. Posted January 23, 2015 Author Share Posted January 23, 2015 fileCreate fileWrite fileClose or you can simply use downloadFile i need to set the images as attribute-false (And the IDs are managed by the website, so i cannot know them), so discard downloadFile.. How could i use fileWrite? i thought about this.. would this be correct? local texture = text -- from fetchRemote local string = dxGetPixels(texture) local file = fileCreate("Id-photo.txt") fileWrite(file, string) fileClose(file) --- Later on -- onLoad: local file = fileOpen("Id-photo.txt") local string = fileRead(file, fileGetSize(file)) fileClose(file) local texture = dxCreateTexture(string, 128,128) Link to comment
Castillo Posted January 23, 2015 Share Posted January 23, 2015 Forget about downloadFile, I noticed as soon as I posted it, then rapidly edited post. Anyway, local string = dxGetPixels(texture) What's that? is not needed, just save the value fetchRemote returns. Link to comment
.:HyPeX:. Posted January 23, 2015 Author Share Posted January 23, 2015 Forget about downloadFile, I noticed as soon as I posted it, then rapidly edited post.Anyway, local string = dxGetPixels(texture) What's that? is not needed, just save the value fetchRemote returns. As far as i know, the fetchRemote returns a material element and fileWrite needs a string https://wiki.multitheftauto.com/wiki/DxGetTexturePixels I'm just converting the image to pixels.. (My bad, typo there) Link to comment
Castillo Posted January 23, 2015 Share Posted January 23, 2015 It returns the pixels, why would it return a material element? just try it. Link to comment
ixjf Posted January 24, 2015 Share Posted January 24, 2015 fetchRemote has no idea of what you are fetching, how could it possibly provide you with a material element? It will fetch the contents of the file you specify and then you can simply save it to a file. Link to comment
.:HyPeX:. Posted January 24, 2015 Author Share Posted January 24, 2015 And how now i'm thinking of creating a serverside constant working thingy to send the clients the images if they need them, How could i check the images in case they change and know if they do? could i compare the file text with the fetchRemote? Link to comment
Dealman Posted January 24, 2015 Share Posted January 24, 2015 Compare their Md5 hashes? Link to comment
Gallardo9944 Posted January 24, 2015 Share Posted January 24, 2015 Instead of Md5, you can also compare their exact sizes. It's faster than Md5 if you compare a ton of pretty big files. Not as safe though (can be tricked, but i'm sure there's no-one to make a useful file with exactly the same size). But I'd stick to Md5 if I were you, just like Dealman said. Link to comment
.:HyPeX:. Posted January 24, 2015 Author Share Posted January 24, 2015 Instead of Md5, you can also compare their exact sizes. It's faster than Md5 if you compare a ton of pretty big files. Not as safe though (can be tricked, but i'm sure there's no-one to make a useful file with exactly the same size). But I'd stick to Md5 if I were you, just like Dealman said. No, nevermind about that, i'm using just forum avatars in-game. I just need a good way to check if users change them Link to comment
.:HyPeX:. Posted January 27, 2015 Author Share Posted January 27, 2015 Okay, i'm stuck in here... (ID is displayed as 0, but it shouldnt.) SQL table: addEventHandler('onPlayerLogin',root,function() local acc = getPlayerAccount(source) local acc = getAccountName(acc) local query = dbQuery(function(qh,player) local result = dbPoll(qh,0) local gvalue = 0 for _,row in ipairs(result) do for column,value in ipairs(row) do if column == "member_id" then gvalue = value setElementData(source, "member_id", gvalue) end end end outputConsole("id "..gvalue) outputConsole("acc "..acc) local query = dbQuery(function(qh,player) local result = dbPoll(qh,0) id, photo = "","" for _,row in ipairs(result) do for column,value in ipairs(row) do if column == "pp_member_id" then id = value elseif column == "pp_main_photo" then photo = value setElementData(player, "avatar", value) end end end outputConsole("1 "..id.." "..photo) fetchImage(id, photo) end,{player},Database, "SELECT pp_member_id,pp_main_photo FROM profile_portal WHERE pp_member_id = '?'", gvalue) end,{source},Database, "SELECT member_id FROM members WHERE name='"..acc.."'") end) function fetchImage(id,photo) outputConsole("2 "..id.." "..photo) fetchRemote ( "http://emp-clan.eu/uploads/"..photo, returnImage, "", false, id,photo ) end function returnImage(image, error, id, photo) outputConsole("3 "..id.." "..photo) if fileExists("saved/"..photo) then local file = fileOpen("saved/"..photo) local size = fileGetSize(file) fileClose(file) local result = fileRead(file,size) if result ~= image then fileDelete("saved/"..photo) local file = fileCreate("saved/"..photo) fileWrite(file, image) fileClose(file) end else local file = fileCreate("saved/"..photo) fileWrite(file, image) fileClose(file) end end Console output: Press 'p' to open your admin panel login: You successfully logged in id 0 acc hypex 1 2 3 Link to comment
GTX Posted January 28, 2015 Share Posted January 28, 2015 Lol? setElementData(source, "member_id", result[1]["member_id"]) Link to comment
.:HyPeX:. Posted January 28, 2015 Author Share Posted January 28, 2015 Lol? setElementData(source, "member_id", result[1]["member_id"]) It does the same job thought, but it is not retriving the ID... Link to comment
GTX Posted January 30, 2015 Share Posted January 30, 2015 local result = dbPoll(query, 0) Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now