From ea88dde4be225d19c12bea4a581aa21f17237070 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Wed, 21 Oct 2020 18:51:57 +0200 Subject: Added Strip, AutoRefill, indexing for InventoryActions and Wield Index starts at 1 now --- src/script/lua_api/l_inventoryaction.cpp | 2 +- src/script/lua_api/l_localplayer.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/script/lua_api') diff --git a/src/script/lua_api/l_inventoryaction.cpp b/src/script/lua_api/l_inventoryaction.cpp index 516d6d3b2..f3037ba83 100644 --- a/src/script/lua_api/l_inventoryaction.cpp +++ b/src/script/lua_api/l_inventoryaction.cpp @@ -133,7 +133,7 @@ void LuaInventoryAction::readFullInventoryLocationInto(lua_State *L, InventoryLo loc->deSerialize(readParam(L, 2)); std::string l = readParam(L, 3); *list = l; - *index = luaL_checkinteger(L, 4); + *index = luaL_checkinteger(L, 4) - 1; } catch (SerializationError &) {} } diff --git a/src/script/lua_api/l_localplayer.cpp b/src/script/lua_api/l_localplayer.cpp index 8057802a4..e40dd7b37 100644 --- a/src/script/lua_api/l_localplayer.cpp +++ b/src/script/lua_api/l_localplayer.cpp @@ -116,7 +116,7 @@ int LuaLocalPlayer::l_get_wield_index(lua_State *L) { LocalPlayer *player = getobject(L, 1); - lua_pushinteger(L, player->getWieldIndex()); + lua_pushinteger(L, player->getWieldIndex() + 1); return 1; } @@ -124,7 +124,7 @@ int LuaLocalPlayer::l_get_wield_index(lua_State *L) int LuaLocalPlayer::l_set_wield_index(lua_State *L) { LocalPlayer *player = getobject(L, 1); - u32 index = luaL_checkinteger(L, 2); + u32 index = luaL_checkinteger(L, 2) - 1; player->setWieldIndex(index); g_game->processItemSelection(&g_game->runData.new_playeritem); -- cgit v1.2.3 From f1d9ac014efc6403e73223f36d3dbb7f5ed50236 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Wed, 4 Nov 2020 12:28:00 +0100 Subject: Moved Killaura to Lua; Added ForceField; Added Friendlist; Added ClientObjectRef:is_local_player(); Documented LocalPlayer:get_object() --- builtin/client/cheats/combat.lua | 22 +++++++++++++++++++++- builtin/client/cheats/init.lua | 1 + builtin/settingtypes.txt | 4 ++++ doc/client_lua_api.txt | 3 +++ src/client/game.cpp | 19 ------------------- src/client/game.h | 1 - src/defaultsettings.cpp | 2 ++ src/script/lua_api/l_clientobject.cpp | 9 +++++++++ src/script/lua_api/l_clientobject.h | 3 +++ 9 files changed, 43 insertions(+), 21 deletions(-) (limited to 'src/script/lua_api') diff --git a/builtin/client/cheats/combat.lua b/builtin/client/cheats/combat.lua index 1f9ba9a91..4904d8c52 100644 --- a/builtin/client/cheats/combat.lua +++ b/builtin/client/cheats/combat.lua @@ -4,13 +4,33 @@ local used_sneak = true local totem_move_action = InventoryAction("move") totem_move_action:to("current_player", "main", 9) +core.register_list_command("friend", "Configure Friend List (friends dont get attacked by Killaura or Forcefield)", "friendlist") + core.register_globalstep(function(dtime) local player = core.localplayer if not player then return end local control = player:get_control() local pointed = core.get_pointed_thing() local item = player:get_wielded_item():get_name() - if core.settings:get_bool("crystal_pvp") then + if core.settings:get_bool("killaura") or core.settings:get_bool("forcefield") and control.LMB then + local friendlist = core.settings:get("friendlist"):split(",") + for _, obj in ipairs(core.get_objects_inside_radius(player:get_pos(), 5)) do + local do_attack = true + if obj:is_local_player() then + do_attack = false + else + for _, friend in ipairs(friendlist) do + if obj:get_name() == friend or obj:get_nametag() == friend then + do_attack = false + break + end + end + end + if do_attack then + obj:punch() + end + end + elseif core.settings:get_bool("crystal_pvp") then if placed_crystal then if core.switch_to_item("mobs_mc:totem") then switched_to_totem = 5 diff --git a/builtin/client/cheats/init.lua b/builtin/client/cheats/init.lua index 6fd78b8b8..466ce4aee 100644 --- a/builtin/client/cheats/init.lua +++ b/builtin/client/cheats/init.lua @@ -1,6 +1,7 @@ core.cheats = { ["Combat"] = { ["Killaura"] = "killaura", + ["Forcefield"] = "forcefield", ["AntiKnockback"] = "antiknockback", ["FastHit"] = "spamclick", ["AttachmentFloat"] = "float_above_parent", diff --git a/builtin/settingtypes.txt b/builtin/settingtypes.txt index 4dcfd1092..ec05c6196 100644 --- a/builtin/settingtypes.txt +++ b/builtin/settingtypes.txt @@ -2314,3 +2314,7 @@ chat_color (Chat Color) string rainbow use_chat_color (ColoredChat) bool false chat_reverse (ReversedChat) bool false + +forcefield (Forcefield) bool false + +friendlist (Killaura / Forcefield Friendlist) string diff --git a/doc/client_lua_api.txt b/doc/client_lua_api.txt index 2daac87fe..c332ca4c3 100644 --- a/doc/client_lua_api.txt +++ b/doc/client_lua_api.txt @@ -1296,6 +1296,8 @@ Methods: * change a value of a previously added HUD element * element `stat` values: `position`, `name`, `scale`, `text`, `number`, `item`, `dir` * Returns `true` on success, otherwise returns `nil` +* `get_object()` + * Returns the ClientObjectRef for the player ### Settings An interface to read config files in the format of `minetest.conf`. @@ -1336,6 +1338,7 @@ This is basically a reference to a C++ `GenericCAO`. * `get_acceleration()`: returns the acceleration, a vector * `get_rotation()`: returns the rotation, a vector (radians) * `is_player()`: returns true if the object is a player +* `is_local_player()`: returns true if the object is the local player * `get_attach()`: returns parent or nil if it isn't attached. * `get_nametag()`: returns the nametag (string) * `get_item_textures()`: returns the textures diff --git a/src/client/game.cpp b/src/client/game.cpp index d8800d9ea..491d55a34 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -2453,9 +2453,6 @@ PointedThing Game::updatePointedThing( ClientMap &map = env.getClientMap(); const NodeDefManager *nodedef = map.getNodeDefManager(); - if (g_settings->getBool("killaura")) - handleKillaura(shootline.start, shootline.getLength()); - runData.selected_object = NULL; hud->pointing_at_object = false; RaycastState s(shootline, look_for_object, liquids_pointable, ! g_settings->getBool("dont_point_nodes")); @@ -2532,22 +2529,6 @@ PointedThing Game::updatePointedThing( return result; } -void Game::handleKillaura(v3f origin, f32 max_d) -{ - ClientEnvironment &env = client->getEnv(); - std::vector allObjects; - env.getActiveObjects(origin, max_d, allObjects); - for (const auto &allObject : allObjects) { - ClientActiveObject *obj = allObject.obj; - s16 id = obj->getId(); - aabb3f selection_box; - if (! obj->getSelectionBox(&selection_box)) - continue; - PointedThing pointed(id, v3f(0,0,0), v3s16(0,0,0), 0); - client->interact(INTERACT_START_DIGGING, pointed); - } -} - void Game::handlePointingAtNothing(const ItemStack &playerItem) { infostream << "Right Clicked in Air" << std::endl; diff --git a/src/client/game.h b/src/client/game.h index b8efa3a73..51accc679 100644 --- a/src/client/game.h +++ b/src/client/game.h @@ -773,7 +773,6 @@ public: PointedThing updatePointedThing( const core::line3d &shootline, bool liquids_pointable, bool look_for_object, const v3s16 &camera_offset); - void handleKillaura(v3f origin, f32 max_d); void handlePointingAtNothing(const ItemStack &playerItem); void handlePointingAtNode(const PointedThing &pointed, const ItemStack &selected_item, const ItemStack &hand_item, f32 dtime); diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index e3332b14f..bcdd80074 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -117,6 +117,8 @@ void set_default_settings(Settings *settings) settings->setDefault("chat_color", "rainbow"); settings->setDefault("use_chat_color", "false"); settings->setDefault("chat_reverse", "false"); + settings->setDefault("forcefield", "false"); + settings->setDefault("friendlist", ""); // Keymap settings->setDefault("remote_port", "30000"); diff --git a/src/script/lua_api/l_clientobject.cpp b/src/script/lua_api/l_clientobject.cpp index 90f0bcd15..d88b538a1 100644 --- a/src/script/lua_api/l_clientobject.cpp +++ b/src/script/lua_api/l_clientobject.cpp @@ -87,6 +87,14 @@ int ClientObjectRef::l_is_player(lua_State *L) return 1; } +int ClientObjectRef::l_is_local_player(lua_State *L) +{ + ClientObjectRef *ref = checkobject(L, 1); + GenericCAO *gcao = get_generic_cao(ref, L); + lua_pushboolean(L, gcao->isLocalPlayer()); + return 1; +} + int ClientObjectRef::l_get_name(lua_State *L) { ClientObjectRef *ref = checkobject(L, 1); @@ -210,6 +218,7 @@ luaL_Reg ClientObjectRef::methods[] = {luamethod(ClientObjectRef, get_pos), luamethod(ClientObjectRef, get_acceleration), luamethod(ClientObjectRef, get_rotation), luamethod(ClientObjectRef, is_player), + luamethod(ClientObjectRef, is_local_player), luamethod(ClientObjectRef, get_name), luamethod(ClientObjectRef, get_attach), luamethod(ClientObjectRef, get_nametag), diff --git a/src/script/lua_api/l_clientobject.h b/src/script/lua_api/l_clientobject.h index 88a6956bc..521591444 100644 --- a/src/script/lua_api/l_clientobject.h +++ b/src/script/lua_api/l_clientobject.h @@ -60,6 +60,9 @@ private: // is_player(self) static int l_is_player(lua_State *L); + + // is_local_player(self) + static int l_is_local_player(lua_State *L); // get_name(self) static int l_get_name(lua_State *L); -- cgit v1.2.3