Jump to content

triggered client event


WASSIm.

Recommended Posts

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
  • Moderators
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
  • Moderators

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

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

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