Jump to content

Question Download


boro

Recommended Posts

Hi i have idea for start downloading players mod when is player spawned is it possible ?

Example

function downloadOnSpawn ( ) 
    engineImportTXD(engineLoadTXD("pcj600.txd"), 461) 
    engineReplaceModel(engineLoadDFF("pcj600.dff", 0), 461) 
end 
addEventHandler ( "onClientPlayerSpawn", getLocalPlayer(), downloadOnSpawn  ) 

Link to comment

I try this but it dont work alpha mod dont are loaded

local screenWidth,screenHeight = guiGetScreenSize() 
local downloadFiles = { 
    { "mods/alpha.txd" }, 
    { "mods/alpha.dff" }, 
} 
  
 function downloadState() 
 dxDrawText("Downloading... (0/2)",screenWidth,screenHeight,screenWidth,screenHeight,tocolor(255,255,255,255),1,"bankgothic") 
 end 
 addEventHandler("onClientRender",root,downloadState) 
  
for _, downFile in pairs( downloadFiles ) do 
    downloadFile ( downFile[1] ) 
    downloadState() 
end 
  
addEventHandler ( "onClientFileDownloadComplete", resourceRoot, 
    function ( file, success ) 
        if ( success ) then 
            -- alpha 
            if ( file == "mods/alpha.txd" and fileExists("mods/alpha.dff") ) or ( file == "mods/alpha.dff" and fileExists("mods/alpha.txd") ) then 
                local txdalp = engineLoadTXD ( "mods/alpha.txd" ) 
                local dffalp = engineLoadDFF ( "mods/alpha.dff", 602 ) 
                engineImportTXD ( txdalp, 602 ) 
                engineReplaceModel ( dffalp, 602 ) 
                removeEventHandler("onClientRender",root,downloadState) 
           end     
       end 
  end 
) 
  
function checkIfPlayerAlreadyHasDownloaded() 
if ( fileExists("mods/alpha.dff") and fileExists("mods/alpha.txd")) then 
outputChatBox("Loading carmods...") 
                local txdalp = engineLoadTXD ( "mods/alpha.txd" ) 
                local dffalp = engineLoadDFF ( "mods/alpha.dff", 602 ) 
                engineImportTXD ( txdalp, 602 ) 
                engineReplaceModel ( dffalp, 602 ) 
                else 
                outputChatBox("client has no carmods, and has triggered the download!") 
                for _, downFile in pairs( downloadFiles ) do 
    downloadFile ( downFile[1] ) 
    downloadState() 
end 
end 
end 
addEventHandler("onClientPlayerSpawn",root,checkIfPlayerAlreadyHasDownloaded) 

Link to comment

Hm i check it but all still dont work for me

and this script is good idea ? dont make it some lag on server ?

function downloadOnSpawn ( ) 
    engineImportTXD(engineLoadTXD("pcj600.txd"), 461) 
    engineReplaceModel(engineLoadDFF("pcj600.dff", 0), 461) 
end 
addEventHandler ( "onClientPlayerSpawn", getLocalPlayer(), downloadOnSpawn  ) 

I download mods only if is player spawn

Link to comment

Ok i check your old posts

And i have now this script but still dont work, in meta i have set download to false and old downloaded mod is deleted and still nothing

what is bad now ?

local screenWidth,screenHeight = guiGetScreenSize() 
local downloadFiles = { "mods/alpha.txd", "mods/alpha.dff" } 
      
function downloadState() 
    dxDrawText("Downloading... (0/2)",screenWidth,screenHeight,screenWidth,screenHeight,tocolor(255,255,255,255),1,"bankgothic") 
end 
  
--[[ This is handled in onClientPlayerSpawn 
for _, downFile in pairs( downloadFiles ) do 
    downloadFile ( downFile ) 
    downloadState() 
end ]] 
      
addEventHandler ( "onClientFileDownloadComplete", root, function ( file, success ) 
    if ( success and fileExists ( "mods/alpha.dff" ) and fileExists ( "mods/alpha.txd" ) ) then 
        local txdalp = engineLoadTXD ( "mods/alpha.txd" ) 
        local dffalp = engineLoadDFF ( "mods/alpha.dff", 602 ) 
        engineImportTXD ( txdalp, 602 ) 
        engineReplaceModel ( dffalp, 602 ) 
        removeEventHandler("onClientRender",root,downloadState) 
    end     
end ) 
      
function checkIfPlayerAlreadyHasDownloaded() 
    if ( fileExists("mods/alpha.dff") and fileExists("mods/alpha.txd")) then 
        outputChatBox("Loading carmods...") 
        local txdalp = engineLoadTXD ( "mods/alpha.txd" ) 
        local dffalp = engineLoadDFF ( "mods/alpha.dff", 602 ) 
        engineImportTXD ( txdalp, 602 ) 
        engineReplaceModel ( dffalp, 602 ) 
    else 
        outputChatBox("client has no carmods, and has triggered the download!") 
        for _, downFile in pairs( downloadFiles ) do 
            downloadFile ( downFile ) 
            addEventHandler ( "onClientRender", root, downloadState ) 
        end 
    end 
end 
addEventHandler("onClientPlayerSpawn", localPlayer, checkIfPlayerAlreadyHasDownloaded ) 

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