Advertisement
MarrKoo

[GPT] PZ SearchModeAPI - question answer

Dec 26th, 2024
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.03 KB | None | 0 0
  1. To achieve the effect of triggering the darkness effect when wearing specific items, such as a Welders Mask, you'll need to check whether the player is currently wearing or equipping the item, and then activate the "darkness" effect using the `SearchModeAPI` when the item is equipped. Here's a basic approach to implementing this in Lua:
  2.  
  3. ### Steps:
  4.  
  5. 1. **Check if the player is wearing a specific item**: You need to check the player's inventory or equipped items to see if they're wearing something like a Welder's Mask.
  6.  
  7. 2. **Activate the "darkness" effect when the item is equipped**: Once the item is equipped, you'll trigger the effect (e.g., darkness) using the `SearchModeAPI` functions.
  8.  
  9. 3. **Deactivate the effect when the item is removed**: If the player removes the item, you'll deactivate the effect.
  10.  
  11. Here is an example of how you can implement this:
  12.  
  13. ### Example Lua Code:
  14.  
  15. ```lua
  16. -- Register a new mode for the effect (you can change 'welders_mask_effect' to something meaningful)
  17. SearchModeAPI.Register("welders_mask_effect", 5) -- Set priority (higher value means higher priority)
  18.  
  19. -- Function to check if player is wearing a specific item
  20. local function isWearingWeldersMask(player)
  21.    -- You can change "Welders Mask" to the exact item name in the game
  22.    return player:getInventory():contains("Welders Mask")
  23. end
  24.  
  25. -- Function to activate the darkness effect
  26. local function activateDarknessEffect()
  27.    SearchModeAPI.Activate("welders_mask_effect")
  28.    local mode = getSearchMode():getSearchModeForPlayer(0)
  29.    mode:getDarkness():setTargets(1, 1) -- Set darkness to 100% (black screen)
  30. end
  31.  
  32. -- Function to deactivate the darkness effect
  33. local function deactivateDarknessEffect()
  34.    SearchModeAPI.Deactivate("welders_mask_effect")
  35.    local mode = getSearchMode():getSearchModeForPlayer(0)
  36.    mode:getDarkness():setTargets(0, 0) -- Set darkness back to 0% (normal screen)
  37. end
  38.  
  39. -- Function to monitor the player's equipped items and apply the effect accordingly
  40. local function checkWeldersMaskEffect(player)
  41.     if isWearingWeldersMask(player) then
  42.         -- Activate effect if wearing the mask
  43.         activateDarknessEffect()
  44.     else
  45.         -- Deactivate effect if not wearing the mask
  46.         deactivateDarknessEffect()
  47.     end
  48. end
  49.  
  50. -- Call the check function periodically (for example, once per frame or every few seconds)
  51. Events.OnPlayerUpdate.Add(function(player)
  52.     checkWeldersMaskEffect(player)
  53. end)
  54. ```
  55.  
  56. ### Explanation:
  57.  
  58. - **`isWearingWeldersMask(player)`**: This function checks if the player is currently wearing the Welders Mask (or any other item you specify). You can change `"Welders Mask"` to match the exact name of the item in the game.
  59.  
  60. - **`activateDarknessEffect()`**: This function activates the darkness effect using `SearchModeAPI`. It sets the darkness to 100%, which results in a black screen.
  61.  
  62. - **`deactivateDarknessEffect()`**: This function deactivates the darkness effect and restores the screen to normal.
  63.  
  64. - **`checkWeldersMaskEffect(player)`**: This function checks if the player is wearing the Welders Mask, and if so, activates the darkness effect. If the mask is removed, it deactivates the effect.
  65.  
  66. - **`Events.OnPlayerUpdate.Add(...)`**: This code checks the player's equipment every time the player updates (i.e., every frame or at intervals). It calls `checkWeldersMaskEffect` to ensure the effect is correctly applied when the item is equipped or removed.
  67.  
  68. ### Notes:
  69. - The above code assumes that the item (e.g., "Welders Mask") is identified correctly in the player's inventory. If you have a different name for the item in your game, make sure to adjust the item name accordingly.
  70. - You may need to adjust the exact way the `SearchModeAPI` works depending on whether you're using it with other mods or effects.
  71. - If you're using other equipment that should trigger a similar effect, you can extend the `isWearingWeldersMask` function to check for multiple items or use additional `SearchModeAPI.Register` calls for each item.
  72.  
  73. Let me know if you need further details or adjustments!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement