Jump to content

About FetchRemote JPG/PNG File


Annas

Recommended Posts

Hello, all what i want is loading a skin shader without download..

So i tried to create this resource

-- Server Side 
  
function downloadPlayerAlternateSkin(plr, cmd, filename) 
    theskinId = filename 
    if (filename) then 
    fetchRemote("http://localhost/shadersqsdqs/"..filename..".jpg", checkPlayerAlternateSkin) 
    end 
end 
addCommandHandler("loadshader", downloadPlayerAlternateSkin) 
  
  
function checkPlayerAlternateSkin(responseData, errno) 
    if (errno == 0) then 
        GottheSkin = responseData 
    end 
end 
  
function setPlayerAlternateSkin(player, theid, thepng) 
    theid = theskinId 
    thepng = GottheSkin 
    textureName = "*" 
    if (not GottheSkin) then 
        outputChatBox("Something goes wrong, please contact an admin.", player, 255, 0, 0) 
        return 
    end 
    triggerClientEvent(root, "CSTshaders.applyShader", root, player, {theid, textureName, thepng}, "skin" ) 
end 

What i want?:

- Add jpg file (Example: 5.jpg) on (http://localhost/shadersqsdqs) folder

- Go ingame and type "./loadshader 5" to download the JPG file (it should goes to MTA->mods->Deathmatch->priv->[iD or Key]->ResourceName)

The problem is:

It didn't want to be downloaded, well i don't know if Fetch Remote able to download PNG/JPG files or no..

Help me please

Link to comment

If fetchRemote is on the serverside, then nothing should be downloaded/saved under ../priv/ as far as I'm concerned. (And I don't think anything get's downloaded/saved even if used through clientside) It's probably your clientside code, upon receiving the pixel code (from PNG/JPEG) that saves it to "@.png" or whatever (as long as there is the prefix "@" which means it'll be in the priv folder)

Link to comment

fetchRemote is not for downloading files. Use downloadFile instead. fetchRemote is used for POST and GET requests.

After seeing the examples, reliazed that you can do that. You can use the example. You can create a texture using it client side and draw it then.. or apply it.

Link to comment
If fetchRemote is on the serverside, then nothing should be downloaded/saved under ../priv/ as far as I'm concerned. (And I don't think anything get's downloaded/saved even if used through clientside) It's probably your clientside code, upon receiving the pixel code (from PNG/JPEG) that saves it to "@.png" or whatever (as long as there is the prefix "@" which means it'll be in the priv folder)

i didn't understand you .. , how to save the PNG/JPEG ? , where should i put the '@', can you make an example using my code?, and thanks

Link to comment
If fetchRemote is on the serverside, then nothing should be downloaded/saved under ../priv/ as far as I'm concerned. (And I don't think anything get's downloaded/saved even if used through clientside) It's probably your clientside code, upon receiving the pixel code (from PNG/JPEG) that saves it to "@.png" or whatever (as long as there is the prefix "@" which means it'll be in the priv folder)

i didn't understand you .. , how to save the PNG/JPEG ? , where should i put the '@', can you make an example using my code?, and thanks

You probably can't do that. But you can make a texture and load it as shader as I told. See the example.

Link to comment

The data variable in callback function can be sent to client side using triggerClientEvent and then save it using:

local f = fileCreate (":myResourceName/fileName")  
fileWrite ( f, data) 
fileClose ( f )  
f = nil 
  

Link to comment
The data variable in callback function can be sent to client side using triggerClientEvent and then save it using:
local f = fileCreate (":myResourceName/fileName")  
fileWrite ( f, data) 
fileClose ( f )  
f = nil 
  

Done thanks.

Im using this:

function downloadsCSTShaders (data, theskinId) 
local f = fileCreate ("@/jpg2/"..theskinId.."") 
fileWrite ( f, data) 
fileClose ( f ) 
f = nil 
end 
addEventHandler("CSTskins.downloadTheShaderOnSkins", root, downloadsCSTShaders) 

File created and everything is okey .. But, there is an issuse.. , the Texture cannot be created .. i used this .. but it's not working..

local textureElement = dxCreateTexture ( "@/jpg2/"..thepng.."" ); 

Bad file path @ 'dxCreateTexture' [@/jpg2/
Link to comment

Hey, It's working perfect, Now i need to make it, select (filename) from MySQL.. but it's not working

Notice:

LS1bwbU.png

  
function downloadPlayerAlternatexx() 
    local filename = exports.CSTmysql:query("SELECT * shaderid FROM skinsShaders") 
    if (filename) then 
    fetchRemote("http://localhost/shadersqsdqs/"..filename..".jpg", checkPlayerAlternateSkin) 
    end 
end 
addCommandHandler("additsx", downloadPlayerAlternatexx) 
  

The problem is:

It Didn't select (shaderid) ..

Maybe my code have issuse, please help me..

Link to comment
Hey, It's working perfect, Now i need to make it, select (filename) from MySQL.. but it's not working

Notice:

LS1bwbU.png

  
function downloadPlayerAlternatexx() 
    local filename = exports.CSTmysql:query("SELECT * shaderid FROM skinsShaders") 
    if (filename) then 
    fetchRemote("http://localhost/shadersqsdqs/"..filename..".jpg", checkPlayerAlternateSkin) 
    end 
end 
addCommandHandler("additsx", downloadPlayerAlternatexx) 
  

The problem is:

It Didn't select (shaderid) ..

Maybe my code have issuse, please help me..

I believe the variable filename return a table so you have to do something like this:

  
fetchRemote("http://localhost/shadersqsdqs/"..filename[1]["key"]..".jpg", checkPlayerAlternateSkin) 
  

Keep in mind that key is the column name so better change it.

Link to comment

The query itself has a problem.

  
  
function downloadPlayerAlternatexx(p, _) 
    local filename = exports.CSTmysql:query("SELECT * FROM skinsShaders") 
    if (#filename > 0 ) then 
    fetchRemote("http://localhost/shadersqsdqs/"..filename[1].shaderid..".jpg", checkPlayerAlternateSkin) 
    end 
end 
addCommandHandler("additsx", downloadPlayerAlternatexx) 
  

Also you need to poll the result if you haven't.

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