CounterStrikeSharp
CounterStrikeSharp copied to clipboard
`UserMessage` missing `ReadMessage`/`ReadRepeatedMessage`/`AddMessage` methods
Hello,
some usermessages have nested protobuf types, how would we access those?
I saw they are commented out, was this done for any particular reason or simply forgotten?
https://github.com/roflmuffin/CounterStrikeSharp/blob/1f904a52a7a41558128cd360e82c89562848c066/managed/CounterStrikeSharp.API/Modules/UserMessages/UserMessage.cs#L80-L82
Hey! They are not finished yet, require more work to do
+1 on this. would need this for usage for Replicated convars to show env_instructor_hint
public void Command_DisplayHint(CCSPlayerController? playerController, CommandInfo info)
{
if (playerController == null) return;
if (!playerController.IsReal()) return;
// Example parameters for the hint
float time = 10.0f;
float height = 50.0f;
float range = 1000.0f;
bool follow = true;
bool showOffScreen = true;
string iconOnScreen = "icon_bulb";
string iconOffScreen = "icon_arrow_up";
string cmd = "use_binding";
bool showTextAlways = false;
Color color = Color.FromArgb(255, 255,0,0);
string text = "This is a hint!";
UserMessage um = UserMessage.FromId(6);
SubPbMessage convars = um.ReadMessage("convars");
SubPbMessage cvar = convars.AddMessage("cvars");
cvar.SetString("name", "sv_gameinstructor_enable");
cvar.SetString("value", "true");
um.Send(playerController);
DisplayInstructorHint(playerController, time, height, range, follow, showOffScreen, iconOnScreen, iconOffScreen, cmd, showTextAlways, color, text);
}
private void DisplayInstructorHint(CCSPlayerController targetEntity, float time, float height, float range, bool follow, bool showOffScreen, string iconOnScreen, string iconOffScreen, string cmd, bool showTextAlways, Color color, string text)
{
// Implementation of the SourceMod HUD text functionality
CEnvInstructorHint entity = Utilities.CreateEntityByName<CEnvInstructorHint>("env_instructor_hint")!;
if (entity == null) return;
string buffer = targetEntity.Index.ToString();
// Target
entity.Target = buffer;
entity.HintTargetEntity = buffer;
// Static
entity.Static = follow;
// Timeout
buffer = ((int)time).ToString();
entity.Timeout = (int)time;
//if (time > 0.0f) RemoveEntity(entity, time);
// Height
entity.IconOffset = height;
// Range
entity.Range = range;
// Show off screen
entity.NoOffscreen = showOffScreen;
// Icons
entity.Icon_Onscreen = iconOnScreen;
entity.Icon_Offscreen = iconOffScreen;
// Command binding
entity.Binding = cmd;
// Show text behind walls
entity.ForceCaption = showTextAlways;
// Text color
entity.Color = color;
// Text
text = text.Replace("\n", " ");
entity.Caption = text;
entity.DispatchSpawn();
entity.AcceptInput("ShowHint");
}
private void RemoveEntity(CEnvInstructorHint entity, float time = 0.0f)
{
if (time == 0.0f)
{
if (entity.IsValid)
{
entity.AcceptInput("Kill");
}
}
else if (time > 0.0f)
{
_base!.AddTimer(time, () =>
{
if (entity.IsValid)
{
entity.AcceptInput("Kill");
}
}, TimerFlags.STOP_ON_MAPCHANGE);
}
}