Skip to content

Commit

Permalink
Release 1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dronelektron committed Oct 20, 2021
2 parents 4160543 + 13bada1 commit 8c50039
Show file tree
Hide file tree
Showing 12 changed files with 229 additions and 174 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Respawn Unlocker

Allows you to remove invisible walls and add crates near the spawn zone at the end of the round.
Allows you to unlock respawn at the end of the round:

* Remove invisible walls
* Add crates

### Supported Games

Expand All @@ -17,6 +20,10 @@ Allows you to remove invisible walls and add crates near the spawn zone at the e
* sm_respawnunlocker_crates - Enable (1) or disable (0) crates adding [default: "1"]
* sm_respawnunlocker_notifications - Enable (1) or disable (0) notifications [default: "1"]

### Console Commands

* sm_respawnunlocker_reload_crates - Reload crates from config file

### How to add crates

Create a file "addons/sourcemod/configs/respawn-unlocker.txt" with the following structure:
Expand Down
3 changes: 3 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

spcomp scripting/respawn-unlocker.sp scripting/modules/*.sp -i scripting/include -o plugins/respawn-unlocker.smx
6 changes: 6 additions & 0 deletions scripting/include/crate.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#if defined _crate_included
#endinput
#endif
#define _crate_included

#define MAX_CRATES_COUNT 32
7 changes: 7 additions & 0 deletions scripting/include/message.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#if defined _message_included
#endinput
#endif
#define _message_included

#define PREFIX "[Respawn unlocker] "
#define PREFIX_COLORED "{fuchsia}[Respawn unlocker] "
8 changes: 8 additions & 0 deletions scripting/include/wall.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#if defined _wall_included
#endinput
#endif
#define _wall_included

#define MAX_WALLS_COUNT 32
#define ENTITY_NOT_FOUND -1
#define COLLISION_GROUP_IN_VEHICLE 10
10 changes: 10 additions & 0 deletions scripting/modules/concmd.sp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
void CreateConCmds() {
RegAdminCmd("sm_respawnunlocker_reload_crates", Command_ReloadCrates, ADMFLAG_GENERIC);
}

public Action Command_ReloadCrates(int client, int args) {
LoadCrates();
ReplyToCommand(client, "%s%t", PREFIX, "Crates reloaded");

return Plugin_Handled;
}
21 changes: 21 additions & 0 deletions scripting/modules/convar.sp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
static ConVar g_wallsEnabled = null;
static ConVar g_cratesEnabled = null;
static ConVar g_notificationsEnabled = null;

void CreateConVars() {
g_wallsEnabled = CreateConVar("sm_respawnunlocker_walls", "1", "Enable (1) or disable (0) walls removing");
g_cratesEnabled = CreateConVar("sm_respawnunlocker_crates", "1", "Enable (1) or disable (0) crates adding");
g_notificationsEnabled = CreateConVar("sm_respawnunlocker_notifications", "1", "Enable (1) or disable (0) notifications");
}

bool IsWallsEnabled() {
return g_wallsEnabled.IntValue == 1;
}

bool IsCratesEnabled() {
return g_cratesEnabled.IntValue == 1;
}

bool IsNotificationsEnabled() {
return g_notificationsEnabled.IntValue == 1;
}
79 changes: 79 additions & 0 deletions scripting/modules/crate.sp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
static int g_cratesCount = 0;
static float g_cratePositions[MAX_CRATES_COUNT][3];

void LoadCrates() {
char configPath[PLATFORM_MAX_PATH];
char mapName[256];

GetCurrentMap(mapName, sizeof(mapName));
BuildPath(Path_SM, configPath, sizeof(configPath), "configs/respawn-unlocker.txt");

if (!FileExists(configPath)) {
return;
}

KeyValues kv = new KeyValues("Crates");

kv.ImportFromFile(configPath);
g_cratesCount = 0;

if (!kv.JumpToKey(mapName) || !kv.GotoFirstSubKey()) {
LogMessage("No crates for this map");

delete kv;

return;
}

do {
g_cratePositions[g_cratesCount][0] = kv.GetFloat("position_x");
g_cratePositions[g_cratesCount][1] = kv.GetFloat("position_y");
g_cratePositions[g_cratesCount][2] = kv.GetFloat("position_z");
g_cratesCount++;
} while (kv.GotoNextKey());

LogMessage("Loaded %d crates for this map", g_cratesCount);

delete kv;
}

void NotifyAboutCrates() {
if (g_cratesCount == 0 || !IsCratesEnabled() || !IsNotificationsEnabled()) {
return;
}

CPrintToChatAll("%s%t", PREFIX_COLORED, "Crates created");
}

void SpawnCrates() {
if (!IsCratesEnabled()) {
return;
}

for (int crateIndex = 0; crateIndex < g_cratesCount; crateIndex++) {
SpawnCrate(g_cratePositions[crateIndex]);
}
}

void SpawnCrate(const float position[3]) {
int crate = CreateEntityByName("prop_dynamic_override");

DispatchKeyValue(crate, "model", "models/props_junk/wood_crate001a.mdl");
DispatchKeyValue(crate, "disableshadows", "1");
DispatchKeyValue(crate, "solid", "6");
DispatchSpawn(crate);

SetEntityRenderColor(crate, 255, 255, 255, 127);
SetEntityRenderMode(crate, RENDER_TRANSCOLOR);

float minBounds[3];
float newPosition[3];

GetEntPropVector(crate, Prop_Send, "m_vecMins", minBounds);

newPosition[0] = position[0];
newPosition[1] = position[1];
newPosition[2] = position[2] - minBounds[2];

TeleportEntity(crate, newPosition, NULL_VECTOR, NULL_VECTOR);
}
62 changes: 62 additions & 0 deletions scripting/modules/wall.sp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
static char g_wallEntityClasses[][] = {"func_team_wall", "func_teamblocker"};

static int g_wallsCount = 0;
static int g_wallEntities[MAX_WALLS_COUNT];
static int g_wallCollisionFlags[MAX_WALLS_COUNT];

void FindWallEntities() {
int wallIndex = 0;
int entity = ENTITY_NOT_FOUND;

for (int classIndex = 0; classIndex < sizeof(g_wallEntityClasses); classIndex++) {
while ((entity = FindEntityByClassname(entity, g_wallEntityClasses[classIndex])) != ENTITY_NOT_FOUND) {
g_wallEntities[wallIndex++] = entity;
}
}

g_wallsCount = wallIndex;
}

void SaveWallsCollisionFlags() {
for (int wallIndex = 0; wallIndex < g_wallsCount; wallIndex++) {
int entity = g_wallEntities[wallIndex];

g_wallCollisionFlags[wallIndex] = GetCollisionFlags(entity);
}
}

void RemoveWallsCollisionFlags() {
if (!IsWallsEnabled()) {
return;
}

for (int wallIndex = 0; wallIndex < g_wallsCount; wallIndex++) {
int entity = g_wallEntities[wallIndex];

SetCollisionFlags(entity, COLLISION_GROUP_IN_VEHICLE);
}
}

void RestoreWallsCollisionFlags() {
for (int wallIndex = 0; wallIndex < g_wallsCount; wallIndex++) {
int entity = g_wallEntities[wallIndex];

SetCollisionFlags(entity, g_wallCollisionFlags[wallIndex]);
}
}

int GetCollisionFlags(int entity) {
return GetEntProp(entity, Prop_Send, "m_CollisionGroup");
}

void SetCollisionFlags(int entity, int flags) {
SetEntProp(entity, Prop_Send, "m_CollisionGroup", flags);
}

void NotifyAboutRespawnUnlocking() {
if (g_wallsCount == 0 || !IsWallsEnabled() || !IsNotificationsEnabled()) {
return;
}

CPrintToChatAll("%s%t", PREFIX_COLORED, "Respawn unlocked");
}
Loading

0 comments on commit 8c50039

Please sign in to comment.