How to develop plugin with Vote System ?

Of course, here's the tutorial in English:

Tutorial: Creating a "Vote Rewards Shop" Extension for VoteSystem using Oxide

1. Setting Up Your Extension

Create a new class for your extension:

public class VoteRewardsShop : RustPlugin
{
    [PluginReference] 
    Plugin VoteSystem;
}

2. Creating the Shop

For simplicity, let's create a shop with three items: wood, stone, and metal fragments.

private Dictionary<string, int> shopItems = new Dictionary<string, int>
{
    {"wood", 10},  // 10 points for 1000 wood
    {"stone", 20}, // 20 points for 1000 stones
    {"metal.fragments", 30} // 30 points for 1000 metal fragments
};

3. Interacting with VoteSystem

To get a player's total votes:

public int GetPlayerTotalVotes(ulong playerId)
{
    return VoteSystem.Call<int>("GetTotalVotes_API", playerId);
}

4. Buying Items from the Shop

Let's create a command that players can use to buy items in the shop:

[ChatCommand("buy")]
private void BuyCommand(BasePlayer player, string command, string[] args)
{
    if (args.Length == 0)
    {
        player.ChatMessage("Usage: /buy <item>");
        return;
    }

    string item = args[0];
    if (!shopItems.ContainsKey(item))
    {
        player.ChatMessage($"Item {item} not found in the shop.");
        return;
    }

    int itemCost = shopItems[item];
    int playerVotes = GetPlayerTotalVotes(player.userID);

    if (playerVotes < itemCost)
    {
        player.ChatMessage($"You don't have enough points to buy {item}. You need {itemCost} points.");
        return;
    }

    // Deduct points from a custom data structure (e.g., a dictionary)
    // and give item to player
    playerVotes -= itemCost;
    player.inventory.GiveItem(ItemManager.CreateByName(item, 1000)); // Give 1000 of the item

    player.ChatMessage($"You bought 1000 {item} for {itemCost} points. Remaining points: {playerVotes}");
}

Note: In this example, we're assuming you have a custom data structure (e.g., a dictionary) to store players' vote points. You'll need to implement this structure and methods to add, subtract, and get points.

5. Implementing VoteSystem Hooks

OnGivePoints Hook:

This hook is called when a player receives points for voting. You can use it to inform players of their new balance:

void VoteSystem_OnGivePoint(ulong playerId, string site, int givedPoints, int totalPointsSite)
{
    BasePlayer player = BasePlayer.FindByID(playerId);
    if (player != null)
    {
        player.ChatMessage($"Thank you for voting on {site}! You received {givedPoints} points. Total points: {totalPointsSite}");
    }
}

6. Conclusion

By following this tutorial, you've created a "Vote Rewards Shop" extension for the VoteSystem plugin using Oxide. Players can now earn points by voting and spend these points in the shop for in-game items. This is a basic example, and you can further develop the shop, add other features, or integrate other plugins as per your requirements.

Last updated