mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-30 20:41:41 +09:00
Fixed bugs with /chelp
This commit is contained in:
@@ -67,7 +67,7 @@ Commands.add_parse('integer',function(input,player,reject)
|
|||||||
if not number then
|
if not number then
|
||||||
return reject{'expcore-commands.reject-number'}
|
return reject{'expcore-commands.reject-number'}
|
||||||
else
|
else
|
||||||
return number:floor()
|
return math.floor(number)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ kill-already-dead=You are already dead.
|
|||||||
admin-chat-format=[Admin Chat] [color=__3__]__1__: __2__
|
admin-chat-format=[Admin Chat] [color=__3__]__1__: __2__
|
||||||
tp-no-position-found=No position to teleport to was found, please try again later.
|
tp-no-position-found=No position to teleport to was found, please try again later.
|
||||||
tp-to-self=Player can not be teleported to themselves.
|
tp-to-self=Player can not be teleported to themselves.
|
||||||
chelp-title=Help results for __1__ page __2__ of __3__
|
chelp-title=Help results for "__1__":
|
||||||
chelp-format=/__1__ __2__ - __3__
|
chelp-footer=(__1__ results found; page __2__ of __3__)
|
||||||
|
chelp-format=/__1__ __2__ - __3__ __4__
|
||||||
|
chelp-alias=Alias: __1__
|
||||||
chelp-out-of-range=__1__ is an invalid page number.
|
chelp-out-of-range=__1__ is an invalid page number.
|
||||||
@@ -3,6 +3,8 @@ kill-already-dead=You are already dead.
|
|||||||
admin-chat-format=[Admin Chat] [color=__3__]__1__: __2__
|
admin-chat-format=[Admin Chat] [color=__3__]__1__: __2__
|
||||||
tp-no-position-found=No position to teleport to was found, please try again later.
|
tp-no-position-found=No position to teleport to was found, please try again later.
|
||||||
tp-to-self=Player can not be teleported to themselves.
|
tp-to-self=Player can not be teleported to themselves.
|
||||||
chelp-title=Help results for __1__ page __2__ of __3__
|
chelp-title=Help results for "__1__":
|
||||||
chelp-format=/__1__ __2__ - __3__
|
chelp-footer=(__1__ results found; page __2__ of __3__)
|
||||||
|
chelp-format=/__1__ __2__ - __3__ __4__
|
||||||
|
chelp-alias=Alias: __1__
|
||||||
chelp-out-of-range=__1__ is an invalid page number.
|
chelp-out-of-range=__1__ is an invalid page number.
|
||||||
@@ -10,50 +10,64 @@ Global.register(search_cache,function(tbl)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
Commands.new_command('chelp','Searches for a keyword in all commands you are allowed to use.')
|
Commands.new_command('chelp','Searches for a keyword in all commands you are allowed to use.')
|
||||||
:add_param('keyword',false) -- the keyword that will be looked for
|
:add_param('keyword',true) -- the keyword that will be looked for
|
||||||
:add_param('page',true,'integer') -- the keyword that will be looked for
|
:add_param('page',true,'integer') -- the keyword that will be looked for
|
||||||
:add_defaults{page=1}
|
:add_defaults{keyword='',page=1}
|
||||||
:register(function(player,keyword,page,raw)
|
:register(function(player,keyword,page,raw)
|
||||||
|
-- if keyword is a number then treat it as page number
|
||||||
|
if tonumber(keyword) then
|
||||||
|
page = math.floor(tonumber(keyword))
|
||||||
|
keyword = ''
|
||||||
|
end
|
||||||
-- gets a value for pages, might have result in cache
|
-- gets a value for pages, might have result in cache
|
||||||
local pages
|
local pages
|
||||||
|
local found = 0
|
||||||
if search_cache[player.index] and search_cache[player.index].keyword == keyword:lower() then
|
if search_cache[player.index] and search_cache[player.index].keyword == keyword:lower() then
|
||||||
pages = search_cache[player.index].pages
|
pages = search_cache[player.index].pages
|
||||||
|
found = search_cache[player.index].found
|
||||||
else
|
else
|
||||||
pages = {{}}
|
pages = {{}}
|
||||||
local current_page = 1
|
local current_page = 1
|
||||||
local page_count = 0
|
local page_count = 0
|
||||||
|
local commands = Commands.search(keyword,player)
|
||||||
-- loops other all commands returned by search, includes game commands
|
-- loops other all commands returned by search, includes game commands
|
||||||
for _,command_data in pairs(Commands.search(keyword,player)) do
|
for _,command_data in pairs(commands) do
|
||||||
-- if the number of results if greater than the number already added then it moves onto a new page
|
-- if the number of results if greater than the number already added then it moves onto a new page
|
||||||
if page_count > results_per_page then
|
if page_count >= results_per_page then
|
||||||
page_count = 0
|
page_count = 0
|
||||||
current_page = current_page + 1
|
current_page = current_page + 1
|
||||||
table.insert(pages,{})
|
table.insert(pages,{})
|
||||||
end
|
end
|
||||||
-- adds the new command to the page
|
-- adds the new command to the page
|
||||||
page_count = page_count + 1
|
page_count = page_count + 1
|
||||||
|
found = found + 1
|
||||||
|
local alias_format = #command_data.aliases > 0 and {'exp-commands.chelp-alias',table.concat(command_data.aliases,', ')} or ''
|
||||||
table.insert(pages[current_page],{
|
table.insert(pages[current_page],{
|
||||||
'exp-commands.chelp-format',
|
'exp-commands.chelp-format',
|
||||||
command_data.name,
|
command_data.name,
|
||||||
command_data.description,
|
command_data.description,
|
||||||
command_data.help,
|
command_data.help,
|
||||||
command_data.aliases:concat(', ')
|
alias_format
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
-- adds the result to the cache
|
-- adds the result to the cache
|
||||||
search_cache[player.index] = {
|
search_cache[player.index] = {
|
||||||
keyword=keyword:lower(),
|
keyword=keyword:lower(),
|
||||||
pages=pages
|
pages=pages,
|
||||||
|
found=found
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
-- print the requested page
|
-- print the requested page
|
||||||
Commands.print{'exp-commands.chelp-title',keyword,page,#pages}
|
keyword = keyword == '' and '<all>' or keyword
|
||||||
|
Commands.print({'exp-commands.chelp-title',keyword},'cyan')
|
||||||
if pages[page] then
|
if pages[page] then
|
||||||
for _,command in pairs(pages[page]) do
|
for _,command in pairs(pages[page]) do
|
||||||
Commands.print(command)
|
Commands.print(command)
|
||||||
end
|
end
|
||||||
|
Commands.print({'exp-commands.chelp-footer',found,page,#pages},'cyan')
|
||||||
else
|
else
|
||||||
Commands.print{'exp-commands.chelp-out-of-range',page}
|
Commands.print({'exp-commands.chelp-footer',found,page,#pages},'cyan')
|
||||||
|
return Commands.error{'exp-commands.chelp-out-of-range',page}
|
||||||
end
|
end
|
||||||
-- blocks command complete message
|
-- blocks command complete message
|
||||||
return Commands.success
|
return Commands.success
|
||||||
|
|||||||
Reference in New Issue
Block a user