WASSIm. Posted January 14, 2014 Share Posted January 14, 2014 hi guys. i have problem. and this problem make me suck and i don't know what is this problem Server triggered client side event onClientCheckDownload, but event is not added clientside Server addEventHandler("onResourceStart", resourceRoot, function() local meta = xmlLoadFile ("mods.xml") for i,node in ipairs(xmlNodeGetChildren(meta)) do local theModel = xmlNodeGetAttribute(node, "theModel") local modelID = xmlNodeGetAttribute(node, "modelID") local theFile = fileOpen(theModel) if (theFile) then triggerClientEvent(root, "onClientCheckDownload", root, theFile, theModel, modelID) else outputChatBox(modelID.." This file do not exist") end end end) Client addEvent("onClientCheckDownload", true) addEventHandler("onClientCheckDownload", root, function(theFile, theModel, modelID) end) Link to comment
Baseplate Posted January 14, 2014 Share Posted January 14, 2014 You sure you've added the client file as "client" on meta? Link to comment
Moderators IIYAMA Posted January 14, 2014 Moderators Share Posted January 14, 2014 Cause the server is already sending data while the client hasn't loaded yet. (loaded the client.lua file) Link to comment
Baseplate Posted January 14, 2014 Share Posted January 14, 2014 I think putting client.lua first before the server.lua in the meta.xml can solve the problem Link to comment
WASSIm. Posted January 14, 2014 Author Share Posted January 14, 2014 i try it but same problem Link to comment
Moderators IIYAMA Posted January 14, 2014 Moderators Share Posted January 14, 2014 I think putting client.lua first before the server.lua in the meta.xml can solve the problem NO, cause the server ALWAYS start first. You have to send a message from clientside > onClientResourceStart < to the server and send the data back to the client. Link to comment
WASSIm. Posted January 14, 2014 Author Share Posted January 14, 2014 thanks its working but i have other problem. its put in chat nil addEvent("onClientCheckDownload", true) addEventHandler("onClientCheckDownload", root, function(theFile, theModel, modelID) outputChatBox(fileGetSize(theFile)) end) Link to comment
Moderators IIYAMA Posted January 14, 2014 Moderators Share Posted January 14, 2014 because you can't past files with this function. Only data. Tables, strings, numbers, userdata etc. You have to read the information from it first or read the whole file. And then recreate it at clientside, with the new data. Link to comment
WASSIm. Posted January 14, 2014 Author Share Posted January 14, 2014 now its working fine but make lag Client addEventHandler("onClientResourceStart", resourceRoot, function( ) triggerServerEvent("onPlayerPreDownload", localPlayer) end) addEvent("onClientPlayerPreDownload", true) addEventHandler("onClientPlayerPreDownload", root, function(data, size, theModel, modelID) local theFile = fileOpen(theModel) if (fileExists(theModel)) and (fileGetSize(theFile) == size) then fileClose(theFile) if (string.find(theModel, ".txd")) then local txd = engineLoadTXD(theModel, true) if (txd) then engineImportTXD(txd, modelID) end elseif (string.find(theModel, ".dff")) then local dff = engineLoadDFF(theModel, modelID) if (dff) then engineReplaceModel(dff, modelID) end end else local newFile = fileCreate(theModel) if (newFile) then local downloadSize = fileWrite(newFile, data) outputChatBox(theModel.." Started Download") triggerEvent("onClientPlayerDownload", localPlayer, newFile) end end end) Server addEvent("onPlayerPreDownload", true) addEventHandler("onPlayerPreDownload", root, function() local meta = xmlLoadFile ("mods.xml") for i,node in ipairs(xmlNodeGetChildren(meta)) do local theModel = xmlNodeGetAttribute(node, "theModel") local modelID = xmlNodeGetAttribute(node, "modelID") local theFile = fileOpen(theModel) if (theFile) then local size = fileGetSize(theFile) local data = fileRead(theFile, size) triggerClientEvent(source, "onClientPlayerPreDownload", source, data, size, theModel, modelID) fileClose(theFile) else outputChatBox(modelID.." This file do not exist") end end end) Link to comment
Moderators IIYAMA Posted January 14, 2014 Moderators Share Posted January 14, 2014 Because you are sending a lot of trigger events, when you can just do it with one triggerLatentClientEvent, a table and a loop. Link to comment
WASSIm. Posted January 14, 2014 Author Share Posted January 14, 2014 (edited) ok i change to this but nothing happen triggerLatentClientEvent(source, "onClientCheckDownload", 50000, false, source, data, size, theModel, modelID) Edited January 14, 2014 by Guest Link to comment
Moderators IIYAMA Posted January 14, 2014 Moderators Share Posted January 14, 2014 where is your table? Link to comment
Moderators IIYAMA Posted January 14, 2014 Moderators Share Posted January 14, 2014 To save your stuff so it can be send with 1 triggerLatentClientEvent Link to comment
WASSIm. Posted January 14, 2014 Author Share Posted January 14, 2014 finally working thanks Link to comment
Moderators IIYAMA Posted January 14, 2014 Moderators Share Posted January 14, 2014 local newTable = {} local size = fileGetSize(theFile) local data = fileRead(theFile, size) -- loop local theModel = xmlNodeGetAttribute(node, "theModel") local modelID = xmlNodeGetAttribute(node, "modelID") newTable[#newTable+1]= {theModel,modelID} --- -- in function -- triggerLatentClientEvent(source, "onClientPlayerPreDownload", source, newTable,size,data) Something like this, except most of those things should be out of the function, because it only have to be done one time. Also you should first pre communicate with the server before you are sending this data over. Because now you are still sending everything to the client, since that is the thing you want to prevent. 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