Skip to content

Commit

Permalink
Release 1.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
dronelektron committed Dec 27, 2022
2 parents ec22cfc + 85748c2 commit c9f6535
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 19 deletions.
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 grab, move and throw players",
version = "1.4.1",
version = "1.4.2",
url = "https://github.com/dronelektron/gravity-gun"
};

Expand Down
2 changes: 1 addition & 1 deletion scripting/include/gg/use-case.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#define CLIENT_NOT_FOUND -1
#define INVALID_CLIENT 0
#define DISTANCE_MIN 64.0
#define OBSERVER_MODE_FIRST_PERSON 4
#define OBSERVER_MODE_FREE_CAMERA 7
#define CAPTURE_MODE_FIXED 0
#define TRACE_MODE_LINE 0

Expand Down
40 changes: 25 additions & 15 deletions scripting/modules/use-case.sp
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,56 @@ void UseCase_CapturePlayer(int client) {

int target = UseCase_TraceTarget(client);

if (!UseCase_IsTargetCapturable(client, target)) {
return;
}

int clientId = GetClientUserId(client);
float distance = UseCase_GetInitialDistance(client, target);

Client_SetTarget(client, target);
Client_SetDistance(client, distance);
UseCase_RemoveClientSpeedLimit(target);
CreateTimer(RETENTION_TIMER_INTERVAL, UseCaseTimer_PlayerRetention, clientId, RETENTION_TIMER_FLAGS);
Message_PlayerCaptured(client, target);
}

bool UseCase_IsTargetCapturable(int client, int target) {
if (target == CLIENT_NOT_FOUND) {
MessagePrint_PlayerNotFound(client);

return;
return false;
}

if (UseCase_IsInvalidObserverMode(client)) {
MessagePrint_InvalidObserverMode(client);

return;
return false;
}

int owner = Client_GetOwner(target);

if (owner != CLIENT_NOT_FOUND) {
MessagePrint_PlayerAlreadyCaptured(client, target, owner);

return;
return false;
}

bool isClientCapturedByTarget = Client_GetTarget(target) == client;

if (isClientCapturedByTarget) {
MessagePrint_YouCannotCaptureOwner(client, target);

return;
return false;
}

if (!CanUserTarget(client, target)) {
MessagePrint_TargetHasImmunity(client, target);

return;
return false;
}

int clientId = GetClientUserId(client);
float distance = UseCase_GetInitialDistance(client, target);

Client_SetTarget(client, target);
Client_SetDistance(client, distance);
UseCase_RemoveClientSpeedLimit(target);
CreateTimer(RETENTION_TIMER_INTERVAL, UseCaseTimer_PlayerRetention, clientId, RETENTION_TIMER_FLAGS);
Message_PlayerCaptured(client, target);
return true;
}

int UseCase_TraceTarget(int client) {
Expand All @@ -70,8 +78,10 @@ int UseCase_FindNearestTargetInCone(int client) {

float angle = Math_CalculateAngleToCone(client, i);
float distance = Math_CalculateDistance(client, i);
bool isTargetInCone = angle < coneAngle && distance < coneDistance;
bool isTargetAngleSmaller = angle < targetAngle;

if (angle <= coneAngle && distance < coneDistance && angle < targetAngle) {
if (isTargetInCone && isTargetAngleSmaller) {
target = i;
targetAngle = angle;
}
Expand Down Expand Up @@ -223,7 +233,7 @@ void UseCase_DecreaseDistance(int client, float step) {
bool UseCase_IsInvalidObserverMode(int client) {
int observerMode = GetEntProp(client, Prop_Send, "m_iObserverMode");

return IsClientObserver(client) && observerMode == OBSERVER_MODE_FIRST_PERSON;
return IsClientObserver(client) && observerMode != OBSERVER_MODE_FREE_CAMERA;
}

void UseCase_RemoveClientSpeedLimit(int client) {
Expand Down
2 changes: 1 addition & 1 deletion translations/gravity-gun.phrases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

"Invalid observer mode"
{
"en" "You cannot grab a player in first person"
"en" "You can only capture a player in freecam mode"
}

"Player already captured"
Expand Down
2 changes: 1 addition & 1 deletion translations/ru/gravity-gun.phrases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

"Invalid observer mode"
{
"ru" "Вы не можете схватить игрока от вида первого лица"
"ru" "Вы можете схватить игрока только в режиме свободной камеры"
}

"Player already captured"
Expand Down

0 comments on commit c9f6535

Please sign in to comment.