Loading

添加自动下载功能

可以使用此功能为客户端补充必要的文件,例如声音文件、模型文件、等
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] == '\n') {
			buffer[--len] = '\0'
		}
		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] == '\n') {
			buffer[--len] = '\0'
		}
		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"
posted @ 2018-09-01 09:04  纯白、色  阅读(426)  评论(0编辑  收藏  举报