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 Oct 20, 2022
2 parents df0e302 + ccb86c2 commit 7c2d4cb
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 83 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ Allows you to perform various actions with objects at the beginning of the round

### Console Variables

* sm_entitymanager_allow_freezing - Freeze (1 - yes, 0 - no) objects at the beginning of the round [default: "1"]
* sm_entitymanager_allow_deletion - Delete (1 - yes, 0 - no) objects at the beginning of the round [default: "1"]
* sm_entitymanager_auto_freezing - Freeze (1 - yes, 0 - no) objects at the beginning of the round [default: "1"]
* sm_entitymanager_auto_deletion - Delete (1 - yes, 0 - no) objects at the beginning of the round [default: "1"]

### Console Commands

Expand Down
8 changes: 2 additions & 6 deletions scripting/entity-manager.sp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
#undef REQUIRE_PLUGIN
#include <adminmenu>

#pragma semicolon 1
#pragma newdecls required

#include "em/entity-list"
#include "em/entity"
#include "em/math"
Expand All @@ -29,12 +26,11 @@ public Plugin myinfo = {
name = "Entity manager",
author = "Dron-elektron",
description = "Allows you to perform various actions with objects at the beginning of the round",
version = "1.2.1",
version = "1.3.0",
url = "https://github.com/dronelektron/entity-manager"
};

public void OnPluginStart() {
Storage_BuildConfigPath();
EntityList_Create();
Command_Create();
Variable_Create();
Expand All @@ -50,7 +46,7 @@ public void OnPluginEnd() {

public void OnMapStart() {
Visualizer_PrecacheTempEntityModels();
Storage_SaveCurrentMapName();
Storage_BuildConfigPath();
UseCase_LoadEntities(CONSOLE);
}

Expand Down
2 changes: 0 additions & 2 deletions scripting/include/em/entity-list.inc
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
#endif
#define _em_entity_list_included

#define ENTITY_NOT_FOUND -1

#define ENTITY_FIELD_ID 0
#define ENTITY_FIELD_ACTION 1

Expand Down
2 changes: 1 addition & 1 deletion scripting/include/em/entity.inc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#endif
#define _em_entity_included

#define VECTOR_SIZE 3
#define ENTITY_NOT_FOUND -1
#define ENTITY_WORLD 0

#define ENT_PROP_EFFECTS "m_fEffects"
Expand Down
10 changes: 9 additions & 1 deletion scripting/include/em/storage.inc
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@
#endif
#define _em_storage_included

#define MAP_NAME_MAX_LENGTH (30 + 1)
#define PERMISSIONS_USER (FPERM_U_READ | FPERM_U_WRITE | FPERM_U_EXEC)
#define PERMISSIONS_GROUP (FPERM_G_READ | FPERM_G_WRITE | FPERM_G_EXEC)
#define PERMISSIONS_OTHER (FPERM_O_READ | FPERM_O_EXEC)
#define PERMISSIONS (PERMISSIONS_USER | PERMISSIONS_GROUP | PERMISSIONS_OTHER)

#define STORAGE_KEY_ACTION "action"
#define STORAGE_ENTITY_ID_MAX_LENGTH (5 + 1)

#define CREATE_YES true

#define IMPORT_YES true
#define IMPORT_NO false

typedef StorageOperation = function void (KeyValues kv);
4 changes: 2 additions & 2 deletions scripting/modules/console-variable.sp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ static ConVar g_freezeEntities = null;
static ConVar g_deleteEntities = null;

void Variable_Create() {
g_freezeEntities = CreateConVar("sm_entitymanager_allow_freezing", "1", "Freeze (1 - yes, 0 - no) objects at the beginning of the round");
g_deleteEntities = CreateConVar("sm_entitymanager_allow_deletion", "1", "Delete (1 - yes, 0 - no) objects at the beginning of the round");
g_freezeEntities = CreateConVar("sm_entitymanager_auto_freezing", "1", "Freeze (1 - yes, 0 - no) objects at the beginning of the round");
g_deleteEntities = CreateConVar("sm_entitymanager_auto_deletion", "1", "Delete (1 - yes, 0 - no) objects at the beginning of the round");
}

bool Variable_IsFreezeAllowed() {
Expand Down
43 changes: 9 additions & 34 deletions scripting/modules/message.sp
Original file line number Diff line number Diff line change
Expand Up @@ -14,76 +14,51 @@ void MessageReply_EntityNotDeleted(int client, int entity) {
ReplyToCommand(client, "%s%t", PREFIX, "Entity not deleted", entity);
}

void MessageActivity_EntityFrozen(int client, int entity) {
void Message_EntityFrozen(int client, int entity) {
ShowActivity2(client, PREFIX, "%t", "Entity has been frozen", entity);
}

void MessageLog_EntityFrozen(int client, int entity) {
LogMessage("\"%L\" froze entity %d", client, entity);
}

void MessageActivity_EntityUnfrozen(int client, int entity) {
void Message_EntityUnfrozen(int client, int entity) {
ShowActivity2(client, PREFIX, "%t", "Entity has been unfrozen", entity);
}

void MessageLog_EntityUnfrozen(int client, int entity) {
LogMessage("\"%L\" unfroze entity %d", client, entity);
}

void MessageActivity_EntityDeleted(int client, int entity) {
void Message_EntityDeleted(int client, int entity) {
ShowActivity2(client, PREFIX, "%t", "Entity has been deleted", entity);
}

void MessageLog_EntityDeleted(int client, int entity) {
LogMessage("\"%L\" deleted entity %d", client, entity);
}

void MessageActivity_EntityRestored(int client, int entity) {
void Message_EntityRestored(int client, int entity) {
ShowActivity2(client, PREFIX, "%t", "Entity has been restored", entity);
}

void MessageLog_EntityRestored(int client, int entity) {
LogMessage("\"%L\" restored entity %d", client, entity);
}

void MessageActivity_ListOfEntitiesCleared(int client) {
void Message_ListOfEntitiesCleared(int client) {
ShowActivity2(client, PREFIX, "%t", "List of entities cleared");
}

void MessageLog_ListOfEntitiesCleared(int client) {
LogMessage("\"%L\" cleared the list of entities", client);
}

void MessageActivity_EntitiesSaved(int client, int entitiesAmount) {
void Message_EntitiesSaved(int client, int entitiesAmount) {
ShowActivity2(client, PREFIX, "%t", "Entities saved", entitiesAmount);
}

void MessageLog_EntitiesSaved(int client, int entitiesAmount) {
LogMessage("\"%L\" saved %d entities", client, entitiesAmount);
}

void MessageReply_NoEntitiesForLoading(int client) {
void Message_NoEntitiesForLoading(int client) {
if (client != CONSOLE) {
ReplyToCommand(client, "%s%t", PREFIX, "No entities for loading");
}
}

void MessageLog_NoEntitiesForLoading(int client) {
if (client == CONSOLE) {
LogMessage("No entities for this map");
}
}

void MessageActivity_EntitiesLoaded(int client, int entitiesAmount) {
if (client != CONSOLE) {
ShowActivity2(client, PREFIX, "%t", "Entities loaded", entitiesAmount);
}
}

void MessageLog_EntitiesLoaded(int client, int entitiesAmount) {
void Message_EntitiesLoaded(int client, int entitiesAmount) {
if (client == CONSOLE) {
LogMessage("Loaded %d entities", entitiesAmount);
} else {
ShowActivity2(client, PREFIX, "%t", "Entities loaded", entitiesAmount);
LogMessage("\"%L\" loaded %d entities", client, entitiesAmount);
}
}
35 changes: 18 additions & 17 deletions scripting/modules/storage.sp
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
static char g_mapName[MAP_NAME_MAX_LENGTH];
static char g_configPath[PLATFORM_MAX_PATH];

void Storage_SaveCurrentMapName() {
GetCurrentMap(g_mapName, sizeof(g_mapName));
}

void Storage_BuildConfigPath() {
BuildPath(Path_SM, g_configPath, sizeof(g_configPath), "configs/entity-manager.txt");
BuildPath(Path_SM, g_configPath, sizeof(g_configPath), "configs/entity-manager");

if (!DirExists(g_configPath)) {
CreateDirectory(g_configPath, PERMISSIONS);
}

char mapName[PLATFORM_MAX_PATH];

GetCurrentMap(mapName, sizeof(mapName));
Format(g_configPath, sizeof(g_configPath), "%s/%s.txt", g_configPath, mapName);
}

void Storage_SaveEntities(KeyValues kv) {
int entitiesAmount = EntityList_Size();
DeleteFile(g_configPath);

if (kv.JumpToKey(g_mapName)) {
kv.DeleteThis();
kv.Rewind();
}
int entitiesAmount = EntityList_Size();

if (entitiesAmount > 0) {
kv.JumpToKey(g_mapName, true);
if (entitiesAmount == 0) {
return;
}

char entityId[STORAGE_ENTITY_ID_MAX_LENGTH];
Expand All @@ -29,7 +30,7 @@ void Storage_SaveEntities(KeyValues kv) {

IntToString(entity, entityId, sizeof(entityId));

kv.JumpToKey(entityId, true);
kv.JumpToKey(entityId, CREATE_YES);
kv.SetNum(STORAGE_KEY_ACTION, action);
kv.GoBack();
}
Expand All @@ -41,7 +42,7 @@ void Storage_SaveEntities(KeyValues kv) {
void Storage_LoadEntities(KeyValues kv) {
EntityList_Clear();

if (!kv.JumpToKey(g_mapName) || !kv.GotoFirstSubKey()) {
if (!kv.GotoFirstSubKey()) {
return;
}

Expand All @@ -57,10 +58,10 @@ void Storage_LoadEntities(KeyValues kv) {
} while (kv.GotoNextKey());
}

void Storage_Apply(StorageOperation operation) {
void Storage_Apply(StorageOperation operation, bool isImport) {
KeyValues kv = new KeyValues("Entities");

if (FileExists(g_configPath)) {
if (FileExists(g_configPath) && isImport) {
kv.ImportFromFile(g_configPath);
kv.Rewind();
}
Expand Down
28 changes: 10 additions & 18 deletions scripting/modules/use-case.sp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ void UseCase_FreezeEntity(int client) {

Entity_Freeze(entity);
EntityList_Add(entity, ENTITY_ACTION_FREEZE);
MessageActivity_EntityFrozen(client, entity);
MessageLog_EntityFrozen(client, entity);
Message_EntityFrozen(client, entity);
}

void UseCase_UnfreezeEntity(int client) {
Expand All @@ -36,8 +35,7 @@ void UseCase_UnfreezeEntity(int client) {

Entity_Unfreeze(entity);
EntityList_Remove(entity);
MessageActivity_EntityUnfrozen(client, entity);
MessageLog_EntityUnfrozen(client, entity);
Message_EntityUnfrozen(client, entity);
}

void UseCase_DeleteEntity(int client) {
Expand All @@ -57,8 +55,7 @@ void UseCase_DeleteEntity(int client) {

Entity_Delete(entity);
EntityList_Add(entity, ENTITY_ACTION_DELETE);
MessageActivity_EntityDeleted(client, entity);
MessageLog_EntityDeleted(client, entity);
Message_EntityDeleted(client, entity);
}

void UseCase_RestoreEntity(int client) {
Expand All @@ -78,8 +75,7 @@ void UseCase_RestoreEntity(int client) {

Entity_Restore(entity);
EntityList_Remove(entity);
MessageActivity_EntityRestored(client, entity);
MessageLog_EntityRestored(client, entity);
Message_EntityRestored(client, entity);
}

void UseCase_ShowPathToEntities(int client) {
Expand All @@ -97,30 +93,26 @@ void UseCase_ShowPathToEntities(int client) {
}

void UseCase_SaveEntities(int client) {
Storage_Apply(Storage_SaveEntities);
Storage_Apply(Storage_SaveEntities, IMPORT_NO);

int entitiesAmount = EntityList_Size();

if (entitiesAmount == 0) {
MessageActivity_ListOfEntitiesCleared(client);
MessageLog_ListOfEntitiesCleared(client);
Message_ListOfEntitiesCleared(client);
} else {
MessageActivity_EntitiesSaved(client, entitiesAmount);
MessageLog_EntitiesSaved(client, entitiesAmount);
Message_EntitiesSaved(client, entitiesAmount);
}
}

void UseCase_LoadEntities(int client) {
Storage_Apply(Storage_LoadEntities);
Storage_Apply(Storage_LoadEntities, IMPORT_YES);

int entitiesAmount = EntityList_Size();

if (entitiesAmount == 0) {
MessageReply_NoEntitiesForLoading(client);
MessageLog_NoEntitiesForLoading(client);
Message_NoEntitiesForLoading(client);
} else {
MessageActivity_EntitiesLoaded(client, entitiesAmount);
MessageLog_EntitiesLoaded(client, entitiesAmount);
Message_EntitiesLoaded(client, entitiesAmount);
}
}

Expand Down

0 comments on commit 7c2d4cb

Please sign in to comment.