添加自动下载功能

Posted jkcx

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了添加自动下载功能相关的知识,希望对你有一定的参考价值。

可以使用此功能为客户端补充必要的文件,例如声音文件、模型文件、等
autotabledownloader.sp

#include <sourcemod>
#include <sdktools>
static String:DownloadPath[64]
public Plugin:myinfo = {
    name = "Auto Table Downloader",
    author = "Master(D)",
    description = "Auto Table Downloader",
    version = "1.1.1",
    url = ""
}
public Action:Command_CheakDownloadTables(Client,Args) {  
    PrintToConsole(Client,"Cheaking Download Table...")
    new Handle:fileh = OpenFile(DownloadPath, "r")
    new String:buffer[256]
    while (ReadFileLine(fileh, buffer, sizeof(buffer))) {
        new len = strlen(buffer)
        if (buffer[len-1] == ‘
‘) {
            buffer[--len] = ‘‘
        }
        if (FileExists(buffer)) {
            PrintToConsole(Client,"Download: %s",buffer)
        } else {
            PrintToConsole(Client,"Ignore: %s",buffer)
        }
        if (IsEndOfFile(fileh)) {
            break
        }
    }
    return Plugin_Handled   
}
public OnMapStart(){
    BuildPath(Path_SM, DownloadPath, 64, "configs/download.txt")
    if(FileExists(DownloadPath) == false) SetFailState("[SM] ERROR: Missing file ‘%s‘", DownloadPath)
    new Handle:fileh = OpenFile(DownloadPath, "r")
    new String:buffer[256]
    while (ReadFileLine(fileh, buffer, sizeof(buffer))) {
        new len = strlen(buffer)
        if (buffer[len-1] == ‘
‘) {
            buffer[--len] = ‘‘
        }
        if (FileExists(buffer)){
            AddFileToDownloadsTable(buffer)
        }
        if (IsEndOfFile(fileh)) {
            break;
        }
    }
}
public OnPluginStart() {
        RegAdminCmd("sm_dlcheck", Command_CheakDownloadTables, ADMFLAG_SLAY, "<Name> <Id> - Checks download.txt")
        CreateConVar("dlversion", "1.1.1", "auto table downloader version",FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_UNLOGGED|FCVAR_DONTRECORD|FCVAR_REPLICATED|FCVAR_NOTIFY)

}

此外,需要在服务端添加需要检测下载的列表文件
游戏目录/left4dead2/addons/sourcemod/config/download.txt





Example Sounds:
Sound/masters_opening.mp3
Sound/consnd/city.mp3

Example Models:
Models/Player/headcrab.mdl
Models/Player/Headcrab.dx80.vtx
Models/Player/Headcrab.sw.vtx
Models/Player/Headcrab.dx90.vtx
Models/Player/headcrab.vvd
Models/Player/Headcrab.phy

///////////////////////////////////////////////////////////////////////////////////

        Remember To Remove All Of The Content Of This Page

///////////////////////////////////////////////////////////////////////////////////

最后,客户端需要设置为允许下载的类型,才会自动下载

cl_allowdownload 1
cl_downloadfilter all
其他选项还有:
all, none, nosounds

下载服务端与游戏服务器分离的方法:
服务端通过设置 sv_downloadurl 指定到可下载的游戏目录,来实现下载与服务器分离。例如:

sv_downloadurl "http://d.l4dol.com/left4dead2_v2121/left4dead2"



以上是关于添加自动下载功能的主要内容,如果未能解决你的问题,请参考以下文章

从零开始配置vim(27)——代码片段

SQL Prompt7.2下载及破解教程

Java itext为pdf 文件添加水印核心功能代码片段

如何将按钮功能添加到片段中

如何在Sublime Text中添加代码片段

在片段中实现对话框时,必须在添加内容之前请求窗口功能