Skip to content

Commit 3bcf7d8

Browse files
committed
Merge branch 'master' of https://github.com/skuzzis/swiftly
2 parents ac34d7c + 5b7ac55 commit 3bcf7d8

File tree

7 files changed

+48
-2
lines changed

7 files changed

+48
-2
lines changed

docgen/data/data.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2791,6 +2791,19 @@
27912791
},
27922792
"additional": {}
27932793
},
2794+
"ispistolround": {
2795+
"title": "IsPistolRound",
2796+
"template": "function-syntax",
2797+
"language": "both",
2798+
"description": "Checks if the round is a PistolRound.",
2799+
"variable": {
2800+
"cpp": "server->IsPistolRound",
2801+
"lua": "server:IsPistolRound"
2802+
},
2803+
"return": "bool",
2804+
"params": {},
2805+
"additional": {}
2806+
},
27942807
"executecommand": {
27952808
"title": "ExecuteCommand",
27962809
"template": "function-syntax",

plugin_files/scripting/includes/swiftly/server.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@ class Server
5050
this->ExecuteCommand("changelevel %s", map);
5151
}
5252

53+
bool IsPistolRound()
54+
{
55+
void *IsPistolRoundFunc = FetchFunctionPtr(nullptr, "scripting_Server_IsPistolRound");
56+
if (IsPistolRoundFunc)
57+
return reinterpret_cast<Server_IsPistolRound>(IsPistolRoundFunc)();
58+
else
59+
{
60+
NOT_SUPPORTED("scripting_Server_IsPistolRound");
61+
return false;
62+
}
63+
}
64+
5365
bool IsMapValid(const char *map)
5466
{
5567
void *IsMapValidFunc = FetchFunctionPtr(nullptr, "scripting_Server_IsMapValid");
@@ -89,4 +101,4 @@ class Server
89101

90102
extern Server *server;
91103

92-
#endif
104+
#endif

plugin_files/scripting/includes/swiftly/swiftly_memory.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ typedef const char *(*Server_GetMap)();
7575
typedef uint16_t (*Server_GetMaxPlayers)();
7676
typedef bool (*Server_IsMapValid)(const char *);
7777
typedef void (*Server_AddPrecacheModel)(const char *);
78+
typedef bool (*Server_IsPistolRound)();
7879

7980
typedef uint64_t (*HTTP_CreateRequest)(const char *);
8081
typedef void (*HTTP_SetBody)(uint64_t, const char *);

src/components/Plugins/inc/Scripting.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ SMM_API void scripting_Server_ExecuteCommand(const char *str);
214214
SMM_API uint16 scripting_Server_GetMaxPlayers();
215215
SMM_API const char *scripting_Server_GetMapName();
216216
SMM_API bool scripting_Server_IsMapValid(const char *map);
217+
SMM_API bool scripting_Server_IsPistolRound();
217218

218219
SMM_API const char *scripting_Translations_Fetch(const char *key);
219220

src/components/Plugins/src/language/lua/server.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ void SetupLuaServer(luacpp::LuaState *state, Plugin *plugin)
2828
.DefMember("ChangeLevel", [](LuaServerClass *base, const char *map) -> void
2929
{
3030
if(!scripting_Server_IsMapValid(map)) return;
31-
scripting_Server_ExecuteCommand(string_format("map %s", map).c_str()); });
31+
scripting_Server_ExecuteCommand(string_format("map %s", map).c_str()); })
32+
33+
.DefMember("IsPistolRound", [](LuaServerClass *base) -> bool
34+
{ return scripting_Server_IsPistolRound(); });
3235

3336
state->DoString("server = Server()");
3437
}

src/components/Plugins/src/scripting/Server.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "../../../../common.h"
2+
#include "sdk/entity/CGameRules.h"
23

34
SMM_API void scripting_Server_ExecuteCommand(const char *str)
45
{
@@ -25,6 +26,17 @@ SMM_API const char *scripting_Server_GetMapName()
2526
return res;
2627
}
2728

29+
30+
SMM_API bool scripting_Server_IsPistolRound()
31+
{
32+
if (g_pGameRules == nullptr)
33+
return false;
34+
35+
return (g_pGameRules->m_totalRoundsPlayed() == 0 || (g_pGameRules->m_bSwitchingTeamsAtRoundReset() && g_pGameRules->m_nOvertimePlaying() == 0) || g_pGameRules->m_bGameRestart());
36+
}
37+
38+
39+
2840
SMM_API bool scripting_Server_IsMapValid(const char *map)
2941
{
3042
if (map == nullptr)

src/sdk/entity/CGameRules.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ class CCSGameRules : public CGameRules
1919
SCHEMA_FIELD_OFFSET(int, m_totalRoundsPlayed, 0)
2020
SCHEMA_FIELD_OFFSET(GameTime_t, m_fRoundStartTime, 0)
2121
SCHEMA_FIELD_OFFSET(GameTime_t, m_flRestartRoundTime, 0)
22+
SCHEMA_FIELD_OFFSET(int32_t, m_nOvertimePlaying, 0)
23+
SCHEMA_FIELD_OFFSET(bool, m_bSwitchingTeamsAtRoundReset, 0)
24+
SCHEMA_FIELD_OFFSET(bool, m_bGameRestart, 0)
25+
SCHEMA_FIELD_OFFSET(int, m_iRoundTime, 0)
2226
};
2327

2428
class CCSGameRulesProxy : public Z_CBaseEntity

0 commit comments

Comments
 (0)