Initial Commit :)
This commit is contained in:
26
README.md
Normal file
26
README.md
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
# PVP Choice
|
||||||
|
|
||||||
|
PVP Choice empowers players with the ability to toggle Player vs Player (PVP) interactions, providing a customizable experience in player interactions. This tool is ideal for those who prefer a more collaborative and peaceful environment or for times when engaging in combat isn't desired.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- **PVP Toggle Command**: Players can use `/toggle_pvp` to switch their PVP setting on or off.
|
||||||
|
- **Flexible Player Interactions**: If any player involved in a conflict has PVP disabled, damage between them is prevented.
|
||||||
|
- **Intuitive Player Settings**: PVP preferences are stored as player metadata, maintaining individual choices across sessions.
|
||||||
|
|
||||||
|
## Commands
|
||||||
|
|
||||||
|
- `/toggle_pvp`: Enables or disables PVP for the player issuing the command. By default, PVP is disabled.
|
||||||
|
|
||||||
|
## Compatibility
|
||||||
|
|
||||||
|
- Designed to integrate seamlessly with existing player interaction systems.
|
||||||
|
- Compatible with various player and combat-related functionalities.
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
This project is under the GPLv3-or-later license. For more information, see the `LICENSE` file.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
T
|
||||||
94
init.lua
Normal file
94
init.lua
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
-- Function to toggle PvP for a player
|
||||||
|
local function toggle_pvp(player)
|
||||||
|
local pvp_setting = player:get_meta():get_string("pvp_enabled")
|
||||||
|
|
||||||
|
if pvp_setting == "" or pvp_setting == "false" then
|
||||||
|
player:get_meta():set_string("pvp_enabled", "true")
|
||||||
|
minetest.chat_send_player(player:get_player_name(), "PvP is now enabled for you.")
|
||||||
|
else
|
||||||
|
player:get_meta():set_string("pvp_enabled", "false")
|
||||||
|
minetest.chat_send_player(player:get_player_name(), "PvP is now disabled for you.")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Function to check if PvP is enabled for a player
|
||||||
|
local function is_pvp_enabled(player)
|
||||||
|
local pvp_setting = player:get_meta():get_string("pvp_enabled")
|
||||||
|
return pvp_setting ~= "false"
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Registering the /toggle_pvp command
|
||||||
|
minetest.register_chatcommand("toggle_pvp", {
|
||||||
|
description = "Toggle PvP on or off",
|
||||||
|
privs = {interact = true},
|
||||||
|
func = function(name)
|
||||||
|
local player = minetest.get_player_by_name(name)
|
||||||
|
if player then
|
||||||
|
toggle_pvp(player)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
-- Register the on punch player event
|
||||||
|
minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch, tool_capabilities, dir, damage)
|
||||||
|
local player_pvp_setting = player:get_meta():get_string("pvp_enabled")
|
||||||
|
local hitter_pvp_setting = hitter:get_meta():get_string("pvp_enabled")
|
||||||
|
|
||||||
|
-- Check if PvP is disabled for either player
|
||||||
|
if player_pvp_setting == "false" or hitter_pvp_setting == "false" then
|
||||||
|
return true -- Cancel the punch event
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Initialize PvP setting for each player as they join
|
||||||
|
minetest.register_on_joinplayer(function(player)
|
||||||
|
-- Default to PvP off if not already set
|
||||||
|
if player:get_meta():get_string("pvp_enabled") == "" then
|
||||||
|
player:get_meta():set_string("pvp_enabled", "false")
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
if minetest.get_modpath("mcl_inventory") then
|
||||||
|
-- Override the damage handling function
|
||||||
|
local original_damage_function = mcl_damage.run_modifiers
|
||||||
|
mcl_damage.run_modifiers = function(obj, damage, reason)
|
||||||
|
-- Check if the damage is caused by a projectile and both entities involved are players
|
||||||
|
if (reason.type == "arrow" or reason.type == "fireball") and obj:is_player() and reason.source and reason.source:is_player() then
|
||||||
|
-- Check PvP settings for both players
|
||||||
|
if not is_pvp_enabled(obj) or not is_pvp_enabled(reason.source) then
|
||||||
|
return 0 -- No damage if PvP is disabled for either player
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Call the original damage function for all other cases
|
||||||
|
return original_damage_function(obj, damage, reason)
|
||||||
|
end
|
||||||
|
minetest.log("action", "[PvP Mod] mcl_inventory modpath found. Registering PvP tab.")
|
||||||
|
|
||||||
|
mcl_inventory.register_survival_inventory_tab({
|
||||||
|
id = "pvp_toggle",
|
||||||
|
description = "PvP Toggle",
|
||||||
|
item_icon = "mcl_tools:sword_diamond", -- Replace with an appropriate icon
|
||||||
|
show_inventory = true,
|
||||||
|
build = function(player)
|
||||||
|
minetest.log("action", "[PvP Mod] Building PvP formspec for player " .. player:get_player_name())
|
||||||
|
local pvp_setting = player:get_meta():get_string("pvp_enabled")
|
||||||
|
local button_label = pvp_setting == "true" and "Disable PvP" or "Enable PvP"
|
||||||
|
return "label[1,1;PvP Settings]" ..
|
||||||
|
"button[2,2;3,1;toggle_pvp;" .. button_label .. "]"
|
||||||
|
end,
|
||||||
|
handle = function(player, fields)
|
||||||
|
minetest.log("action", "[PvP Mod] PvP tab pressed by" .. player:get_player_name())
|
||||||
|
if fields.toggle_pvp then
|
||||||
|
minetest.log("action", "[PvP Mod] PvP toggle button pressed by " .. player:get_player_name())
|
||||||
|
toggle_pvp(player)
|
||||||
|
mcl_inventory.update_inventory(player) -- Update inventory to refresh the tab
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.log("action", "[PvP Mod] PvP tab registered.")
|
||||||
|
else
|
||||||
|
minetest.log("error", "[PvP Mod] mcl_inventory modpath not found. PvP tab not registered.")
|
||||||
|
end
|
||||||
|
|
||||||
5
mod.conf
Normal file
5
mod.conf
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
name = pvp_choice
|
||||||
|
title = PVP Choice
|
||||||
|
description = Enables you to choose weather you want to PVP or not.
|
||||||
|
supported_games = *
|
||||||
|
optional_depends = mcl_inventory, mcl_damage
|
||||||
BIN
screenshot.png
Normal file
BIN
screenshot.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 342 KiB |
BIN
screenshot2.png
Normal file
BIN
screenshot2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 413 KiB |
Reference in New Issue
Block a user