Skip to content

Commit

Permalink
add sm_beamer
Browse files Browse the repository at this point in the history
  • Loading branch information
rtldg committed May 26, 2022
1 parent ed481b2 commit d8a9dd7
Showing 1 changed file with 105 additions and 1 deletion.
106 changes: 105 additions & 1 deletion addons/sourcemod/scripting/shavit-zones.sp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ public void OnPluginStart()

RegAdminCmd("sm_reloadzonesettings", Command_ReloadZoneSettings, ADMFLAG_ROOT, "Reloads the zone settings.");

RegConsoleCmd("sm_beamer", Command_Beamer, "Draw cool beams");

RegConsoleCmd("sm_stages", Command_Stages, "Opens the stage menu. Usage: sm_stages [stage #]");
RegConsoleCmd("sm_stage", Command_Stages, "Opens the stage menu. Usage: sm_stage [stage #]");
RegConsoleCmd("sm_s", Command_Stages, "Opens the stage menu. Usage: sm_s [stage #]");
Expand Down Expand Up @@ -2093,6 +2095,107 @@ public Action Command_ReloadZoneSettings(int client, int args)
return Plugin_Handled;
}

stock void RotateAroundAxis(float v[3], const float in_k[3], float theta)
{
// https://en.wikipedia.org/wiki/Rodrigues%27_rotation_formula#Statement
// vrot = (v * cos(theta)) + ((k x v) * sin(theta)) + (k * (k . v) * (1 - cos(theta)))

float k[3];
k[0] = DegToRad(in_k[1]); k[1] = DegToRad(in_k[2]); k[2] = DegToRad(in_k[0]); // right-hand rule related ordering?
NormalizeVector(k, k);

theta = DegToRad(theta);
float theta_cos = Cosine(theta);
float theta_sin = Sine(theta);
float one_minus_theta_cos = 1.0 - theta_cos;
float kv_dot = GetVectorDotProduct(k, v);

float kv_cross[3];
GetVectorCrossProduct(k, v, kv_cross);

for (int i = 0; i < 3; i++)
{
v[i] = (v[i] * theta_cos)
+ (kv_cross[i] * theta_sin)
+ (k[i] * kv_dot * one_minus_theta_cos);
}
}

public Action Command_Beamer(int client, int args)
{
static float rate_limit[MAXPLAYERS+1];
float now = GetEngineTime();

if (rate_limit[client] > now)
return Plugin_Handled;

rate_limit[client] = now + 0.2;

float startpos[3], endpos[3], direction[3];
GetClientEyePosition(client, startpos);
startpos[2] -= 3.0;
GetClientEyeAngles(client, direction);

float delay = 0.0;

for (int i = 20; i >= 0; --i)
{
/*
My code from tracegun.lua that I based this off of:
local ang = tr.Normal:Angle() // ( traceRes.HitPos - traceRes.StartPos ):Normalize()
ang:RotateAroundAxis(tr.HitNormal, 180)
local dir = ang:Forward()*-1
tr = util.TraceLine({start=tr.HitPos, endpos=tr.HitPos+(dir*100000), filter=players})
*/

TR_TraceRayFilter(startpos, direction, MASK_ALL, RayType_Infinite, TRFilter_NoPlayers, client);
TR_GetEndPosition(endpos);

TE_SetupBeamPoints(
startpos,
endpos,
gI_BeamSpriteIgnoreZ,
gA_ZoneSettings[Zone_Start][Track_Main].iHalo,
0, // StartFrame
0, // FrameRate
10.0, // Life
1.0, // Width
1.0, // EndWidth
0, // FadeLength
0.0, // Amplitude
{255, 255, 0, 192}, // Colour
20 // Speed
);

TE_SendToClient(client, delay);
delay += 0.11;

if (!i) break;

SubtractVectors(endpos, startpos, direction);
NormalizeVector(direction, direction);
GetVectorAngles(direction, direction);

#if 1
// this sometimes helps with the beam getting stuck in walls
float fwd[3];
GetAngleVectors(direction, fwd, NULL_VECTOR, NULL_VECTOR);
ScaleVector(fwd, -1.5);
AddVectors(fwd, startpos, startpos);
#endif

startpos = endpos;

float hitnormal[3];
TR_GetPlaneNormal(INVALID_HANDLE, hitnormal);

RotateAroundAxis(direction, hitnormal, 180.0);
}

return Plugin_Handled;
}

public Action Command_Stages(int client, int args)
{
if(!IsValidClient(client))
Expand Down Expand Up @@ -3322,7 +3425,8 @@ public Action Shavit_OnUserCmdPre(int client, int &buttons, int &impulse, float

public bool TRFilter_NoPlayers(int entity, int mask, any data)
{
return (entity != view_as<int>(data) || (entity < 1 || entity > MaxClients));
//return (entity != view_as<int>(data) || (entity < 1 || entity > MaxClients));
return !(1 <= entity <= MaxClients);
}

public int CreateZoneConfirm_Handler(Menu menu, MenuAction action, int param1, int param2)
Expand Down

0 comments on commit d8a9dd7

Please sign in to comment.