improving the cheat commands
This commit is contained in:
@@ -171,6 +171,39 @@ function console.log(...)
|
||||
log_element:paste(text)
|
||||
end
|
||||
|
||||
function console.add_command(scheme, description, handler, is_cheat)
|
||||
console.__add_command(scheme, description, handler)
|
||||
if not is_cheat then return end
|
||||
|
||||
local name = string.match(scheme, "^(%S+)")
|
||||
if not name then
|
||||
error("Incorrect command syntax, command name not found")
|
||||
end
|
||||
|
||||
table.insert_unique(console.cheats, name)
|
||||
end
|
||||
|
||||
function console.is_cheat(name)
|
||||
if not table.has(console.get_commands_list(), name) then
|
||||
error(string.format("command \"%s\" not found", name))
|
||||
end
|
||||
|
||||
return table.has(console.cheats, name)
|
||||
end
|
||||
|
||||
function console.set_cheat(name, status)
|
||||
local is_cheat = console.is_cheat(name)
|
||||
if status and not is_cheat then
|
||||
table.insert(console.cheats, name)
|
||||
return true
|
||||
elseif not status and is_cheat then
|
||||
table.remove_value(console.cheats, name)
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
function console.chat(...)
|
||||
console.log(...)
|
||||
events.emit("core:chat", ...)
|
||||
|
||||
Reference in New Issue
Block a user