Kits with server rewards is allowing players to go negative rp

is this just me? they buy kits, even though they have no reward points

I have the same problem, I'm not a developer, but it seems to be an issue with the Kits plugin. The ServerRewards cancels transactions with insufficient RP points.

i am sure there is a more elegant way, but the check for taking rp, was being given without checking if they had the rp give.
I added this. The problem is that the TakePoints call made to the ServerRewards plugin, does not return false, unless the user does not exist. So it was always returning true, and then kits would give them the kit, thinking they could afford it. fix is below
right at the top around line 37

#region Oxide Hooks
#region Methods

//added by phatblinkie as players could take kits with no balance
public bool TakeRP(ulong player, int amount)
{
int startamount = (int)ServerRewards?.Call("CheckPoints", player);
if ((startamount - amount) < 0)
{
return false;
}
object x = ServerRewards?.Call("TakePoints", player, amount);
int endamount = (int)ServerRewards?.Call("CheckPoints", player);
Puts($"deducting for a kit: '{amount}' from user '{player}' starting balance: '{startamount}', ending balance:'{endamount}'");
bool result = Convert.ToBoolean(x);
return result;
}

then around line 283, comment out the normal call to server rewards and replace it with the local method TakeRP
case CostType.ServerRewards:
//return (bool)ServerRewards?.Call("TakePoints", player.userID, amount);
return (bool)TakeRP(player.userID, amount);

Hey,

Can you pastebin the fixed code? im getting:

Error while compiling: Kits.cs(3437,1): error CS1038: #endregion directive expected

Thx!

yeah i got that too, was not sure if it was just me so didnt add that line
under line 33 make it look like this (add the endregion) orig

        #region Oxide Hooks
        #region Methods

modded

        #region Oxide Hooks
        #endregion
        #region Methods

Great Workaround!

this works for me

Nevertheless, I cannot understand why this problem only arose now or why it is only now noticeable.

Greetings
Sepron

 

I keep getting the Error while compiling: Kits.cs(3437,1): error CS1038: #endregion directive expected 

anyone able to give me an idea how to add the code in please 

see my post 2 above this, you need to edit the file and add the #endregion

Was making the mistake with the part near line 283 worked it out thank you 

phatblinkie

i am sure there is a more elegant way, but the check for taking rp, was being given without checking if they had the rp give.
I added this. The problem is that the TakePoints call made to the ServerRewards plugin, does not return false, unless the user does not exist. So it was always returning true, and then kits would give them the kit, thinking they could afford it. fix is below
right at the top around line 37

#region Oxide Hooks
#region Methods

//added by phatblinkie as players could take kits with no balance
public bool TakeRP(ulong player, int amount)
{
int startamount = (int)ServerRewards?.Call("CheckPoints", player);
if ((startamount - amount) < 0)
{
return false;
}
object x = ServerRewards?.Call("TakePoints", player, amount);
int endamount = (int)ServerRewards?.Call("CheckPoints", player);
Puts($"deducting for a kit: '{amount}' from user '{player}' starting balance: '{startamount}', ending balance:'{endamount}'");
bool result = Convert.ToBoolean(x);
return result;
}

then around line 283, comment out the normal call to server rewards and replace it with the local method TakeRP
case CostType.ServerRewards:
//return (bool)ServerRewards?.Call("TakePoints", player.userID, amount);
return (bool)TakeRP(player.userID, amount);

WHere at in the server rewards does this go?, im having the same problem with players buying kits and going into the negative rp. I thought that couldnt happen but after the underwater labs update alot of things got messed up. my new players dont recieve the begining rp so i have to do it manually until i can get that fixed.

@phatblinkie thank you this works and fixed the issue. I think the k1lly0u should add this fix to the plugin as it works well. One thing though - you forgot to add and extra #endregion to close the added #region Methods and the plugin won't work without it. Final results should look like this:

        #region Oxide Hooks
	#region Methods
		
		//added by phatblinkie as players could take kits with no balance
		public bool TakeRP(ulong player, int amount)
		{
		int startamount = (int)ServerRewards?.Call("CheckPoints", player);
		if ((startamount - amount) < 0)
		{
		return false;
		}
		object x = ServerRewards?.Call("TakePoints", player, amount);
		int endamount = (int)ServerRewards?.Call("CheckPoints", player);
		Puts($"deducting for a kit: '{amount}' from user '{player}' starting balance: '{startamount}', ending balance:'{endamount}'");
		bool result = Convert.ToBoolean(x);
		return result;
		}
		
        private void Loaded()
        {
            LoadData();

            permission.RegisterPermission(ADMIN_PERMISSION, this);
            kitData.RegisterPermissions(permission, this);

            _costType = ParseType<CostType>(Configuration.Currency);

            cmd.AddChatCommand(Configuration.Command, this, cmdKit);
            cmd.AddConsoleCommand(Configuration.Command, this, "ccmdKit");
        }

        protected override void LoadDefaultMessages() => lang.RegisterMessages(Messages, this);

        private void OnServerInitialized()
        {
            LastWipeTime = SaveRestore.SaveCreatedTime.Subtract(Epoch).TotalSeconds;

            kitData.RegisterImages(ImageLibrary);

            if (Configuration.AutoKits.Count == 0)
                Unsubscribe(nameof(OnPlayerRespawned));
        }

        private void OnNewSave(string filename)
        {
            if (Configuration.WipeData)
                playerData.Wipe();
        }

        private void OnServerSave() => SavePlayerData();

        private void OnPlayerRespawned(BasePlayer player)
        {
            if (player == null)
                return;

            if ((Interface.Oxide.CallDeprecatedHook("canRedeemKit", "CanRedeemKit", _deprecatedHookTime, player) ?? Interface.Oxide.CallHook("CanRedeemKit", player)) != null)
                return;

            if (Configuration.AllowAutoToggle && !playerData[player.userID].ClaimAutoKits)
            {
                player.ChatMessage(Message("Error.AutoKitDisabled", player.userID));
                return;
            }

            for (int i = 0; i < Configuration.AutoKits.Count; i++)
            {
                KitData.Kit kit;
                if (!kitData.Find(Configuration.AutoKits[i], out kit))
                    continue;

                object success = CanClaimKit(player, kit, true);
                if (success != null)
                    continue;

                player.inventory.Strip();

                success = GiveKit(player, kit);
                if (success is string)
                    continue;

                OnKitReceived(player, kit);
                return;
            }
        }

        private object OnServerCommand(ConsoleSystem.Arg arg)
        {
            BasePlayer player = arg.Player();
            if (player == null)
                return null;

            if (_kitCreators.ContainsKey(player.userID) && !arg.cmd.FullName.StartsWith("kits."))
                return false;

            return null;
        }

        private object OnPlayerCommand(BasePlayer player, string s, string[] args) => _kitCreators.ContainsKey(player.userID) ? (object)false : null;

        private void Unload()
        {
            if (!Interface.Oxide.IsShuttingDown)
                SavePlayerData();

            foreach (BasePlayer player in BasePlayer.activePlayerList)
            {
                CuiHelper.DestroyUi(player, UI_MENU);
                CuiHelper.DestroyUi(player, UI_POPUP);
            }

            Configuration = null;
        }
        #endregion
	#endregion​


and then of course the replacement at the end:

Replace:

return (bool)ServerRewards?.Call("TakePoints", player.userID, amount);

With:

return (bool)TakeRP(player.userID, amount);​
nU9XxVFlxdpHfyW.jpg mic773

@phatblinkie thank you this works and fixed the issue. I think the k1lly0u should add this fix to the plugin as it works well. One thing though - you forgot to add and extra #endregion to close the added #region Methods and the plugin won't work without it. Final results should look like this:

        #region Oxide Hooks
	#region Methods
		
		//added by phatblinkie as players could take kits with no balance
		public bool TakeRP(ulong player, int amount)
		{
		int startamount = (int)ServerRewards?.Call("CheckPoints", player);
		if ((startamount - amount) < 0)
		{
		return false;
		}
		object x = ServerRewards?.Call("TakePoints", player, amount);
		int endamount = (int)ServerRewards?.Call("CheckPoints", player);
		Puts($"deducting for a kit: '{amount}' from user '{player}' starting balance: '{startamount}', ending balance:'{endamount}'");
		bool result = Convert.ToBoolean(x);
		return result;
		}
		
        private void Loaded()
        {
            LoadData();

            permission.RegisterPermission(ADMIN_PERMISSION, this);
            kitData.RegisterPermissions(permission, this);

            _costType = ParseType<CostType>(Configuration.Currency);

            cmd.AddChatCommand(Configuration.Command, this, cmdKit);
            cmd.AddConsoleCommand(Configuration.Command, this, "ccmdKit");
        }

        protected override void LoadDefaultMessages() => lang.RegisterMessages(Messages, this);

        private void OnServerInitialized()
        {
            LastWipeTime = SaveRestore.SaveCreatedTime.Subtract(Epoch).TotalSeconds;

            kitData.RegisterImages(ImageLibrary);

            if (Configuration.AutoKits.Count == 0)
                Unsubscribe(nameof(OnPlayerRespawned));
        }

        private void OnNewSave(string filename)
        {
            if (Configuration.WipeData)
                playerData.Wipe();
        }

        private void OnServerSave() => SavePlayerData();

        private void OnPlayerRespawned(BasePlayer player)
        {
            if (player == null)
                return;

            if ((Interface.Oxide.CallDeprecatedHook("canRedeemKit", "CanRedeemKit", _deprecatedHookTime, player) ?? Interface.Oxide.CallHook("CanRedeemKit", player)) != null)
                return;

            if (Configuration.AllowAutoToggle && !playerData[player.userID].ClaimAutoKits)
            {
                player.ChatMessage(Message("Error.AutoKitDisabled", player.userID));
                return;
            }

            for (int i = 0; i < Configuration.AutoKits.Count; i++)
            {
                KitData.Kit kit;
                if (!kitData.Find(Configuration.AutoKits[i], out kit))
                    continue;

                object success = CanClaimKit(player, kit, true);
                if (success != null)
                    continue;

                player.inventory.Strip();

                success = GiveKit(player, kit);
                if (success is string)
                    continue;

                OnKitReceived(player, kit);
                return;
            }
        }

        private object OnServerCommand(ConsoleSystem.Arg arg)
        {
            BasePlayer player = arg.Player();
            if (player == null)
                return null;

            if (_kitCreators.ContainsKey(player.userID) && !arg.cmd.FullName.StartsWith("kits."))
                return false;

            return null;
        }

        private object OnPlayerCommand(BasePlayer player, string s, string[] args) => _kitCreators.ContainsKey(player.userID) ? (object)false : null;

        private void Unload()
        {
            if (!Interface.Oxide.IsShuttingDown)
                SavePlayerData();

            foreach (BasePlayer player in BasePlayer.activePlayerList)
            {
                CuiHelper.DestroyUi(player, UI_MENU);
                CuiHelper.DestroyUi(player, UI_POPUP);
            }

            Configuration = null;
        }
        #endregion
	#endregion​

and then of course the replacement at the end:

Replace:

return (bool)ServerRewards?.Call("TakePoints", player.userID, amount);

With:

return (bool)TakeRP(player.userID, amount);​
Are you willing to send me the working .cs file? I cant locate this code my line 37 looks nothing like here. If you're willing my discord is Seawheels#2408

Thanks.

yeah a whole new .cs file would be great having same issue

Merged post

[email protected] if anyone has thanks in advance

Is there a more simple option? Some servers you can't go negative RP using the kits.

it is a server reward issue not kits