Skip to content

Commit

Permalink
Release 1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dronelektron committed Dec 21, 2022
2 parents 6d1b9ff + 08d9358 commit ba9e820
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 2 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@ Allows you to grab and move players
* sm_gravitygun_default_distance_enable - Enable (1) or disable (0) default capture distance [default: "1"]
* sm_gravitygun_default_distance - Default capture distance, must be at least 64.0 [default: "128.0"]
* sm_gravitygun_default_distance_step - Default distance step for increase/decrease [default: "64.0"]
* sm_gravitygun_default_throw_velocity - Default throw velocity [default: "1000.0"]
* sm_gravitygun_velocity_factor - How fast to move a player [default: "5.0"]
* sm_gravitygun_show_activity - Show (1) or hide (0) admin activity for all players [default: "1"]

### Console Commands

* sm_gravitygun_grab - Grab a player
* sm_gravitygun_throw [velocity] - Throw a player
* sm_gravitygun_distance_increase [step] - Increase capture distance
* sm_gravitygun_distance_decrease [step] - Decrease capture distance

If you do not specify a `step`, then the value from `sm_gravitygun_distance_step` will be used.
If you do not specify a `step`, then the value from `sm_gravitygun_default_distance_step` will be used.
If you do not specify a `velocity`, then the value from `sm_gravitygun_default_throw_velocity` will be used.

### Notes

Expand Down
2 changes: 1 addition & 1 deletion scripting/gravity-gun.sp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public Plugin myinfo = {
name = "Gravity gun",
author = "Dron-elektron",
description = "Allows you to manipulate players",
version = "1.2.1",
version = "1.3.0",
url = "https://github.com/dronelektron/gravity-gun"
};

Expand Down
4 changes: 4 additions & 0 deletions scripting/include/gg/use-case.inc
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
#endif
#define _gg_use_case_included

#define ENTITY_NOT_FOUND -1
#define CLIENT_NOT_FOUND -1
#define INVALID_CLIENT 0
#define DISTANCE_MIN 64.0
#define OBSERVER_MODE_FIRST_PERSON 4

#define RETENTION_TIMER_INTERVAL 0.1
#define RETENTION_TIMER_FLAGS (TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE)

#define FLIGHT_TIMER_INTERVAL 0.1
#define FLIGHT_TIMER_FLAGS (TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE)
9 changes: 9 additions & 0 deletions scripting/modules/console-command.sp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
void Command_Create() {
RegAdminCmd("+sm_gravitygun_grab", Command_CapturePlayer, ADMFLAG_GENERIC);
RegAdminCmd("-sm_gravitygun_grab", Command_ReleasePlayer, ADMFLAG_GENERIC);
RegAdminCmd("sm_gravitygun_throw", Command_ThrowPlayer, ADMFLAG_GENERIC);
RegAdminCmd("sm_gravitygun_distance_increase", Command_IncreaseDistance, ADMFLAG_GENERIC);
RegAdminCmd("sm_gravitygun_distance_decrease", Command_DecreaseDistance, ADMFLAG_GENERIC);
}
Expand All @@ -17,6 +18,14 @@ public Action Command_ReleasePlayer(int client, int args) {
return Plugin_Handled;
}

public Action Command_ThrowPlayer(int client, int args) {
float velocity = args == 0 ? Variable_DefaultThrowVelocity() : GetCmdArgFloat(1);

UseCase_ThrowPlayer(client, velocity);

return Plugin_Handled;
}

public Action Command_IncreaseDistance(int client, int args) {
float step = Command_GetDistanceStep(args);

Expand Down
6 changes: 6 additions & 0 deletions scripting/modules/console-variable.sp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ static ConVar g_pluginEnabled = null;
static ConVar g_defaultDistanceEnabled = null;
static ConVar g_defaultDistance = null;
static ConVar g_defaultDistanceStep = null;
static ConVar g_defaultThrowVelocity = null;
static ConVar g_velocityFactor = null;
static ConVar g_showActivity = null;

Expand All @@ -10,6 +11,7 @@ void Variable_Create() {
g_defaultDistanceEnabled = CreateConVar("sm_gravitygun_default_distance_enable", "1", "Enable (1) or disable (0) default capture distance");
g_defaultDistance = CreateConVar("sm_gravitygun_default_distance", "128.0", "Default capture distance, must be at least 64.0");
g_defaultDistanceStep = CreateConVar("sm_gravitygun_default_distance_step", "64.0", "Default distance step for increase/decrease");
g_defaultThrowVelocity = CreateConVar("sm_gravitygun_default_throw_velocity", "1000.0", "Default throw velocity");
g_velocityFactor = CreateConVar("sm_gravitygun_velocity_factor", "5.0", "How fast to move a player");
g_showActivity = CreateConVar("sm_gravitygun_show_activity", "1", "Show (1) or hide (0) admin activity for all players");
}
Expand All @@ -30,6 +32,10 @@ float Variable_DefaultDistanceStep() {
return g_defaultDistanceStep.FloatValue;
}

float Variable_DefaultThrowVelocity() {
return g_defaultThrowVelocity.FloatValue;
}

float Variable_VelocityFactor() {
return g_velocityFactor.FloatValue;
}
Expand Down
14 changes: 14 additions & 0 deletions scripting/modules/message.sp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ void MessagePrint_YouCannotCaptureOwner(int client, int target) {
PrintToChat(client, "%s%t", PREFIX, "You cannot capture owner", target);
}

void MessagePrint_NoPlayerToThrow(int client) {
PrintToChat(client, "%s%t", PREFIX, "No player to throw");
}

void MessagePrint_DistanceChanged(int client, float distance) {
PrintToChat(client, "%s%t", PREFIX, "Distance changed", distance);
}
Expand All @@ -37,3 +41,13 @@ void Message_PlayerReleased(int client, int target) {

LogMessage("\"%L\" released \"%L\"", client, target);
}

void Message_PlayerThrown(int client, int target, float velocity) {
if (Variable_ShowActivity()) {
ShowActivity2(client, PREFIX, "%t", "Player thrown", target, velocity);
} else {
PrintToChat(client, "%s%t", PREFIX, "Player thrown", target, velocity);
}

LogMessage("\"%L\" threw \"%L\" at a speed of %.2f u/s", client, target, velocity);
}
51 changes: 51 additions & 0 deletions scripting/modules/use-case.sp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,23 @@ void UseCase_ReleaseTarget(int client) {
}
}

void UseCase_ThrowPlayer(int client, float velocity) {
int target = Client_GetTarget(client);

if (target == CLIENT_NOT_FOUND) {
MessagePrint_NoPlayerToThrow(client);

return;
}

int targetId = GetClientUserId(target);

Client_RemoveTarget(client, target);
CreateTimer(FLIGHT_TIMER_INTERVAL, UseCaseTimer_PlayerFlight, targetId, FLIGHT_TIMER_FLAGS);
UseCase_ApplyForceOnce(client, target, velocity);
Message_PlayerThrown(client, target, velocity);
}

public Action UseCaseTimer_PlayerRetention(Handle timer, int clientId) {
int client = GetClientOfUserId(clientId);

Expand All @@ -94,6 +111,30 @@ public Action UseCaseTimer_PlayerRetention(Handle timer, int clientId) {
return Plugin_Continue;
}

public Action UseCaseTimer_PlayerFlight(Handle timer, int targetId) {
int target = GetClientOfUserId(targetId);

if (target == INVALID_CLIENT) {
return Plugin_Stop;
}

int owner = Client_GetOwner(target);

if (owner != CLIENT_NOT_FOUND || !IsPlayerAlive(target)) {
return Plugin_Stop;
}

int groundEntity = GetEntPropEnt(target, Prop_Send, "m_hGroundEntity");

if (groundEntity != ENTITY_NOT_FOUND) {
UseCase_RestoreClientSpeedLimit(target);

return Plugin_Stop;
}

return Plugin_Continue;
}

void UseCase_ApplyForce(int client, int target) {
float clientEyePosition[VECTOR_SIZE];
float clientEyeAngles[VECTOR_SIZE];
Expand All @@ -116,6 +157,16 @@ void UseCase_ApplyForce(int client, int target) {
TeleportEntity(target, NULL_VECTOR, NULL_VECTOR, velocity);
}

void UseCase_ApplyForceOnce(int client, int target, float velocity) {
float eyeAngles[VECTOR_SIZE];
float direction[VECTOR_SIZE];

GetClientEyeAngles(client, eyeAngles);
GetAngleVectors(eyeAngles, direction, NULL_VECTOR, NULL_VECTOR);
ScaleVector(direction, velocity);
TeleportEntity(target, NULL_VECTOR, NULL_VECTOR, direction);
}

float UseCase_GetInitialDistance(int client, int target) {
if (Variable_DefaultDistanceEnabled()) {
float distance = Variable_DefaultDistance();
Expand Down
11 changes: 11 additions & 0 deletions translations/gravity-gun.phrases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
"en" "You cannot capture player {1} because he captured you"
}

"No player to throw"
{
"en" "Grab the player first to throw them"
}

"Distance changed"
{
"#format" "{1:.2f}"
Expand All @@ -39,4 +44,10 @@
"#format" "{1:N}"
"en" "Player {1} is released"
}

"Player thrown"
{
"#format" "{1:N},{2:.2f}"
"en" "Player {1} is thrown at a speed of {2} u/s"
}
}
10 changes: 10 additions & 0 deletions translations/ru/gravity-gun.phrases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
"ru" "Вы не можете схватить игрока {1}, т.к. он схватил вас"
}

"No player to throw"
{
"ru" "Сначала схватите игрока, чтобы его бросить"
}

"Distance changed"
{
"ru" "Расстояние изменено на {1}"
Expand All @@ -34,4 +39,9 @@
{
"ru" "Игрок {1} отпущен"
}

"Player thrown"
{
"ru" "Игрок {1} брошен со скоростью {2} ю/с"
}
}

0 comments on commit ba9e820

Please sign in to comment.