From b1c2a0def89f6953e57aedf86fb69fa6af103524 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 28 Aug 2019 18:49:19 +1000 Subject: [PATCH] Adjust crosshair position while in third person mode, make the player invisible while they obstruct the view --- crosshairs.cfg | 4 ++++ qcsrc/client/autocvars.qh | 2 ++ qcsrc/client/view.qc | 14 ++++++++++++++ qcsrc/common/csqcmodel_settings.qh | 7 ++++++- qcsrc/lib/csqcmodel/cl_model.qc | 3 +++ qcsrc/lib/csqcmodel/cl_model.qh | 3 ++- qcsrc/lib/csqcmodel/sv_model.qc | 6 +++++- qcsrc/lib/csqcmodel/sv_model.qh | 4 +++- 8 files changed, 39 insertions(+), 4 deletions(-) diff --git a/crosshairs.cfg b/crosshairs.cfg index 8e7bc9b4f..82758fa70 100644 --- a/crosshairs.cfg +++ b/crosshairs.cfg @@ -48,6 +48,10 @@ seta crosshair_per_weapon 1 "when 1, each gun will display a different crosshair // side-scrolling crosshair seta crosshair_2d 54 "selects crosshair to use in side-scrolling mode (\"\" uses regular crosshair and 0 is none)" +// third person chase-camera crosshair +seta crosshair_chase 1 "adjust the crosshair while in third person mode to where the shot will actually hit" +seta crosshair_chase_playeralpha 0.25 "opacity of the player while they obstruct the view when crosshair_chase is enabled, can be a value between 0 and 1" + // ========================= // Crosshair ring settings diff --git a/qcsrc/client/autocvars.qh b/qcsrc/client/autocvars.qh index c372be250..a151c0c40 100644 --- a/qcsrc/client/autocvars.qh +++ b/qcsrc/client/autocvars.qh @@ -150,6 +150,8 @@ bool autocvar_crosshair_ring_reload; float autocvar_crosshair_ring_reload_alpha; float autocvar_crosshair_ring_reload_size; float autocvar_crosshair_size; +bool autocvar_crosshair_chase = true; +float crosshair_chase_playeralpha = 0.25; int autocvar_ekg; float autocvar_fov; bool autocvar_hud_cursormode = true; diff --git a/qcsrc/client/view.qc b/qcsrc/client/view.qc index 744c54792..917d795ca 100644 --- a/qcsrc/client/view.qc +++ b/qcsrc/client/view.qc @@ -974,6 +974,20 @@ void HUD_Crosshair(entity this) // wcross_origin = '0.5 0 0' * vid_conwidth + '0 0.5 0' * vid_conheight; if(csqcplayer.viewloc && (csqcplayer.viewloc.spawnflags & VIEWLOC_FREEAIM)) wcross_origin = viewloc_mousepos; + else if(autocvar_chase_active && autocvar_crosshair_chase) + { + vector player_org = ((csqcplayer) ? csqcplayer.origin + csqcplayer.view_ofs : view_origin); + if(csqcplayer && crosshair_chase_playeralpha && crosshair_chase_playeralpha < 1) + { + traceline(view_origin, view_origin + max_shot_distance * view_forward, MOVE_NORMAL, NULL); + if(trace_ent == csqcplayer) + csqcplayer.alpha = crosshair_chase_playeralpha; + else + csqcplayer.alpha = csqcplayer.m_alpha; + } + traceline(player_org, player_org + max_shot_distance * view_forward, MOVE_WORLDONLY, NULL); + wcross_origin = project_3d_to_2d(trace_endpos); + } else wcross_origin = project_3d_to_2d(view_origin + max_shot_distance * view_forward); wcross_origin.z = 0; diff --git a/qcsrc/common/csqcmodel_settings.qh b/qcsrc/common/csqcmodel_settings.qh index 7c5a218b2..96836a38e 100644 --- a/qcsrc/common/csqcmodel_settings.qh +++ b/qcsrc/common/csqcmodel_settings.qh @@ -18,12 +18,17 @@ # define TAG_VIEWLOC_NAME tag_networkviewloc # define TAG_VIEWLOC_TYPE int .float tag_networkviewloc; + +# define ALPHA m_alpha +.float m_alpha; #else # define TAG_ENTITY_NAME tag_entity # define TAG_ENTITY_TYPE entity # define TAG_VIEWLOC_NAME viewloc # define TAG_VIEWLOC_TYPE entity + +# define ALPHA alpha #endif // add properties you want networked to CSQC here @@ -31,7 +36,7 @@ CSQCMODEL_PROPERTY(BIT(0), int, ReadShort, WriteShort, colormap) \ CSQCMODEL_PROPERTY(BIT(1), int, ReadInt24_t, WriteInt24_t, effects) \ CSQCMODEL_PROPERTY(BIT(2), int, ReadByte, WriteByte, modelflags) \ - CSQCMODEL_PROPERTY_SCALED(BIT(3), float, ReadByte, WriteByte, alpha, 254, -1, 254) \ + CSQCMODEL_PROPERTY_SCALED(BIT(3), float, ReadByte, WriteByte, ALPHA, 254, -1, 254) \ CSQCMODEL_PROPERTY(BIT(4), int, ReadByte, WriteByte, skin) \ CSQCMODEL_PROPERTY(BIT(5), float, ReadApproxPastTime, WriteApproxPastTime, death_time) \ CSQCMODEL_PROPERTY(BIT(6), float, ReadByte, WriteByte, solid) \ diff --git a/qcsrc/lib/csqcmodel/cl_model.qc b/qcsrc/lib/csqcmodel/cl_model.qc index 12be0dbaa..ccf675117 100644 --- a/qcsrc/lib/csqcmodel/cl_model.qc +++ b/qcsrc/lib/csqcmodel/cl_model.qc @@ -277,6 +277,9 @@ NET_HANDLE(ENT_CLIENT_MODEL, bool isnew) this.csqcmodel_teleported = 1; } + if(sf & BIT(3)) + this.alpha = this.m_alpha; + if(sf & BIT(14)) viewloc_SetTags(this); diff --git a/qcsrc/lib/csqcmodel/cl_model.qh b/qcsrc/lib/csqcmodel/cl_model.qh index b5d9f8bd3..621186844 100644 --- a/qcsrc/lib/csqcmodel/cl_model.qh +++ b/qcsrc/lib/csqcmodel/cl_model.qh @@ -27,7 +27,8 @@ #define CSQCMODEL_ENDIF #define CSQCMODEL_PROPERTY(flag,t,r,w,f) \ .t f; -#define CSQCMODEL_PROPERTY_SCALED(flag,t,r,w,f,s,mi,ma) CSQCMODEL_PROPERTY(flag,t,r,w,f) +#define CSQCMODEL_PROPERTY_SCALED(flag,t,r,w,f,s,mi,ma) \ + .t f; ALLPROPERTIES #undef CSQCMODEL_PROPERTY_SCALED #undef CSQCMODEL_PROPERTY diff --git a/qcsrc/lib/csqcmodel/sv_model.qc b/qcsrc/lib/csqcmodel/sv_model.qc index 584bfc23f..70e2c1a15 100644 --- a/qcsrc/lib/csqcmodel/sv_model.qc +++ b/qcsrc/lib/csqcmodel/sv_model.qc @@ -48,7 +48,11 @@ bool CSQCModel_Send(entity this, entity to, int sf) { \ w(MSG_ENTITY, this.csqcmodel_##f); \ } -#define CSQCMODEL_PROPERTY_SCALED(flag,t,r,w,f,s,mi,ma) CSQCMODEL_PROPERTY(flag,t,r,w,f) +#define CSQCMODEL_PROPERTY_SCALED(flag,t,r,w,f,s,mi,ma) \ + if(sf & flag) \ + { \ + w(MSG_ENTITY, this.csqcmodel_##f); \ + } ALLPROPERTIES #undef CSQCMODEL_PROPERTY_SCALED #undef CSQCMODEL_PROPERTY diff --git a/qcsrc/lib/csqcmodel/sv_model.qh b/qcsrc/lib/csqcmodel/sv_model.qh index e963f12a1..f70ecea88 100644 --- a/qcsrc/lib/csqcmodel/sv_model.qh +++ b/qcsrc/lib/csqcmodel/sv_model.qh @@ -34,7 +34,9 @@ void CSQCModel_UnlinkEntity(entity e); #define CSQCMODEL_PROPERTY(flag,t,r,w,f) \ .t f; \ .t csqcmodel_##f; -#define CSQCMODEL_PROPERTY_SCALED(flag,t,r,w,f,s,mi,ma) CSQCMODEL_PROPERTY(flag,t,r,w,f) +#define CSQCMODEL_PROPERTY_SCALED(flag,t,r,w,f,s,mi,ma) \ + .t f; \ + .t csqcmodel_##f; ALLPROPERTIES #undef CSQCMODEL_PROPERTY_SCALED #undef CSQCMODEL_PROPERTY -- 2.39.2