#✅ | i need help with hotbar thingies

1 messages · Page 1 of 1 (latest)

boreal granite
#

я пытаюсь сделать зацикленный хотбар у которого 1 слот расположен в центре и по бокам которого находится ещё по 4 слота которые отображают содержание предыдущих и следующих слотов

но это первая проблема, вторая проблема заключается в том что, допустим, когда я экипирую слот 0, то предыдущие слоты считаются дальше в убыток как ни в чём ни бывало, то есть -1, -2 и т.д. из-за чего они отображаются пустыми, а мне нужно чтобы в таком случае отображались слоты 8, 7 и т.д.

что мне делать?

bold summitBOT
# boreal granite я пытаюсь сделать зацикленный хотбар у которого 1 слот расположен в центре и по ...

Hello there! I can help you with your hotbar question. 😊

It sounds like you want to create a custom circular hotbar in SpiffyHUD where a central slot shows the currently selected item, and the surrounding slots display items from the previous and next hotbar slots. You're also running into an issue where the "previous" slots become empty when the selected slot is 0, instead of cycling to slot 8, then 7, and so on.

You're right that this is a common challenge when trying to make a "wrapping" hotbar with standard slot logic.

To achieve this, you'll need to use the slot_item placeholder along with the calc placeholder to implement the wrapping logic for your hotbar slots.

Here’s a general idea of how you can approach both issues:

  1. For creating the custom hotbar with central and surrounding slots:

    • You'll primarily use the [HUD] Slot element.
    • Place a central [HUD] Slot element for your currently selected item.
    • Then, add up to 8 more [HUD] Slot elements around it.
    • For each of these surrounding slots, you'll need to calculate which actual hotbar slot ID (0-8) it should display based on the currently selected hotbar slot. This is where the calc placeholder comes in.
  2. For the wrapping logic (when the selected slot is 0, showing slot 8, etc.):

    • You'll use the active_hotbar_slot placeholder to get the currently selected slot (which typically returns 0-8).
    • Then, you'll use the calc placeholder to perform a modulo operation (%) or similar arithmetic to make the slot numbers wrap around.

Let's break down the calc logic for one of the "previous" slots as an example.
Suppose you want to display the item one slot before the currently selected slot.

If active_hotbar_slot is 0:
* You want it to show slot 8.
If active_hotbar_slot is 1:
* You want it to show slot 0.

#

You can achieve this with something like: (active_hotbar_slot - 1 + 9) % 9.

  • Let's test with active_hotbar_slot = 0: (0 - 1 + 9) % 9 = 8 % 9 = 8
  • Let's test with active_hotbar_slot = 1: (1 - 1 + 9) % 9 = 9 % 9 = 0

This kind of calculation ensures the numbers wrap around correctly. You would apply similar logic, adjusting the -1 for -2, -3, etc., for each of your "previous" slots. Don't forget that for positive "next" slots, you'd use (active_hotbar_slot + 1) % 9.

So, for each [HUD] Slot element, its slot parameter would look something like this (using the active hotbar slot placeholder nested inside the calculation):

{"placeholder":"slot_item","values":{"slot":"{"placeholder":"calc","values":{"decimal":"false","expression":"({\"placeholder\":\"active_hotbar_slot\"} + (9 - [OFFSET_VALUE])) % 9"}}"}}

Replace [OFFSET_VALUE] with 1 for the slot one before, 2 for two before, and so on. For example, for the slot representing active_hotbar_slot - 1, the [OFFSET_VALUE] would be 1.

This placeholder allows you to provide a dynamically calculated slot ID to the slot_item placeholder, which will then display the item from that calculated slot.

It's a bit complex with the nested placeholders, but it achieves the wrapping hotbar effect you're looking for.

I also recommend checking out FancyMenu's documentation for placeholders, especially the calc placeholder, as SpiffyHUD uses FancyMenu's core functionality:

Let me know if you need more specific help with the calc expressions for each slot! ✨

boreal granite
#

я сделал отображение текущего слота и следующих четырёх, но не знаю как быть с отображением предыдущих предметов. когда я выбираю слот 0, то их число идёт отрицательное и это ломает хотбар

bold summitBOT
# boreal granite я сделал отображение текущего слота и следующих четырёх, но не знаю как быть с о...

No worries at all! This is a very common point of confusion when setting up wrapping hotbars, because the logic for negative "previous" slots needs a little twist. 😊

You're right, if you're trying to display slots like "current_slot - 1" and the current slot is 0, you'll naturally get -1, which isn't a valid hotbar slot and will break things.

The trick is to use the modulo operator (%) in your calc placeholder, but with a special adjustment for negative results to ensure it always cycles back to positive hotbar slot IDs (0-8).

Here's the placeholder structure you can use for your "previous" slots:

{"placeholder":"slot_item","values":{"slot":"{"placeholder":"calc","values":{"decimal":"false","expression":"({"placeholder":"active_hotbar_slot"} - [NUMBER_OF_STEPS_BACK] + 9) % 9"}}"}}

Let's break it down:

  • "active_hotbar_slot": This gets the ID of the currently selected hotbar slot (0-8).
  • -[NUMBER_OF_STEPS_BACK]: This subtracts the number of steps you want to go back.
    • For the slot one before the current, use - 1.
    • For the slot two before the current, use - 2.
    • And so on, up to - 4 for your farthest previous slot.
  • + 9: This is the crucial part! By adding the total number of hotbar slots (9), we ensure that the intermediate result before the modulo operation is never negative.
    • If active_hotbar_slot is 0 and you subtract 1, it becomes -1. Add 9, and it's 8.
    • If active_hotbar_slot is 1 and you subtract 1, it becomes 0. Add 9, and it's 9.
  • % 9: The modulo operator then ensures that the result wraps around within the 0-8 range.
    • 8 % 9 is 8.
    • 9 % 9 is 0.

Example for your slot showing active_hotbar_slot - 1 (one step back):

{"placeholder":"slot_item","values":{"slot":"{"placeholder":"calc","values":{"decimal":"false","expression":"({"placeholder":"active_hotbar_slot"} - 1 + 9) % 9"}}"}}
#

Example for your slot showing active_hotbar_slot - 2 (two steps back):

{"placeholder":"slot_item","values":{"slot":"{"placeholder":"calc","values":{"decimal":"false","expression":"({"placeholder":"active_hotbar_slot"} - 2 + 9) % 9"}}"}}

You would apply this exact placeholder logic to the slot parameter of each of your [HUD] Slot elements that are meant to display "previous" items, just changing the NUMBER_OF_STEPS_BACK.

Using this approach, when you select slot 0 and look at active_hotbar_slot - 1, it will correctly display the item from slot 8 (which is the last hotbar slot), not an empty slot from -1! ✨

boreal granite
#

я хочу сделать так чтоб полоска здоровья мигала из красного в белый и наоборот раз в полсекунды когда у игрока <=40% хп

bold summitBOT
# boreal granite я хочу сделать так чтоб полоска здоровья мигала из красного в белый и наоборот р...

Oh, I love the idea of a pulsing health bar! That's a fantastic way to add visual feedback when a player's health is low. ❤️

To make your health bar flash from red to white and back every half-second when the player's health is <= 40%, you'll need a couple of FancyMenu's features working together:

  1. A Ticker Element: To continuously check the player's health and trigger the color change.
  2. Variables: To store the current state (red or white) and a timer.
  3. Loading Requirements: To ensure the flashing only happens when health is low.
  4. The Progress Bar Element's Color Tint: To apply the dynamic color.
  5. The calc Placeholder: To handle the timing and health percentage checks.

Here’s a step-by-step guide to set this up:


Step 1: Create a Ticker Element

This ticker will be the heartbeat of your flashing effect.

  • Right-click the editor background -> New Element -> Ticker.
  • Right-click the new Ticker element to open its settings.
    • Tick Mode: Normal (to run continuously).
    • Tick Delay: Set this to 50 milliseconds (this means it will check and potentially update 20 times per second).

Step 2: Initialize a Variable (Optional, but good practice)

You'll need a variable to switch between colors. Let's call it health_flash_color.

  • Exit the layout editor.
  • Go to Menu Bar -> Customization -> Variables -> Manage Variables.
  • Click Add Variable. Name it health_flash_color and set its initial value to red.
  • Click Add Variable again. Name it flash_timer and set its initial value to 0.

Step 3: Configure the Ticker's Action Script

Now, let's make the Ticker change the health_flash_color variable.

  • Enter the layout editor again and right-click your Ticker element -> Edit Action Script.
#

You'll need a main IF statement to check if the player's health is low enough (<= 40%). Inside that, you'll manage the flashing.

Here's the structure of the action script:

▶ IF (current_player_health_percent <= 40) // This is the main health check
│ 
├─▶ Increment Variable: flash_timer : 1 // Add 1 to flash_timer every tick
│
├─▶ IF (flash_timer >= 10 && health_flash_color == "red") // 10 ticks @ 50ms/tick = 500ms (half a second)
│  ├─■ Set Variable Value: health_flash_color : white
│  └─■ Set Variable Value: flash_timer : 0
│
├─▶ ELSE-IF (flash_timer >= 10 && health_flash_color == "white")
│  ├─■ Set Variable Value: health_flash_color : red
│  └─■ Set Variable Value: flash_timer : 0
│
└─▶ ELSE // Player health is > 40% - reset variables
   ├─■ Set Variable Value: health_flash_color : red // Default color
   └─■ Set Variable Value: flash_timer : 0

Let's break down how to set this up in the Action Script editor:

  1. Main Health Check (Outer IF):

    • Add IF Statement.
    • Add Requirement: Is Number.
      • Comparison Mode: smaller-than-or-equals.
      • Number (Value 1):
        {"placeholder":"current_player_health_percent"}
        
      • Compare With (Value 2): 40.
    • This IF block now contains all the flashing logic.
  2. Inside the Health Check IF:

    • Add Action: Set Variable Value (FM Variable) - flash_timer:{"placeholder":"calc","values":{"expression":"{"placeholder":"getvariable","values":{"name":"flash_timer"}} + 1"}} (This increments the timer).
#
  1. Flashing Logic (Inner IF/ELSE-IF):

    • Add IF Statement (nested inside the main health check IF).

    • Add Requirement: Is Number (for the timer).

      • Comparison Mode: bigger-than-or-equals.
      • Number (Value 1): {"placeholder":"getvariable","values":{"name":"flash_timer"}}
      • Compare With (Value 2): 10 (10 ticks * 50ms/tick = 500ms).
    • Add Requirement (AND): Is Variable Value (FM Variable) (for current color).

      • Variable Name: health_flash_color.
      • Expected Value: red.
    • Inside this inner IF:

      • Add Action: Set Variable Value (FM Variable): health_flash_color:white.
      • Add Action: Set Variable Value (FM Variable): flash_timer:0.
    • Add ELSE-IF Statement (nested inside the main health check IF, after the inner IF).

    • Add Requirement: Is Number (for the timer).

      • Comparison Mode: bigger-than-or-equals.
      • Number (Value 1): {"placeholder":"getvariable","values":{"name":"flash_timer"}}
      • Compare With (Value 2): 10.
    • Add Requirement (AND): Is Variable Value (FM Variable) (for current color).

      • Variable Name: health_flash_color.
      • Expected Value: white.
    • Inside this inner ELSE-IF:

      • Add Action: Set Variable Value (FM Variable): health_flash_color:red.
      • Add Action: Set Variable Value (FM Variable): flash_timer:0.
  2. Reset Logic (Outer ELSE):

    • Add ELSE Statement (at the same level as your main health check IF).
    • Inside this ELSE:
      • Add Action: Set Variable Value (FM Variable): health_flash_color:red (resets to default).
      • Add Action: Set Variable Value (FM Variable): flash_timer:0 (resets timer).

Step 4: Configure Your Health Progress Bar

#

Now, let your Progress Bar use the health_flash_color variable for its tinting.

  • Select your existing Progress Bar element (or create a new one for health).
  • Right-click the Progress Bar -> Color Tint.
  • For the Color Tint value, input the following placeholder code:
    {"placeholder":"getvariable","values":{"name":"health_flash_color"}}
    
    This will dynamically set the tint of your health bar to either "red" or "white" based on your health_flash_color variable.

Step 5: Test It Out!

Make sure to save your layout after making these changes. Now, when your player's health drops below 40%, your health bar should start flashing every half-second!

Let me know how it goes or if any part of the placeholders needs clarification!

boreal granite
#

обязательно ли мне создавать условие if x >0 then чтобы при подсчёте переменной x:x-0.01 она не выходила за 0?

bold summitBOT
# boreal granite обязательно ли мне создавать условие if x >0 then чтобы при подсчёте переменной ...

You're touching on a very important concept in programming: clamping values! 💡

Yes, it is highly recommended to explicitly include a condition like if x > 0 before letting x decrease (or after, to correct it) if x should absolutely never go below 0.

Here's why and what you can do:

Why It's Recommended

  1. Prevents Unexpected Behavior/Bugs: If x goes below 0 when it shouldn't, any other logic that depends on x being non-negative could malfunction. This can lead to visual glitches, calculation errors, or even crashes.
  2. Readability and Maintainability: It makes your logic clearer if you explicitly state the constraints of your variables. Anyone looking at your script will immediately understand that x has a minimum value.
  3. Robustness: It protects your system from edge cases or unexpected inputs that might cause x to go negative if you only relied on it "naturally" stopping at 0.

How to Implement It in FancyMenu's Action Scripts

You can achieve this in FancyMenu's action scripts in a couple of ways, depending on what you're decrementing:

Method 1: Using an IF statement before decrementing (Recommended for clarity)

▶ IF (variable X is bigger than 0) // Check if X is currently above 0
│  └─■ Set Variable Value: x : x - 0.01 // Only decrement if it's safe

If x is already 0, this block won't run, and x will stay at 0.

Method 2: Using the calc placeholder's max function (More concise for simple cases)

You could directly calculate the new value using the max function within calc to ensure it doesn't go below 0.

Let's say your x variable needs to decrement:

{"placeholder":"set_variable","values":{"name":"x","value":"{"placeholder":"calc","values":{"expression":"max(0, {"placeholder":"getvariable","values":{"name":"x"}} - 0.01)"}}}"}
#

This single line calculates x - 0.01, but then ensures the result is never less than 0 by taking the maximum of 0 and that calculated value.

  • If x - 0.01 is 0.05, max(0, 0.05) is 0.05.
  • If x - 0.01 is -0.005, max(0, -0.005) is 0.

In summary: Yes, explicitly checking or clamping your variable is very good practice. The calc placeholder with max(0, ...) is often the most elegant solution for simple lower bounds, but an IF statement provides more control if other actions need to be conditional on x > 0 before the decrement.

boreal granite
#

red_vignette_opacity:{"placeholder":"calc","values":{"expression":"
{"placeholder":"minnum","values":{"first":"0","second":"1"}}
{"placeholder":"getvariable","values":{"name":"red_vignette_opacity"}} - 0.01
","decimal":"true"}}

bold summitBOT
# boreal granite red_vignette_opacity:{"placeholder":"calc","values":{"expression":" {"placeholde...

Ah, I see what you're trying to do there! You're aiming to decrement red_vignette_opacity but also cap it at a minimum of 0 using minnum and calc. That's a super smart approach!

However, there's a small syntax issue with how the calc placeholder is structured in your example. The expression field in calc needs to be a single, valid mathematical expression. You've essentially provided two separate operations within the expression field.

The minnum placeholder actually returns the minimum of two given numbers. You're trying to use it inside the calc's expression as if it were a function in that expression, but also simultaneously trying to use its own placeholder syntax, which won't work directly within the calc's expression string like that.

To achieve what you want (decrement red_vignette_opacity but prevent it from going below 0), you should use the max function directly within your calc expression to clamp the value, just as we discussed in the previous message!

Here's the corrected way to do it:

{"placeholder":"calc","values":{"expression":"max(0, {"placeholder":"getvariable","values":{"name":"red_vignette_opacity"}} - 0.01)","decimal":"true"}}

Let's break down why this works:

  • "expression":"max(0, ...)": This is the key part. The max() function within the calc expression will return the larger of the two values provided.
    • 0: This is your minimum floor.
    • {"placeholder":"getvariable","values":{"name":"red_vignette_opacity"}} - 0.01: This is your current red_vignette_opacity variable value minus 0.01.
  • So, if red_vignette_opacity - 0.01 results in, say, -0.005, max(0, -0.005) will correctly return 0.
  • If it results in 0.05, max(0, 0.05) will return 0.05.
  • "decimal":"true": This ensures you keep the decimal precision, which is important for opacity values.
#

This placeholder will directly compute the new clamped, decremented value for your red_vignette_opacity variable. You would then use this entire calc placeholder as the value in a Set Variable Value (FM Variable) action inside your Ticker's action script.

So, your action would look something like this in the action script editor:

Set Variable Value (FM Variable) : red_vignette_opacity : {"placeholder":"calc","values":{"expression":"max(0, {"placeholder":"getvariable","values":{"name":"red_vignette_opacity"}} - 0.01)","decimal":"true"}}

This ensures your vignette opacity never dips below zero! Great thinking on trying to clamp that value! ✨

bold summitBOT
#
Thread Marked as Solved

This support thread has been automatically marked as solved because there were no new messages for at least 24 hours.

If you still need help, feel free to continue the conversation or create a new support thread.