1. Karltubing

    Karltubing Scavenger

    I have been trying to figure out how to do this... I would like to take information from SavedTradeWalletById.json (from GrandExchange.cs) and the information from SavedPlayersInfos.json to make custom list with all the info so I can make a "Top Richest Players" (use "TopGold" as the command) to open a popup or list in chat. I have been modifying plugins but have limited experience and am not sure if I should try a stand alone .cs and reference the GrandExchange.cs or just add code to the GrandExchange.cs . . Any help would be appreciated.
     
  2. Karltubing

    Karltubing Scavenger

    I think I need to make a new list converting the steam.id of a player to his name, from that make a new list ascending or descending based on Gold amount. Would the new list have to have Gold amount as first item then name?
     
  3. Karltubing

    Karltubing Scavenger

    Everytime I start with

    using System.Collections.Generic;
    using System.ComponentModel;
    using System;
    using System.Collections.Generic;
    using System.Linq;

    namespace Oxide.Plugins
    {
    [Info("TopPlayers", "Karltubing", "1.1.1")]
    [Description("Show Servers TopPlayers")]

    public class TopPlayers : ReignOfKingsPlugin

    I get this

    Severity Code Description Project File Line Suppression State
    Error CS1729 'InfoAttribute' does not contain a constructor that takes 3 arguments TopPlayers C:\Users\kphex\Source\Repos\Oxide\TopPlayers\TopPlayers\Class1.cs 9 Active

    Has the plugin structure changed? this Visual Studio 2015 is confusing as hell . I was doing better hacking at existing plugins with Notepad ++.
     
  4. Mughisi

    Mughisi Grenade Master Community Mod Oxide Developer

    Have a look at Setting up a C# workspace in Visual Studio 2015 | Oxide
     
  5. Karltubing

    Karltubing Scavenger

    I have it set up, both ways, like Wolf posted and like Vilsol suggested. I have played with it I cant get a "HelloWorld I am A plugin noob" test plugin to run........
     
  6. Wulf

    Wulf Community Admin Community Admin Oxide Developer

    Could you upload the entire plugin please or use the [ code ] tags?
     
  7. Karltubing

    Karltubing Scavenger

    I am making progress...... I deleted all that , got D-Kay to give some advice on VS 2015 , starting to come together now. I have since then copied "calling an Api method " from the docs page to give me an outline. I didn't understand ( still may not) where to start, with class library or just a class etc. I have had success modifying existing plugins but had no clue how to start a plugin from scratch. I am sure I will be back looking for help later.
     
  8. Karltubing

    Karltubing Scavenger

    Ok here is my attempt at calling/referencing a plugin (GrandExchange) to remove gold from a players wallet when doing damage. I am down to one error "an object reference is required for a non-static field"



    Code (Text):

    using System;
    using CodeHatch.Blocks.Networking.Events;
    using CodeHatch.Engine.Networking;
    using Oxide.Core.Plugins;
    using Oxide.Core;
    using System.Collections.Generic;
    using CodeHatch.Common;

    namespace Oxide.Plugins
    {
        [Info("DamageGold", "Karltubing", 0.1)]
        [Description("Makes players pay for damages caused to blocks")]

        class DamageGold : CovalencePlugin
        {
            // First, add a reference to the plugin you are trying to call
            // The name of this field needs to be the exact name of the desired plugin
            // eg. We are referencing the example plugin above which is called 'EpicPlugin'
            [PluginReference]
            Plugin GrandExchange;

            // It's a good idea to check if the plugin you're trying to call
            // has been loaded by oxide (otherwise you can't call the method)
            void OnServerInitialized()
            {
                // Note: Trying to do this check in the plugin Init() method may
                // fail, as the plugin load order may be different each time
                if (GrandExchange == null)
                {
                    PrintWarning("Plugin 'GrandExchange' was not found!");
                }
            }

            void CallApi()
            {
                // Plugin methods return objects, so cast the API call to the type
                // you're expecting
                //var getTypedReturn = (bool)GrandExchange?.Call("GetReturn");

                // Send parameters through as variables after the method name
                //var takeParam = (string)GrandExchange?.Call("TakeParam", "param1", 1024);

                // Use JSON.net to process the returned object
                //var returnedObject = GrandExchange?.Call("ReturnObject");

                // Call a plugin to do some work without returning anything
                GrandExchange?.Call("RemoveGold");
            }

            //void OnCubeTakeDamage(CubeDamageEvent evt)
            //{
            //    Puts("OnCubeTakeDamage works!");

            private void SendHelpText(Player player)
            {
                PrintToChat(player, "[0000FF]Damage Gold[FFFFFF]");

                if (player.HasPermission("admin"))
                {
                    PrintToChat(player, "[00FF00]/dmggold[FFFFFF] - Toggle paying gold for damages on / off");
                }

            }

            private void PrintToChat(Player player, string v)
            {
                throw new NotImplementedException();
            }

            #region MODIFIABLE VARIABLES (For server admin)

            private bool _allowDmgGold = true; // Turns on/off gold for DMG

            #endregion

            #region Server Variables

            private readonly System.Random _random = new System.Random();
            void Log(string msg) => Puts($"{Title} : {msg}");
            private const int MaxPossibleGold = 2100000000; // DO NOT RAISE THIS ANY HIGHER - 32-bit INTEGER FLOOD WARNING
            private const int GoldRewardForPve = 20; // This is the maximum amount rewarded to a player for killing monsters, etc. (When harvesting the dead body)  
            private Dictionary<ulong, int> _playerWallet;
            private Dictionary<string, int> _wallet;

            #endregion

            #region Save and Load Data Methods

            // SAVE DATA ===============================================================================================
            private void LoadTradeData()
            {
                _allowDmgGold = Interface.GetMod().DataFileSystem.ReadObject<bool>("SavedDmGGoldStatus");
                _playerWallet = Interface.GetMod().DataFileSystem.ReadObject<Dictionary<ulong, int>>("SavedTradeWalletById");
                _wallet = Interface.GetMod().DataFileSystem.ReadObject<Dictionary<string, int>>("SavedTradeWallet");
            }

            private void SaveTradeData()
            {
                Interface.GetMod().DataFileSystem.WriteObject("SavedDmGGoldStatus", _allowDmgGold);
                Interface.GetMod().DataFileSystem.WriteObject("SavedTradeWalletById", _playerWallet);
                Interface.GetMod().DataFileSystem.WriteObject("SavedTradeWallet", _wallet);
            }

            #endregion

            #region User Commands

            // Enable the DmG gold paying
            [ChatCommand("dmggold")]
            private void AllowGoldForDmG(Player player, string cmd)
            {
                ToggleDmgGoldPaying(player, cmd);
            }

            #endregion

            #region GOLD AND CURRENCY

            private void ToggleDmgGoldPaying(Player player, string cmd)
            {

                if (_allowDmgGold)
                {
                    _allowDmgGold = false;
                    PrintToChat(player, "DmG gold paying is now [FF0000]OFF");
                    return;
                }
                _allowDmgGold = true;
                PrintToChat(player, "DmG gold paying is now [00FF00]ON");
                SaveTradeData();
            }

            #endregion

            private void RemoveGold(Player player, int amount)
            {
                var currentGold = _playerWallet[player.Id];
                currentGold = currentGold - amount;

                _playerWallet[player.Id] = currentGold;
            }

            private void RemoveGold(ulong playerId, int amount)
            {
                var currentGold = _playerWallet[playerId];
                currentGold = currentGold - amount;
                NewMethod(playerId, currentGold);
            }

            private static void NewMethod(ulong playerId, object currentGold)
            {
                _playerWallet[playerId] = currentGold;
            }

            // DmgGold By Karltubing Pay Gold For Damaging Blocks
            private void  OnCubeTakeDamage(CubeDamageEvent cubeDamageEvent)
            {

                if(!_allowDmgGold)
                {
                    if (cubeDamageEvent.Damage.Amount > 1 && cubeDamageEvent.Damage.DamageSource.Owner is Player)
                        {
                            cubeDamageEvent.Damage.Amount = 0f;
                        }
                }

                if(_allowDmgGold)
                {
                    if (cubeDamageEvent.Damage.Amount <= 49 && cubeDamageEvent.Damage.DamageSource.Owner is Player)
                    {
                        var player = cubeDamageEvent.Damage.DamageSource.Owner;
                        var playerGold = _playerWallet[player.Id];
                        if (playerGold < 0) cubeDamageEvent.Damage.Amount = 0f;
                        var goldAmount = _random.Next(2,GoldRewardForPve);
                        RemoveGold(player,goldAmount);
                        // Notify everyone
                        PrintToChat(player, "[00FF00]" + goldAmount.ToString() + "[FFFF00] gold[FF0000] Paid.");

                        SaveTradeData();
                     }
                     else
                     {
                         var player = cubeDamageEvent.Damage.DamageSource.Owner;
                         var playerGold = _playerWallet[player.Id];
                         if (playerGold < 0) cubeDamageEvent.Damage.Amount = 0f;
                         var goldAmount = ((int) (cubeDamageEvent.Damage.Amount) /2 );
                         RemoveGold(player,goldAmount);

                         // Notify everyone
                         PrintToChat(player, "[00FF00]" + goldAmount.ToString() + "[FFFF00] gold[FF0000] Paid.");

                         SaveTradeData();
                     }
                 }

            }
        }
    }
     
     
  9. Karltubing

    Karltubing Scavenger

    D-Kay helped me out