update std rules & add player.destroy binding

This commit is contained in:
MihailRis 2024-11-06 21:28:12 +03:00
parent df2f24d94e
commit d27179b6c3
9 changed files with 22 additions and 9 deletions

View File

@ -21,6 +21,7 @@
- [pack](scripting/builtins/libpack.md)
- [player](scripting/builtins/libplayer.md)
- [quat](scripting/builtins/libquat.md)
- [rules](scripting/builtins/librules.md)
- [time](scripting/builtins/libtime.md)
- [utf8](scripting/builtins/libutf8.md)
- [vec2, vec3, vec4](scripting/builtins/libvecn.md)

View File

@ -13,6 +13,7 @@ camera.mode="key:f4"
player.noclip="key:n"
player.flight="key:f"
player.attack="mouse:left"
player.destroy="mouse:left"
player.build="mouse:right"
player.pick="mouse:middle"
player.drop="key:q"

View File

@ -61,7 +61,7 @@ function submit(text)
if name == nil then
name = text
end
if not rules.get("cheat-commands") and table.has(console.cheats, name) then
if not rules.get("allow-cheats") and table.has(console.cheats, name) then
console.log("cheat commands are disabled")
document.prompt.text = ""
document.prompt.focused = true

View File

@ -33,7 +33,7 @@ console.add_command(
local str = "Available commands:"
for i,k in ipairs(commands) do
if rules.get("cheat-commands") or not table.has(console.cheats, k) then
if rules.get("allow-cheats") or not table.has(console.cheats, k) then
str = str .. "\n " .. build_scheme(console.get_command_info(k))
end
end

View File

@ -229,7 +229,10 @@ function _rules.create(name, value, handler)
end
function _rules.unlisten(name, id)
local rule = _rules.get_rule(name)
local rule = _rules.rules[name]
if rule == nil then
return
end
rule.listeners[utf8.encode(id)] = nil
end
@ -237,7 +240,7 @@ function _rules.clear()
_rules.rules = {}
_rules.nextid = 1
_rules.create("cheat-commands", true)
_rules.create("allow-cheats", true)
end
function __vc_create_hud_rules()
@ -250,9 +253,12 @@ function __vc_create_hud_rules()
_rules.create("allow-noclip", true, function(value)
input.set_enabled("player.noclip", value)
end)
_rules.create("allow-destruct", true, function(value)
_rules.create("allow-attack", true, function(value)
input.set_enabled("player.attack", value)
end)
_rules.create("allow-destroy", true, function(value)
input.set_enabled("player.destroy", value)
end)
_rules.create("allow-cheat-movement", true, function(value)
input.set_enabled("movement.cheat", value)
end)

View File

@ -29,7 +29,8 @@ movement.crouch=Crouch
movement.cheat=Cheat
hud.inventory=Inventory
player.pick=Pick Block
player.attack=Attack / Break
player.attack=Attack
player.destroy=Destroy
player.build=Place Block
player.fast_interaction=Accelerated interaction
player.flight=Flight

View File

@ -91,7 +91,8 @@ movement.crouch=Красться
movement.cheat=Чит
hud.inventory=Инвентарь
player.pick=Подобрать Блок
player.attack=Атаковать / Сломать
player.attack=Атаковать
player.destroy=Сломать
player.build=Поставить Блок
player.fast_interaction=Ускоренное взаимодействие
player.flight=Полёт

View File

@ -25,6 +25,7 @@ inline const std::string BIND_CAM_MODE = "camera.mode";
inline const std::string BIND_PLAYER_NOCLIP = "player.noclip";
inline const std::string BIND_PLAYER_FLIGHT = "player.flight";
inline const std::string BIND_PLAYER_ATTACK = "player.attack";
inline const std::string BIND_PLAYER_DESTROY = "player.destroy";
inline const std::string BIND_PLAYER_BUILD = "player.build";
inline const std::string BIND_PLAYER_PICK = "player.pick";
inline const std::string BIND_PLAYER_FAST_INTERACTOIN =

View File

@ -494,7 +494,9 @@ void PlayerController::updateInteraction(float delta) {
bool xkey = Events::active(BIND_PLAYER_FAST_INTERACTOIN);
float maxDistance = xkey ? 200.0f : 10.0f;
bool longInteraction = interactionTimer <= 0 || xkey;
bool lclick = Events::jactive(BIND_PLAYER_ATTACK) ||
bool lclick = Events::jactive(BIND_PLAYER_DESTROY) ||
(longInteraction && Events::active(BIND_PLAYER_DESTROY));
bool lattack = Events::jactive(BIND_PLAYER_ATTACK) ||
(longInteraction && Events::active(BIND_PLAYER_ATTACK));
bool rclick = Events::jactive(BIND_PLAYER_BUILD) ||
(longInteraction && Events::active(BIND_PLAYER_BUILD));
@ -512,7 +514,7 @@ void PlayerController::updateInteraction(float delta) {
scripting::on_item_use(player.get(), item);
}
if (selection.entity) {
updateEntityInteraction(selection.entity, lclick, rclick);
updateEntityInteraction(selection.entity, lattack, rclick);
}
return;
}