Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UserMessage missing ReadMessage/ReadRepeatedMessage/AddMessage methods #668

Open
BeepIsla opened this issue Nov 12, 2024 · 2 comments
Open
Labels
untriaged New issue has not been triaged

Comments

@BeepIsla
Copy link

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?

// public UserMessage ReadMessage(string fieldName) => NativeAPI.PbReadmessage(this, fieldName);
// public UserMessage ReadRepeatedMessage(string fieldName, int index ) => NativeAPI.PbReadrepeatedmessage(this, fieldName, index);
// public UserMessage AddMessage(string fieldName) => NativeAPI.PbAddmessage(this, fieldName);

@github-actions github-actions bot added the untriaged New issue has not been triaged label Nov 12, 2024
@KillStr3aK
Copy link
Contributor

Hey!
They are not finished yet, require more work to do

@Prefix
Copy link

Prefix commented Jan 9, 2025

image
+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);
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
untriaged New issue has not been triaged
Projects
None yet
Development

No branches or pull requests

3 participants