mommytellme Posted June 11, 2014 Share Posted June 11, 2014 Welcome, I am supposed to create the question, whether it is possible using guiCreateStaticImage drawing picked up from URL, e.g. http://wiki.sa-mp.com/wroot/images2/2/2 ... le_400.jpg ? Link to comment
xXMADEXx Posted June 11, 2014 Share Posted June 11, 2014 Using the function fetchRemote. Link to comment
MIKI785 Posted June 11, 2014 Share Posted June 11, 2014 You can but since the web server the image is on is on different server than your MTA server you can't download it directly to the client. You have to use fetchRemote server-sided and then send the image data to client using triggerClientEvent. You then save these data to some file using fileCreate, fileWrite and fileClose and then you can use that to display the image. Link to comment
Moderators Citizen Posted June 11, 2014 Moderators Share Posted June 11, 2014 (edited) Just to let you know I'm on it, but that's pretty huge because I need to reimplement some basic gui functions (gui(Set/Get)Size, gui(Set/Get)Position etc). Because the only way to do it is to create a texture from image datas and draw it using dxDrawImage. So yeah check this topic later. EDIT: You then save these data to some file using fileCreate, fileWrite and fileClose and then you can use that to display the image. Ah yeah, didn't think about that ! Well I had the idea to store it as a file but thought I would need to reload the resource to get it on the client-side. But not needed at all using ur way. Gonna try it right now. Edited June 11, 2014 by Guest Link to comment
MIKI785 Posted June 11, 2014 Share Posted June 11, 2014 Just to let you know I'm on it, but that's pretty huge because I need to reimplement some basic gui functions (gui(Set/Get)Size, gui(Set/Get)Position etc). Because the only way to do it is to create a texture from image datas and draw it using dxDrawImage.So yeah check this topic later. That's not true, you can save the data to some file and then display it using guiCreateStaticImage, I do it that way myself. Link to comment
Moderators Citizen Posted June 11, 2014 Moderators Share Posted June 11, 2014 Yeah I didn't see your messages when I posted, because I had that tab already opened and it has no reply yet. (It didn't even warned me about new replies) Ok so here is my script based on the MIKI785 idea: Pre-requisites: As we can't create a static image without giving it an existing image, you need to download this image and put in in your resource folder: http://www.mediafire.com/view/ujgfu7wlt ... oading.png And add it to your meta.xml: <file src="imageloading.png" /> server: addEvent("onClientImageRequest", true) addEventHandler("onClientImageRequest", root, function onClientImageRequest( url, id ) fetchRemote( url, function ( datas, errno, player, url ) triggerClientEvent( player, "onClientGotImageResponse", player, url, datas, errno ) end, "", false, client, url ) end ) client: local _loadingImage = "imageloading.png" local _waitingForImage = {} local _imgsOnCache = {} function isUrl( str ) return string.sub(str, 1, 4) == "http" end function getExtension( str ) return string.match(str, "([^%.]+)$") end local _guiCreateStaticImage = guiCreateStaticImage function guiCreateStaticImage( x, y, width, height, path, relative, parent ) if not isUrl(path) then return _guiCreateStaticImage( x, y, width, height, path, relative, parent ) end local img = _guiCreateStaticImage( x, y, width, height, _loadingImage, relative, parent ) setRemoteImage(img, path) return img end local _guiStaticImageLoadImage = guiStaticImageLoadImage function guiStaticImageLoadImage( elem, path ) if not isUrl(path) then return _guiStaticImageLoadImage( elem, path ) end return setRemoteImage( elem, path ) end function generateTmpFilename( img, path ) local str = tostring(img).."_"..tostring(getTickCount()).."."..tostring(getExtension(path)) str = string.gsub(str, "userdata: ", "") return str end function setRemoteImage( img, path ) local currentPath = getElementData(img, "_url") if path ~= currentPath then setElementData(img, "_url", path) setElementData(img, "_tmpfile", generateTmpFilename(img, path)) table.insert(_waitingForImage, img) return triggerServerEvent("onClientImageRequest", localPlayer, path) end end addEvent("onClientGotImageResponse", true) function onClientGotImageResponse( path, datas, errno ) local img, index = nil, nil for k, simage in ipairs (_waitingForImage) do if getElementData(simage, "_url") == path then img = simage index = k break end end if img and isElement(img) then local filename = getElementData(img, "_tmpfile") imageWriteToFile( filename, datas ) _guiStaticImageLoadImage(img, filename) table.remove(_waitingForImage, index) end end addEventHandler("onClientGotImageResponse", root, onClientGotImageResponse) function imageWriteToFile( filename, datas ) local file = fileExists(filename) and fileOpen(filename) or fileCreate(filename) if file then fileWrite(file, datas) fileClose(file) table.insert(_imgsOnCache, filename) end end function cleanUp () for k, filename in ipairs(_imgsOnCache) do fileDelete( filename ) end end addEventHandler("onClientResourceStop", resourceRoot, cleanUp) So you can now use guiCreateStaticImage and guiStaticImageLoadImage with an url as path. Link to comment
mommytellme Posted June 12, 2014 Author Share Posted June 12, 2014 Error http://zapodaj.net/9f73ed432036f.png.html addEvent("onClientImageRequest", true) addEventHandler("onClientImageRequest", root, It is this line: function onClientImageRequest ( url, id ) fetchRemote( url, function ( datas, errno, player, url ) triggerClientEvent( player, "onClientGotImageResponse", player, url, datas, errno ) end, "", false, client, url ) end ) Link to comment
MIKI785 Posted June 12, 2014 Share Posted June 12, 2014 you don't name functions if used inside addEventHandler... It would be like this then: function ( url, id ) fetchRemote( url, function ( datas, errno, player, url ) triggerClientEvent( player, "onClientGotImageResponse", player, url, datas, errno ) end, "", false, client, url ) end ) Please use lua tags. Btw. the way you wrote it, everything on a new line is just horrible... but if you like it.. Link to comment
mommytellme Posted June 12, 2014 Author Share Posted June 12, 2014 Next error :< http://zapodaj.net/f2d1302dacab2.png.html Link to comment
Moderators Citizen Posted June 12, 2014 Moderators Share Posted June 12, 2014 you don't name functions if used inside addEventHandler... Omg ! I just wanted to make it all in one just before posting it, but forgot to make the handler function an anonymous one. *facepalm* Next error :<http://zapodaj.net/f2d1302dacab2.png.html You didn't apply the MIKI785's fix correctly This is what he mean't server: addEvent("onClientImageRequest", true) addEventHandler("onClientImageRequest", root, function ( url, id ) fetchRemote( url, function ( datas, errno, player, url ) triggerClientEvent( player, "onClientGotImageResponse", player, url, datas, errno ) end, "", false, client, url ) end ) 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