diff options
Diffstat (limited to 'builtin/client')
-rw-r--r-- | builtin/client/chatcommands.lua | 141 | ||||
-rw-r--r-- | builtin/client/cheats.lua | 58 | ||||
-rw-r--r-- | builtin/client/death_formspec.lua | 40 | ||||
-rw-r--r-- | builtin/client/init.lua | 5 | ||||
-rw-r--r-- | builtin/client/register.lua | 23 | ||||
-rw-r--r-- | builtin/client/util.lua | 56 |
6 files changed, 297 insertions, 26 deletions
diff --git a/builtin/client/chatcommands.lua b/builtin/client/chatcommands.lua index 0e8d4dd03..0da3dab1b 100644 --- a/builtin/client/chatcommands.lua +++ b/builtin/client/chatcommands.lua @@ -1,6 +1,5 @@ -- Minetest: builtin/client/chatcommands.lua - core.register_on_sending_chat_message(function(message) if message:sub(1,2) == ".." then return false @@ -42,34 +41,144 @@ core.register_on_sending_chat_message(function(message) return true end) -core.register_chatcommand("list_players", { - description = core.gettext("List online players"), +function core.run_server_chatcommand(cmd, param) + core.send_chat_message("/" .. cmd .. " " .. param) +end + +core.register_chatcommand("say", { + description = "Send raw text", + func = function(text) + core.send_chat_message(text) + return true + end, +}) + +core.register_chatcommand("teleport", { + params = "<X>,<Y>,<Z>", + description = "Teleport to coordinates.", func = function(param) - local player_names = core.get_player_names() - if not player_names then - return false, core.gettext("This command is disabled by server.") + local success, pos = core.parse_pos(param) + if success then + core.localplayer:set_pos(pos) + return true, "Teleporting to " .. core.pos_to_string(pos) end + return false, pos + end, +}) - local players = table.concat(player_names, ", ") - return true, core.gettext("Online players: ") .. players +core.register_chatcommand("wielded", { + description = "Print itemstring of wieleded item", + func = function() + return true, core.localplayer:get_wielded_item():get_name() end }) core.register_chatcommand("disconnect", { - description = core.gettext("Exit to main menu"), + description = "Exit to main menu", func = function(param) core.disconnect() end, }) -core.register_chatcommand("clear_chat_queue", { - description = core.gettext("Clear the out chat queue"), +core.register_chatcommand("players", { + description = "List online players", func = function(param) - core.clear_out_chat_queue() - return true, core.gettext("The out chat queue is now empty") + return true, "Online players: " .. table.concat(core.get_player_names(), ", ") + end +}) + +core.register_chatcommand("kill", { + description = "Kill yourself", + func = function() + core.send_damage(10000) end, }) -function core.run_server_chatcommand(cmd, param) - core.send_chat_message("/" .. cmd .. " " .. param) -end +core.register_chatcommand("set", { + params = "([-n] <name> <value>) | <name>", + description = "Set or read client configuration setting", + func = function(param) + local arg, setname, setvalue = string.match(param, "(-[n]) ([^ ]+) (.+)") + if arg and arg == "-n" and setname and setvalue then + core.settings:set(setname, setvalue) + return true, setname .. " = " .. setvalue + end + + setname, setvalue = string.match(param, "([^ ]+) (.+)") + if setname and setvalue then + if not core.settings:get(setname) then + return false, "Failed. Use '.set -n <name> <value>' to create a new setting." + end + core.settings:set(setname, setvalue) + return true, setname .. " = " .. setvalue + end + + setname = string.match(param, "([^ ]+)") + if setname then + setvalue = core.settings:get(setname) + if not setvalue then + setvalue = "<not set>" + end + return true, setname .. " = " .. setvalue + end + + return false, "Invalid parameters (see .help set)." + end, +}) + +core.register_chatcommand("place", { + params = "<X>,<Y>,<Z>", + description = "Place wielded item", + func = function(param) + local success, pos = core.parse_relative_pos(param) + if success then + core.place_node(pos) + return true, "Node placed at " .. core.pos_to_string(pos) + end + return false, pos + end, +}) + +core.register_chatcommand("dig", { + params = "<X>,<Y>,<Z>", + description = "Dig node", + func = function(param) + local success, pos = core.parse_relative_pos(param) + if success then + core.dig_node(pos) + return true, "Node at " .. core.pos_to_string(pos) .. " dug" + end + return false, pos + end, +}) + +core.register_chatcommand("setyaw", { + params = "<yaw>", + description = "Set your yaw", + func = function(param) + local yaw = tonumber(param) + if yaw then + core.localplayer:set_yaw(yaw) + return true + else + return false, "Invalid usage (See .help setyaw)" + end + end +}) + +core.register_chatcommand("setpitch", { + params = "<pitch>", + description = "Set your pitch", + func = function(param) + local pitch = tonumber(param) + if pitch then + core.localplayer:set_pitch(pitch) + return true + else + return false, "Invalid usage (See .help setpitch)" + end + end +}) + +core.register_list_command("xray", "Configure X-Ray", "xray_nodes") +core.register_list_command("search", "Configure NodeESP", "node_esp_nodes") diff --git a/builtin/client/cheats.lua b/builtin/client/cheats.lua new file mode 100644 index 000000000..1abc2c8ef --- /dev/null +++ b/builtin/client/cheats.lua @@ -0,0 +1,58 @@ +core.cheats = { + ["Combat"] = { + ["AntiKnockback"] = "antiknockback", + ["FastHit"] = "spamclick", + ["AttachmentFloat"] = "float_above_parent", + ["ThroughWalls"] = "dont_point_nodes", + ["AutoHit"] = "autohit", + }, + ["Movement"] = { + ["Freecam"] = "freecam", + ["AutoForward"] = "continuous_forward", + ["PitchMove"] = "pitch_move", + ["AutoJump"] = "autojump", + ["Jesus"] = "jesus", + ["NoSlow"] = "no_slow", + ["JetPack"] = "jetpack", + ["AntiSlip"] = "antislip", + }, + ["Render"] = { + ["Xray"] = "xray", + ["Fullbright"] = "fullbright", + ["HUDBypass"] = "hud_flags_bypass", + ["NoHurtCam"] = "no_hurt_cam", + ["BrightNight"] = "no_night", + ["Coords"] = "coords", + ["CheatHUD"] = "cheat_hud", + ["EntityESP"] = "enable_entity_esp", + ["EntityTracers"] = "enable_entity_tracers", + ["PlayerESP"] = "enable_player_esp", + ["PlayerTracers"] = "enable_player_tracers", + ["NodeESP"] = "enable_node_esp", + ["NodeTracers"] = "enable_node_tracers", + }, + ["World"] = { + ["FastDig"] = "fastdig", + ["FastPlace"] = "fastplace", + ["AutoDig"] = "autodig", + ["AutoPlace"] = "autoplace", + ["InstantBreak"] = "instant_break", + }, + ["Exploit"] = { + ["EntitySpeed"] = "entity_speed", + }, + ["Player"] = { + ["NoFallDamage"] = "prevent_natural_damage", + ["NoForceRotate"] = "no_force_rotate", + ["IncreasedRange"] = "increase_tool_range", + ["UnlimitedRange"] = "increase_tool_range_plus", + ["PointLiquids"] = "point_liquids", + ["PrivBypass"] = "priv_bypass", + ["AutoRespawn"] = "autorespawn", + }, +} + +function core.register_cheat(cheatname, category, func) + core.cheats[category] = core.cheats[category] or {} + core.cheats[category][cheatname] = func +end diff --git a/builtin/client/death_formspec.lua b/builtin/client/death_formspec.lua index e755ac5c1..7b8530440 100644 --- a/builtin/client/death_formspec.lua +++ b/builtin/client/death_formspec.lua @@ -1,16 +1,38 @@ --- CSM death formspec. Only used when clientside modding is enabled, otherwise --- handled by the engine. +local death_formspec = "" + .. "size[11,5.5]" + .. "bgcolor[#320000b4;true]" + .. "label[4.85,1.35;" .. "You died" .. "]" + .. "button_exit[2,3;3,0.5;btn_respawn;" .. "Respawn" .. "]" + .. "button_exit[6,3;3,0.5;btn_ghost_mode;" .. "Ghost Mode" .. "]" + .. "set_focus[btn_respawn;true]" core.register_on_death(function() - core.display_chat_message("You died.") - local formspec = "size[11,5.5]bgcolor[#320000b4;true]" .. - "label[4.85,1.35;" .. fgettext("You died") .. - "]button_exit[4,3;3,0.5;btn_respawn;".. fgettext("Respawn") .."]" - core.show_formspec("bultin:death", formspec) + core.display_chat_message("You died at " .. core.pos_to_string(vector.round(core.localplayer:get_pos())) .. ".") + if core.settings:get_bool("autorespawn") then + core.send_respawn() + else + core.show_formspec("__builtin__:death", death_formspec) + end end) core.register_on_formspec_input(function(formname, fields) - if formname == "bultin:death" then - core.send_respawn() + if formname == "__builtin__:death" then + if fields.btn_ghost_mode then + core.display_chat_message("You are in ghost mode. Use .respawn to Respawn.") + else + core.send_respawn() + end end end) + +core.register_chatcommand("respawn", { + description = "Respawn when in ghost mode", + func = function() + if core.localplayer:get_hp() == 0 then + core.send_respawn() + core.display_chat_message("Respawned.") + else + core.display_chat_message("You are not in ghost mode.") + end + end +}) diff --git a/builtin/client/init.lua b/builtin/client/init.lua index 9633a7c71..8c6512ec1 100644 --- a/builtin/client/init.lua +++ b/builtin/client/init.lua @@ -6,6 +6,9 @@ local commonpath = scriptpath.."common"..DIR_DELIM dofile(clientpath .. "register.lua") dofile(commonpath .. "after.lua") dofile(commonpath .. "chatcommands.lua") -dofile(clientpath .. "chatcommands.lua") dofile(commonpath .. "vector.lua") +dofile(clientpath .. "util.lua") +dofile(clientpath .. "chatcommands.lua") dofile(clientpath .. "death_formspec.lua") +dofile(clientpath .. "cheats.lua") + diff --git a/builtin/client/register.lua b/builtin/client/register.lua index 27a6b02d9..de5d89909 100644 --- a/builtin/client/register.lua +++ b/builtin/client/register.lua @@ -47,6 +47,26 @@ function core.run_callbacks(callbacks, mode, ...) return ret end +function core.override_item(name, redefinition) + if redefinition.name ~= nil then + error("Attempt to redefine name of "..name.." to "..dump(redefinition.name), 2) + end + if redefinition.type ~= nil then + error("Attempt to redefine type of "..name.." to "..dump(redefinition.type), 2) + end + local itemdef = core.get_item_def(name) + if not itemdef then + error("Attempt to override non-existent item "..name, 2) + end + local nodedef = core.get_node_def(name) + table.combine(itemdef, nodedef) + + for k, v in pairs(redefinition) do + rawset(itemdef, k, v) + end + core.register_item_raw(itemdef) +end + -- -- Callback registration -- @@ -82,3 +102,6 @@ core.registered_on_item_use, core.register_on_item_use = make_registration() core.registered_on_modchannel_message, core.register_on_modchannel_message = make_registration() core.registered_on_modchannel_signal, core.register_on_modchannel_signal = make_registration() core.registered_on_inventory_open, core.register_on_inventory_open = make_registration() +core.registered_on_recieve_physics_override, core.register_on_recieve_physics_override = make_registration() +core.registered_on_play_sound, core.register_on_play_sound = make_registration() +core.registered_on_spawn_particle, core.register_on_spawn_particle = make_registration() diff --git a/builtin/client/util.lua b/builtin/client/util.lua new file mode 100644 index 000000000..e85727436 --- /dev/null +++ b/builtin/client/util.lua @@ -0,0 +1,56 @@ +function core.parse_pos(param) + local p = {} + local playerpos = core.localplayer:get_pos() + p.x, p.y, p.z = string.match(param, "^([~|%d.-]+)[, ] *([~|%d.-]+)[, ] *([~|%d.-]+)$") + for k, v in pairs(p) do + if p[k] == "~" then + p[k] = playerpos[k] + else + p[k] = tonumber(v) + end + end + if p.x and p.y and p.z then + return true, vector.round(p) + end + return false, "Invalid position (" .. param .. ")" +end + +function core.parse_relative_pos(param) + local success, pos = core.parse_pos(param:gsub("~", "0")) + if success then pos = vector.round(vector.add(core.localplayer:get_pos(), pos)) end + return success, pos +end + +function core.find_item(item, mini, maxi) + for index, stack in ipairs(core.get_inventory("current_player").main) do + if (not mini or index >= mini) and (not maxi or index <= maxi) and stack:get_name() == item then + return index + end + end +end + +function core.switch_to_item(item) + local i = core.find_item(item) + if i then + core.localplayer:set_wield_index(i) + return true + else + return false + end +end + +function core.get_pointed_thing() + local pos = core.camera:get_pos() + local pos2 = vector.add(pos, vector.multiply(core.camera:get_look_dir(), 7)) + local player = core.localplayer + if not player then return end + local item = player:get_wielded_item() + if not item then return end + local def = core.get_item_def(item:get_name()) + local ray = core.raycast(pos, pos2, true, core.settings:get_bool("point_liquids") or def and def.liquids_pointable) + return ray and ray:next() +end + +function core.close_formspec(formname) + return core.show_formspec(formname, "") +end |