Skip to content

Commit

Permalink
Release 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dronelektron committed Feb 23, 2022
2 parents 77e60d7 + 331511e commit a740da1
Show file tree
Hide file tree
Showing 11 changed files with 306 additions and 137 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

Allows you to perform various actions with objects at the beginning of the round:

* Delete
* Freeze
* Delete

### Supported Games

Expand All @@ -16,16 +16,18 @@ Allows you to perform various actions with objects at the beginning of the round

### Console Variables

* sm_entitymanager_allow_freeze - Freeze (1 - yes, 0 - no) objects at the beginning of the round [default: "1"]
* 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"]

### Console Commands

* sm_entitymanager - Open menu
* sm_entitymanager_freeze - Freeze the entity you are looking at
* sm_entitymanager_unfreeze - Unfreeze the entity you are looking at
* sm_entitymanager_delete - Delete entity
* sm_entitymanager_restore - Restore entity
* sm_entitymanager_save - Save entities to file
* sm_entitymanager_load - Load entities from file

### Notes

Expand Down
6 changes: 4 additions & 2 deletions scripting/entity-manager.sp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "em/entity-list"
#include "em/entity"
#include "em/menu"
#include "em/message"
#include "em/storage"
#include "em/use-case"
Expand All @@ -14,6 +15,7 @@
#include "modules/console-variable.sp"
#include "modules/entity-list.sp"
#include "modules/entity.sp"
#include "modules/menu.sp"
#include "modules/message.sp"
#include "modules/storage.sp"
#include "modules/use-case.sp"
Expand All @@ -22,7 +24,7 @@ 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 = "0.1.2",
version = "0.2.0",
url = ""
};

Expand All @@ -41,7 +43,7 @@ public void OnPluginEnd() {
}

public void OnMapStart() {
UseCase_LoadEntities();
UseCase_LoadEntities(CONSOLE);
}

public void Event_RoundStart(Event event, const char[] name, bool dontBroadcast) {
Expand Down
15 changes: 15 additions & 0 deletions scripting/include/em/menu.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#if defined _em_menu_included
#endinput
#endif
#define _em_menu_included

#define MENU_TEXT_MAX_SIZE (32 * 4)

#define ENTITY_MANAGEMENT "Entity management"

#define ITEM_ENTITY_FREEZE "Freeze entity"
#define ITEM_ENTITY_UNFREEZE "Unfreeze entity"
#define ITEM_ENTITY_DELETE "Delete entity"
#define ITEM_ENTITY_RESTORE "Restore entity"
#define ITEM_ENTITIES_SAVE "Save entities"
#define ITEM_ENTITIES_LOAD "Load entities"
6 changes: 6 additions & 0 deletions scripting/include/em/message.inc
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@
#define _message_included

#define PREFIX "[Entity manager] "
#define CONSOLE 0

enum MessageType {
MessageType_Reply,
MessageType_Log
};
100 changes: 49 additions & 51 deletions scripting/modules/console-command.sp
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
void Command_Create() {
RegAdminCmd("sm_entitymanager", Command_Menu, ADMFLAG_GENERIC);
RegAdminCmd("sm_entitymanager_freeze", Command_Freeze, ADMFLAG_GENERIC);
RegAdminCmd("sm_entitymanager_unfreeze", Command_Unfreeze, ADMFLAG_GENERIC);
RegAdminCmd("sm_entitymanager_delete", Command_Delete, ADMFLAG_GENERIC);
RegAdminCmd("sm_entitymanager_restore", Command_Restore, ADMFLAG_GENERIC);
RegAdminCmd("sm_entitymanager_save", Command_Save, ADMFLAG_GENERIC);
RegAdminCmd("sm_entitymanager_load", Command_Load, ADMFLAG_GENERIC);
}

public Action Command_Menu(int client, int args) {
Menu_EntityManager(client);

return Plugin_Handled;
}

public Action Command_Freeze(int client, int args) {
int entity;
UseCaseResult result = UseCase_FreezeEntity(client, entity);

switch (result) {
case UseCaseResult_Success: {
Message_ReplyEntityFrozen(client, entity);
}

case UseCaseResult_EntityNotFound: {
Message_ReplyEntityNotFound(client);
}

case UseCaseResult_AlreadyHasAction: {
Message_ReplyEntityAlreadyHasAction(client, entity);
}
if (result == UseCaseResult_Success) {
Message_EntityFrozen(client, entity);
} else if (result == UseCaseResult_EntityNotFound) {
Message_EntityNotFound(client);
} else if (result == UseCaseResult_AlreadyHasAction) {
Message_EntityAlreadyHasAction(client, entity);
}

return Plugin_Handled;
Expand All @@ -31,18 +33,12 @@ public Action Command_Unfreeze(int client, int args) {
int entity;
UseCaseResult result = UseCase_UnfreezeEntity(client, entity);

switch (result) {
case UseCaseResult_Success: {
Message_ReplyEntityUnfrozen(client, entity);
}

case UseCaseResult_EntityNotFound: {
Message_ReplyEntityNotFound(client);
}

case UseCaseResult_NotFrozen: {
Message_ReplyEntityNotFrozen(client, entity);
}
if (result == UseCaseResult_Success) {
Message_EntityUnfrozen(client, entity);
} else if (result == UseCaseResult_EntityNotFound) {
Message_EntityNotFound(client);
} else if (result == UseCaseResult_NotFrozen) {
Message_EntityNotFrozen(client, entity);
}

return Plugin_Handled;
Expand All @@ -52,18 +48,12 @@ public Action Command_Delete(int client, int args) {
int entity;
UseCaseResult result = UseCase_DeleteEntity(client, entity);

switch (result) {
case UseCaseResult_Success: {
Message_ReplyEntityDeleted(client, entity);
}

case UseCaseResult_EntityNotFound: {
Message_ReplyEntityNotFound(client);
}

case UseCaseResult_AlreadyHasAction: {
Message_ReplyEntityAlreadyHasAction(client, entity);
}
if (result == UseCaseResult_Success) {
Message_EntityDeleted(client, entity);
} else if (result == UseCaseResult_EntityNotFound) {
Message_EntityNotFound(client);
} else if (result == UseCaseResult_AlreadyHasAction) {
Message_EntityAlreadyHasAction(client, entity);
}

return Plugin_Handled;
Expand All @@ -73,32 +63,40 @@ public Action Command_Restore(int client, int args) {
int entity;
UseCaseResult result = UseCase_RestoreEntity(client, entity);

switch (result) {
case UseCaseResult_Success: {
Message_ReplyEntityRestored(client, entity);
}
if (result == UseCaseResult_Success) {
Message_EntityRestored(client, entity);
} else if (result == UseCaseResult_EntityNotFound) {
Message_EntityNotFound(client);
} else if (result == UseCaseResult_NotDeleted) {
Message_EntityNotDeleted(client, entity);
}

case UseCaseResult_EntityNotFound: {
Message_ReplyEntityNotFound(client);
}
return Plugin_Handled;
}

public Action Command_Save(int client, int args) {
UseCase_SaveEntities(client);

case UseCaseResult_NotDeleted: {
Message_ReplyEntityNotDeleted(client, entity);
}
int entitiesAmount = EntityList_Size();

if (entitiesAmount == 0) {
Message_ListOfEntitiesCleared(client);
} else {
Message_EntitiesSaved(client, entitiesAmount);
}

return Plugin_Handled;
}

public Action Command_Save(int client, int args) {
int entitiesAmount;
public Action Command_Load(int client, int args) {
UseCase_LoadEntities(client);

UseCase_SaveEntities(client, entitiesAmount);
int entitiesAmount = EntityList_Size();

if (entitiesAmount == 0) {
Message_ReplyListOfEntitiesCleared(client);
Message_NoEntitiesForLoading(client);
} else {
Message_ReplyEntitiesSaved(client, entitiesAmount);
Message_EntitiesLoaded(client, entitiesAmount);
}

return Plugin_Handled;
Expand Down
2 changes: 1 addition & 1 deletion scripting/modules/console-variable.sp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ static ConVar g_freezeEntities = null;
static ConVar g_deleteEntities = null;

void Variable_Create() {
g_freezeEntities = CreateConVar("sm_entitymanager_allow_freeze", "1", "Freeze (1 - yes, 0 - no) objects at the beginning of the round");
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");
}

Expand Down
51 changes: 51 additions & 0 deletions scripting/modules/menu.sp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
void Menu_EntityManager(int client) {
Menu menu = new Menu(MenuHandler_EntityManager);

menu.SetTitle("%T", ENTITY_MANAGEMENT, client);

Menu_AddItem(menu, ITEM_ENTITY_FREEZE, client);
Menu_AddItem(menu, ITEM_ENTITY_UNFREEZE, client);
Menu_AddItem(menu, ITEM_ENTITY_DELETE, client);
Menu_AddItem(menu, ITEM_ENTITY_RESTORE, client);
Menu_AddItem(menu, ITEM_ENTITIES_SAVE, client);
Menu_AddItem(menu, ITEM_ENTITIES_LOAD, client);

menu.Display(client, MENU_TIME_FOREVER);
}

public int MenuHandler_EntityManager(Menu menu, MenuAction action, int param1, int param2) {
if (action == MenuAction_Select) {
char info[MENU_TEXT_MAX_SIZE];
int entity;

menu.GetItem(param2, info, sizeof(info));

if (strcmp(info, ITEM_ENTITY_FREEZE) == 0) {
UseCase_FreezeEntity(param1, entity);
} else if (strcmp(info, ITEM_ENTITY_UNFREEZE) == 0) {
UseCase_UnfreezeEntity(param1, entity);
} else if (strcmp(info, ITEM_ENTITY_DELETE) == 0) {
UseCase_DeleteEntity(param1, entity);
} else if (strcmp(info, ITEM_ENTITY_RESTORE) == 0) {
UseCase_RestoreEntity(param1, entity);
} else if (strcmp(info, ITEM_ENTITIES_SAVE) == 0) {
UseCase_SaveEntities(param1);
} else if (strcmp(info, ITEM_ENTITIES_LOAD) == 0) {
UseCase_LoadEntities(param1);
}

Menu_EntityManager(param1);
} else if (action == MenuAction_End) {
delete menu;
}

return 0;
}

void Menu_AddItem(Menu menu, char[] phrase, int client) {
char item[MENU_TEXT_MAX_SIZE];

Format(item, sizeof(item), "%T", phrase, client);

menu.AddItem(phrase, item);
}
Loading

0 comments on commit a740da1

Please sign in to comment.