Adding a Ban / Kick reasonSolved

Hey,

So I tried to add a ban/kick reason to each ban/kick.

But I don't get it to work.
I added on the Player Info Panel an Input looks like this: 


5d5c200d9bd04b7e93d682668d8d0f49.png
https://gyazo.com/5d5c200d9bd04b7e93d682668d8d0f49

And now I want to send the Input as a Ban message to the Ban/kick function!

Which I don't get to work.

Maybe someone has an idea?

Regards,

SkillerFreak


Well, you could share what you changed. From there I can help you. ;)
Hey,

first of all thanks for helping!

Input on the Player site:
aUIObj.AddInputField(panelBanByIdGroup, CMainPageEdtBanByIdLbAnchor, CMainPageEdtBanByIdRtAnchor, CuiDefaultColors.TextAlt, string.Empty, 24,
                CBanReasonInputTextCmd);​

Ban Button:

            if (VerifyPermission(aUiUserId, CPermBan)) {
                aUIObj.AddButton(aParent, CUserPageBtnBanLbAnchor, CUserPageBtnBanRtAnchor, CuiDefaultColors.ButtonDanger, CuiDefaultColors.TextAlt,
                                 GetMessage("Ban Button Text", aUiUserId), $"{CBanUserwithreasonCmd} {aPlayerId}");
            } else {
                aUIObj.AddButton(aParent, CUserPageBtnBanLbAnchor, CUserPageBtnBanRtAnchor, CuiDefaultColors.ButtonInactive, CuiDefaultColors.Text,
                                 GetMessage("Ban Button Text", aUiUserId));
            }


Console Command:

[ConsoleCommand(CBanUserwithreasonCmd)]
        private void AdminToolBanUsewithreasonrCallback(ConsoleSystem.Arg aArg)
        {
            LogDebug("AdminToolBanUsewithreasonrCallback was called");
            BasePlayer player = aArg.Player();
            ulong targetId;

            if (!VerifyPermission(ref player, CPermBan, true) || !GetTargetFromArg(ref aArg, out targetId))
                return;
            
            string banReasonMsg = CBanReasonInputTextCmd;
            
            Player.Ban(targetId, banReasonMsg);
            ServerUsers.User targetPlayer = ServerUsers.Get(targetId);
            LogInfo($"{player.displayName}: Banned user ID {targetId}");
            SendDiscordKickBanMessage(player.displayName, player.UserIDString, targetPlayer.username, targetId.ToString(), banReasonMsg, true);
            BuildUI(player, UiPage.PlayerPage, targetId.ToString());
        }

New CUI settings:

        private readonly CuiPoint CUserPageBtnBanLbAnchor = new CuiPoint(0.49f, 0.86f);
        private readonly CuiPoint CUserPageBtnBanRtAnchor = new CuiPoint(0.64f, 0.92f);
        private readonly CuiPoint CUserPageBtnKickLbAnchor = new CuiPoint(0.65f, 0.86f);
        private readonly CuiPoint CUserPageBtnKickRtAnchor = new CuiPoint(0.80f, 0.92f);

        private readonly CuiPoint CUserPageInputReasonLbAnchor = new CuiPoint(0.01f, 0.86f);
        private readonly CuiPoint CUserPageInputReasonRtAnchor = new CuiPoint(0.32f, 0.92f);


That's it hopefully you can help me with that :)

Regards

SkillerFreak

You'll also need to define the text callback.
If you look at existing solutions, such as PlayerAdministrationMainPageBanIdInputTextCallback and CMainPageBanByIdCmd you will get an idea of how I managed to do it.
In response to ThibmoRozier ():
You'll also need to define the text callback.
If you look at existing solutions, such as Player...
This is exactly the point which I don't get.
Would be really cool if you could help me with that :)
It's not too complicated.
The text is entered client-side and the mod runs server-side. For the script to know what the client typed there must be a callback routine. It is sorta like the OnKeyDown event for a normal C# forms component, but here we need to store the updated text server-side.

So we add the text to a dictionary, keyed by the user's ID. :)
In response to ThibmoRozier ():
It's not too complicated.
The text is entered client-side and the mod runs server-side. For the...
I am sorry,
I legit don't understand what you mean.
I am new to coding :/


sry for that
In response to Freakyy ():
I am sorry,
I legit don't understand what you mean.
I am new to coding :/


I hope this helps:
In response to ThibmoRozier ():
I hope this helps:
Might want to check that image URL. ;) Seems to be private.
In response to Wulf ():
Might want to check that image URL. ;) Seems to be private.
Updated with an imgur... Guess LightShot doesn't like people embededing the screenshots... O.o
I tried some options over and over again. But I don't get it to work.

Anyways thanks for the help
In response to Freakyy ():
I tried some options over and over again. But I don't get it to work.

Anyways thanks for...
Thing is, because you said you're quite new to coding, I don't want to just give the full solution. Allowing you to find the solution yourself is more educational then copy-paste work ;)
In response to ThibmoRozier ():
Thing is, because you said you're quite new to coding, I don't want to just give the full solution....
This is actually a good point. And also a good way of thinking.

But I am sitting here since ~ 3days now and didn't manage to get it work.
In response to Freakyy ():
This is actually a good point. And also a good way of thinking.

But I am sitting here sin...

Oh I've felt this a lot myself during my early days, too. And still at times.
But I think this flow might show you what you need.

Will this be added into the new update?
Locked automatically