RaphaelIT7 / gmod-holylib

A library that contains some functions and optimizations for gmod.
42 stars 4 forks source link

SourceTV set camera man #14

Open Glebux opened 1 week ago

Glebux commented 1 week ago

Make it possible to properly set the current camera man with sourcetv.SetCameraMan, And also call a hook "HolyLib:ShouldBecomeCameraMan" when a spectator presses the USE key, as the valve dev wiki stated.

RaphaelIT7 commented 1 week ago

per player or globally? Also I think setting the spectator should already be possible like this:

-- Note: This is just and Idea and untested
hook.Add("HolyLib:OnSourceTVCommand", "Example", function(client, name, args, argString)
    if name == "Spectate" then
        local event = gameevent.Create("hltv_changed_target")
        event:SetInt("mode", OBS_MODE_CHASE)
        event:SetInt("obs_target", player.GetBySteamID(args[1]))
        event:SetInt("old_target", 0) -- Is this even required? idk
        client:FireEvent(event)
        return true
    end
end)

But I will definetly add a proper function so that the engine won't override anything possibly.

Glebux commented 1 week ago

The function should set the camera man globally, yes. But if the user wants more control then something like the pseudo code you provided would certainly do.

Glebux commented 1 week ago

I've done some testing, and it turns out that "hltv_changed_target" fails to initiate, and "hltv_cameraman" is what exactly needed. Also after a few seconds the autodirector regains control of the camera, so a think function for hltv clients would be also required.

RaphaelIT7 commented 1 week ago

I added the HolyLib:OnSourceTVStartNewShot to allow one to cancel it changing the shot. Simply return true in the hook to cancel it.