roflmuffin / CounterStrikeSharp

CounterStrikeSharp allows you to write server plugins in C# for Counter-Strike 2/Source2/CS2
https://docs.cssharp.dev
Other
763 stars 116 forks source link

is there like a "OnClientCommand" #580

Open 2vg opened 6 days ago

2vg commented 6 days ago

I didn't know how to catch the event when the client sends the command. What I want to do is that there are times when I need to set sv_cheats to 1 for some cvars that the map changes on its own, so I want to catch such an event and temporarily enable sv_cheats. (This is mainly useful on minigame maps) At first, I thought of catching the server_cvar event, but if sv_cheats is disabled, cvar is not changed, so no event is issued, so I could not catch it. I wish there was something like OnClientCommand, but if there is another way please let me know, Thanks!

2vg commented 4 days ago

okey, i was finally able to accomplish what i wanted on my own. even if remove the cheat flag from the cvar, the FakeConvar system will still detect the cheat flag so this solution is not useful. Also, for some reason EntityOutputHook for point_servercommand and logic_auto does not work. like this:

[EntityOutputHook("point_servercommand(or, logic_auto)", "*")]
public HookResult OnHook(CEntityIOOutput output, string name, CEntityInstance activator, CEntityInstance caller, CVariant value, float delay)
{
    Logger.LogInformation("[EntityOutputHook Attribute] point_servercommand with ({name}, {activator}, {caller}, {delay})", name, activator.DesignerName, caller.DesignerName, delay);

    return HookResult.Continue;
}

in the end, i decided to put a hook on all entities and check the output target type. i may be doing something wrong or there may be another way, so i will leave the issue open for now.