using System;
using System.Collections.Generic;
using System.Linq;
using Facepunch;
using Newtonsoft.Json;
using Oxide.Core;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("TurboWeapons", "Marte6", "1.0.0")]
[Description("Customizes reload speeds and capacities for firearms.")]
public class TurboWeapons : RustPlugin
{
#region Fields
The provided code is an Oxide plugin for Rust, a multiplayer survival game. This plugin is named "TurboWeapons" and was created by a developer referred to as "Marte6". It offers customization options for firearm reload speeds and magazine capacities in the game. Here's a breakdown of its key components and features:
Key Features:
Reload Speed and Capacity Customization:
The plugin allows players with specific permissions to customize the reload speed and magazine capacity for firearms.
Commands are provided to increase the magazine capacity to 1.5x or 2x the default, reset it to the default capacity, and toggle fast reloading.
Permissions:
turboweapons.fastreload: Required to fast reload firearms.
turboweapons.customcapacity: Allows customization of a weapon's magazine capacity.
turboweapons.admin: Grants administrative control over plugin configurations.
User Interface:
Uses the CUI (Custom User Interface) of Oxide to display a graphical interface where users can interact with the plugin's features.
Users can search through weapon configurations, toggle settings, and adjust capacities directly through the UI.
Localization:
Supports multiple languages, including English, Spanish, Portuguese (Brazil), Russian, and German.
Uses the Oxide lang API to manage translations and provide localized feedback messages to players.
Configuration Management:
A configuration object handles settings and weapon definitions dynamically.
Weapon configurations are automatically refreshed and updated by discovering new weapon definitions present in the game server.
Integration with Other Plugins:
This plugin can work in conjunction with the ImageLibrary, LangAPI, and Notify plugins.
ImageLibrary is used to load weapon images within the UI.
Notify provides player notifications.
LangAPI offers alternative translations for item names.
Commands and Hooks:
Chat Commands:
/ui: Opens the weapon configuration UI for players with admin permissions.
Console Commands:
turboweapons.togglefastreload: Toggles fast reload mode for a specified weapon.
turboweapons.setcapacity: Sets a custom magazine capacity for a weapon.
Additional commands manage pagination and searching within the UI.
Lifecycle Hooks:
Init: Registers permissions when the plugin initializes.
OnServerInitialized: Invoked when the server is fully initialized to set up image loading and weapon configurations.
Unload: Cleans up any active UI elements when the plugin unloads.
OnActiveItemChanged: Updates weapon capacity appropriately when a player changes their active item.
OnWeaponReload: Handles customized reload processes following the configured settings.
How It Works:
Configuration and Setup: At startup, the plugin initializes configurations, loads necessary assets (such as images), and sets up hooks.
Player Interaction: Players can interact with the plugin via commands or the UI, if they have appropriate permissions. This includes adjusting firearms' reload properties and capacities.
Dynamic Adjustments: As players equip different firearms, the plugin dynamically adjusts their capacities and potentially changes reload behaviors based on player configurations and permissions.
Localization and Notifications: Players receive messages and notifications in their selected language, enhancing engagement and accessibility.
This plugin is designed to give server administrators control over firearm characteristics in Rust, providing a customizable experience in terms of how combat mechanics can be experienced by players.
To achieve the behavior you want—in which a notification includes the display name of the weapon and uses the GetItemDisplayName method—you will need to modify the NotifyPlayer method to include an additional parameter for the item's shortname. This parameter will be used to fetch the weapon's display name using the GetItemDisplayName method and then include it in the notification message.
Here's how you can implement this:
Modify the NotifyPlayer Method:
Update the NotifyPlayer method to accept an additional parameter for the weapon's shortname and use the GetItemDisplayName method to get the human-readable name of the weapon item:
csharp
private void NotifyPlayer(BasePlayer player, string key, int type, string weaponShortname = null, params object[] obj)
{
string userIdString = player.UserIDString;
string weaponDisplayName = weaponShortname != null ? GetItemDisplayName(player, weaponShortname) : string.Empty;
// Append weapon display name to the object array, if available
if (!string.IsNullOrEmpty(weaponDisplayName))
{
var objList = obj.ToList();
objList.Add(weaponDisplayName);
obj = objList.ToArray();
}
string message = Msg(userIdString, key, obj);
if (_configs.UseNotify && Notify != null)
{
Notify.Call("SendNotify", userIdString, type, message);
}
else
{
player.ChatMessage(message);
}
}
Update Message Calls:
Anywhere you call NotifyPlayer, make sure to pass the weapon's shortname as an argument. For example, in functions like UpdateWeaponCapacityForPlayer or any other function where you send a notification about a weapon, update the call:
The key here is ensuring that you pass weapon.GetItem()?.info?.shortname (or the relevant shortname) whenever you want the notification to include the weapon's display name.
Ensure Display Name is Used:
Ensure that your localization messages are structured to include the item name if needed. For instance, in your messages dictionary in LoadDefaultMessages, you would handle it like:
json
["NewCapacity"] = "Your {0} now has a magazine capacity of {1}."
This setup assumes that {0} will be replaced by the item's display name, provided as a part of the params object[] obj.
By following these steps, you ensure that the player's notification includes an item display name wherever applicable, thereby providing a more readable and engaging user experience.
If the GetItemDisplayName method is where you actually want to determine and include the weapon's display name, and you just want to change the way you pass the parameters to NotifyPlayer, here's how you can do it:
In the NotifyPlayer method, instead of directly appending the weapon display name to the message, ensure that you are passing the weapon shortname obtained from the item entity, and adjust your message composition logic to properly format the message using the display name through GetItemDisplayName.
Use GetItemDisplayName When Setting Up Message Content:
You can keep the logic in NotifyPlayer similar but ensure you're getting the right display name within your context:
csharp
private void NotifyPlayer(BasePlayer player, string key, int type, string weaponShortname = null, params object[] obj)
{
string userIdString = player.UserIDString;
string weaponDisplayName = weaponShortname != null ? GetItemDisplayName(player, weaponShortname) : string.Empty;
// Format the message by integrating the weapon display name in the provided objects (if applicable)
string message = Msg(userIdString, key, obj.Prepend(weaponDisplayName).ToArray());
if (_configs.UseNotify && Notify != null)
{
// Use the Notify plugin to send the message, if available
Notify.Call("SendNotify", userIdString, type, message);
}
else
{
// Send the message directly to the player chat
player.ChatMessage(message);
}
}
Ensure Correct Parameterization:
When invoking NotifyPlayer, make sure you're using the appropriate data, fetching the shortname for the weapon wherever you call it. For example:
You ensure you pass the weapon shortname correctly.
The message formatting automatically prepends the resolved display name for the item wherever you have a placeholder for it in your localization dictionary.
Localization Texts:
Ensure your localization resources/messages contain placeholders for weapon names, if necessary:
json
{"NewCapacity": "Your {1} now has a magazine capacity of {2}."}
This setup allows you to handle the message localization with pre-fetched display name by calling GetItemDisplayName prior to composing the message, ensuring clarity in player notifications.
By following these steps, you will be able to integrate the actual item display names seamlessly into your notification system while keeping the existing structure largely intact. If you're referring to more specific changes required or if I misunderstood a part of your requirement, please provide any additional specifics needed.