Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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:
- ### Steps:
- 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.
- 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.
- 3. **Deactivate the effect when the item is removed**: If the player removes the item, you'll deactivate the effect.
- Here is an example of how you can implement this:
- ### Example Lua Code:
- ```lua
- -- Register a new mode for the effect (you can change 'welders_mask_effect' to something meaningful)
- SearchModeAPI.Register("welders_mask_effect", 5) -- Set priority (higher value means higher priority)
- -- Function to check if player is wearing a specific item
- local function isWearingWeldersMask(player)
- -- You can change "Welders Mask" to the exact item name in the game
- return player:getInventory():contains("Welders Mask")
- end
- -- Function to activate the darkness effect
- local function activateDarknessEffect()
- SearchModeAPI.Activate("welders_mask_effect")
- local mode = getSearchMode():getSearchModeForPlayer(0)
- mode:getDarkness():setTargets(1, 1) -- Set darkness to 100% (black screen)
- end
- -- Function to deactivate the darkness effect
- local function deactivateDarknessEffect()
- SearchModeAPI.Deactivate("welders_mask_effect")
- local mode = getSearchMode():getSearchModeForPlayer(0)
- mode:getDarkness():setTargets(0, 0) -- Set darkness back to 0% (normal screen)
- end
- -- Function to monitor the player's equipped items and apply the effect accordingly
- local function checkWeldersMaskEffect(player)
- if isWearingWeldersMask(player) then
- -- Activate effect if wearing the mask
- activateDarknessEffect()
- else
- -- Deactivate effect if not wearing the mask
- deactivateDarknessEffect()
- end
- end
- -- Call the check function periodically (for example, once per frame or every few seconds)
- Events.OnPlayerUpdate.Add(function(player)
- checkWeldersMaskEffect(player)
- end)
- ```
- ### Explanation:
- - **`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.
- - **`activateDarknessEffect()`**: This function activates the darkness effect using `SearchModeAPI`. It sets the darkness to 100%, which results in a black screen.
- - **`deactivateDarknessEffect()`**: This function deactivates the darkness effect and restores the screen to normal.
- - **`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.
- - **`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.
- ### Notes:
- - 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.
- - You may need to adjust the exact way the `SearchModeAPI` works depending on whether you're using it with other mods or effects.
- - 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.
- Let me know if you need further details or adjustments!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement