Moved Killaura to Lua; Added ForceField; Added Friendlist; Added ClientObjectRef:is_local_player(); Documented LocalPlayer:get_object()

This commit is contained in:
Elias Fleckenstein 2020-11-04 12:28:00 +01:00
parent 06b72069d8
commit f1d9ac014e
9 changed files with 43 additions and 21 deletions

View File

@ -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

View File

@ -1,6 +1,7 @@
core.cheats = {
["Combat"] = {
["Killaura"] = "killaura",
["Forcefield"] = "forcefield",
["AntiKnockback"] = "antiknockback",
["FastHit"] = "spamclick",
["AttachmentFloat"] = "float_above_parent",

View File

@ -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

View File

@ -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

View File

@ -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<DistanceSortedActiveObject> 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;

View File

@ -773,7 +773,6 @@ public:
PointedThing updatePointedThing(
const core::line3d<f32> &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);

View File

@ -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");

View File

@ -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),

View File

@ -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);