* command /chost to allow host custom maps with GHost f6a2049502 (commitcomment-7207326)

* add help for /host and /chost
This commit is contained in:
HarpyWar 2014-08-02 19:28:33 +04:00
parent f4fff62f82
commit 137b5cc7a5
5 changed files with 89 additions and 4 deletions

View file

@ -600,7 +600,7 @@ Syntax for operator/admin:
/icon l[ist]
Display availaible icons in server stash that can be assigned to users
%language /lang
%language lang
--------------------------------------------------------
/lang [code]
Set your language to get another translation:
@ -618,3 +618,20 @@ Syntax for operator/admin:
Display record statistics for user
/quiz stats
Display Top records
%host
--------------------------------------------------------
/host <type> <mode> <game name>
Create a ladder DotA map using Host Bot
Available types: 5x5/3x3
Available modes: ap/cm/rd/sd/ar/tt/aptb/rdtb/artb/sdtb/tttb
%chost
--------------------------------------------------------
/chost <map code> <game name>
Create a custom map from the list using Host Bot
Available maps:

View file

@ -15,7 +15,7 @@
--- USER -> PVPGN -> GHOST ---
------------------------------
-- /host [mode] [type] [name]
-- /host [mode] [type] [gamename]
function command_host(account, text)
if not config.ghost or not account.clienttag == CLIENTTAG_WAR3XP then return 1 end
@ -45,6 +45,66 @@ function command_host(account, text)
return 0
end
gh_maplist = {}
-- /chost [code] [gamename]
function command_chost(account, text)
if not config.ghost or not account.clienttag == CLIENTTAG_WAR3XP then return 1 end
local filename = gh_directory() .. "/maplist.txt"
-- load maps from the file
file_load(filename, file_load_dictionary_callback,
function(a,b)
-- split second value to get name and filename
local mapname,mapfile = string.split(b,"|")
table.insert(gh_maplist, { code = a, name = mapname, filename = mapfile })
end)
local args = split_command(text, 2)
if not args[1] or not args[2] then
api.describe_command(account.name, args[0])
-- send user each map on a new line
for i,map in pairs(gh_maplist) do
api.message_send_text(account.name, message_type_info, string.format("%s = %s", map.code, map.name) )
end
return -1
end
-- find map by code
local mapfile = nil
for i,map in pairs(gh_maplist) do
if (args[1] == map.code) then mapfile = map.filename end
end
if not mapfile then
api.message_send_text(account.name, message_type_info, localize(account.name, "Invalid map code.") )
return -1
end
if gh_get_userbot(account.name) then
local gamename = gh_get_usergame(account.name)
local game = game_get_by_name(gamename, account.clienttag, game_type_all)
if next(game) then
api.message_send_text(account.name, message_type_info, localize("You already host a game \"{}\". Use /unhost to destroy it.", gamename))
return -1
else
-- if game doesn't exist then remove mapped bot for user
gh_del_userbot(account.name)
end
end
-- get bot by ping
local botname = gh_select_bot(account.name)
-- redirect message to bot
message_send_ghost(botname, string.format("/pvpgn chost %s %s %s", account.name, mapfile, args[2]) )
return 0
end
-- /unhost
function command_unhost(account, text)
if not config.ghost or not account.clienttag == CLIENTTAG_WAR3XP then return 1 end

View file

@ -39,7 +39,7 @@ function command_ghost(account, text)
elseif (cmd == "gameresult") then
gh_callback_gameresult(args[2], args[3], args[4])
elseif (cmd == "host") then
elseif (cmd == "host" or cmd == "chost") then
gh_callback_host(args[3], account.name, args[4])
elseif (cmd == "unhost") then
gh_callback_unhost(args[3], args[4])

6
lua/ghost/maplist.txt Normal file
View file

@ -0,0 +1,6 @@
**************************************************
Custom maps that can be hosted using /chost
**************************************************
DOTA = DotA|DotA v6.80c.w3x
MW = Mirana Wars Final|Mirana Wars Final.w3x

View file

@ -19,6 +19,7 @@ local lua_command_table = {
["/ghost"] = command_ghost,
["/host"] = command_host,
["/chost"] = command_chost,
["/unhost"] = command_unhost,
["/ping"] = command_ping, ["/p"] = command_ping,
["/swap"] = command_swap,
@ -62,8 +63,9 @@ end
-- Executes before executing any command
-- "return 0" stay with flood protection
-- "return 1" allow ignore flood protection
-- "return -1" will prevent next execution silently
-- "return -1" will prevent next command execution silently
function handle_command_before(account, text)
-- special users
for k,username in pairs(config.flood_immunity_users) do