Skip to content

Commit 17c0951

Browse files
authored
feat(roundend): integrate calls for API & forwards (#155)
1 parent 120aa87 commit 17c0951

6 files changed

Lines changed: 155 additions & 13 deletions

File tree

src/addons/sourcemod/scripting/include/zombiereloaded.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <zr/knockback.zr>
3939
#include <zr/ztele.zr>
4040
#include <zr/weapons.zr>
41+
#include <zr/roundend.zr>
4142

4243
public SharedPlugin __pl_zombiereloaded =
4344
{
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* ============================================================================
3+
*
4+
* Zombie:Reloaded
5+
*
6+
* File: roundend.zr.inc
7+
* Type: Include
8+
* Description: Round end-related forwards.
9+
*
10+
* Copyright (C) 2009-2013 Greyscale, Richard Helgeby
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU General Public License as published by
14+
* the Free Software Foundation, either version 3 of the License, or
15+
* (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
*
25+
* ============================================================================
26+
*/
27+
28+
/**
29+
* Called once at round end before player rows are sent.
30+
*
31+
* @param playerCount Number of player rows that will be sent in ZR_OnRoundEndPlayer.
32+
*/
33+
forward void ZR_OnRoundEndStats(int playerCount);
34+
35+
/**
36+
* Called once per player at round end.
37+
*
38+
* @param userid Userid of the player.
39+
* @param name Player name.
40+
* @param auth Player auth id according to zr_roundend_authid_type.
41+
* @param alive True if the player is alive.
42+
* @param zombie True if the player is a zombie, false if human.
43+
*/
44+
forward void ZR_OnRoundEndPlayer(int userid, const char[] name, const char[] auth, bool alive, bool zombie);

src/addons/sourcemod/scripting/zr/api/api.inc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include "knockback.api"
4949
#include "weapons.api"
5050
#include "ztele.api"
51+
#include "roundend.api"
5152

5253
/**
5354
* Initializes all main natives and forwards.
@@ -62,6 +63,7 @@ void APIInit()
6263
APIKnockbackInit();
6364
APIWeaponsInit();
6465
APIZteleInit();
66+
APIRoundEndInit();
6567
}
6668

6769
/**
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* ============================================================================
3+
*
4+
* Zombie:Reloaded
5+
*
6+
* File: roundend.api.inc
7+
* Type: Core
8+
* Description: Native handlers for the ZR API. (Round end module)
9+
*
10+
* Copyright (C) 2009-2013 Greyscale, Richard Helgeby
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU General Public License as published by
14+
* the Free Software Foundation, either version 3 of the License, or
15+
* (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
*
25+
* ============================================================================
26+
*/
27+
28+
/**
29+
* @section Global forward handles.
30+
*/
31+
GlobalForward g_hAPIFwdOnRoundEndStats = null;
32+
GlobalForward g_hAPIFwdOnRoundEndPlayer = null;
33+
/**
34+
* @endsection
35+
*/
36+
37+
/**
38+
* Initializes all forwards related to round end.
39+
*/
40+
void APIRoundEndInit()
41+
{
42+
g_hAPIFwdOnRoundEndStats = new GlobalForward("ZR_OnRoundEndStats", ET_Ignore, Param_Cell);
43+
g_hAPIFwdOnRoundEndPlayer = new GlobalForward("ZR_OnRoundEndPlayer", ET_Ignore, Param_Cell, Param_String, Param_String, Param_Cell, Param_Cell);
44+
}
45+
46+
/**
47+
* Called once at round end with the number of player rows.
48+
*/
49+
void APIOnRoundEndStats(int playerCount)
50+
{
51+
// Start forward call.
52+
Call_StartForward(g_hAPIFwdOnRoundEndStats);
53+
54+
// Push the parameters.
55+
Call_PushCell(playerCount);
56+
57+
// Finish the call.
58+
Call_Finish();
59+
}
60+
61+
/**
62+
* Called once per player at round end.
63+
*/
64+
void APIOnRoundEndPlayer(int userid, const char[] name, const char[] auth, bool alive, bool zombie)
65+
{
66+
// Start forward call.
67+
Call_StartForward(g_hAPIFwdOnRoundEndPlayer);
68+
69+
// Push the parameters.
70+
Call_PushCell(userid);
71+
Call_PushString(name);
72+
Call_PushString(auth);
73+
Call_PushCell(alive);
74+
Call_PushCell(zombie);
75+
76+
// Finish the call.
77+
Call_Finish();
78+
}

src/addons/sourcemod/scripting/zr/hgversion.h.inc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
#define ZR_CONTRIBUTORS "Greyscale, Richard Helgeby, maxime1907, BotoX, zaCade, .Rushaway, Franug, Anubis"
44
#define ZR_VER_BRANCH "master"
55
#define ZR_VER_MAJOR "3"
6-
#define ZR_VER_MINOR "12"
7-
#define ZR_VER_PATCH "30"
6+
#define ZR_VER_MINOR "13"
7+
#define ZR_VER_PATCH "0"
88
#define ZR_VERSION ZR_VER_MAJOR..."."...ZR_VER_MINOR..."."...ZR_VER_PATCH
99
#define ZR_VER_LICENSE "GNU GPL, Version 3"
10-
#define ZR_VER_DATE "Thu May 21 CEST 2026"
10+
#define ZR_VER_DATE "Sat May 23 CEST 2026"

src/addons/sourcemod/scripting/zr/roundend.inc

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -240,29 +240,46 @@ void RoundEndDisplayStats()
240240
{
241241
AuthIdType authType = view_as<AuthIdType>(g_hCvarsList.CVAR_ROUNDEND_AUTHID_TYPE.IntValue);
242242

243+
int count = 0;
244+
243245
for (int player = 1; player <= MaxClients; player++)
244246
{
245247
if (!IsClientInGame(player) || (IsFakeClient(player) && !IsClientSourceTV(player)))
246248
continue;
247249

248-
static char sPlayerID[8];
249-
static char sPlayerName[MAX_NAME_LENGTH + 2];
250+
count++;
251+
}
252+
253+
APIOnRoundEndStats(count);
254+
255+
// Print to console and log
256+
for (int player = 1; player <= MaxClients; player++)
257+
{
258+
if (!IsClientInGame(player) || (IsFakeClient(player) && !IsClientSourceTV(player)))
259+
continue;
260+
261+
int userid = GetClientUserId(player);
262+
263+
static char sPlayerName[MAX_NAME_LENGTH + 1];
264+
static char sPlayerNameQuoted[MAX_NAME_LENGTH + 3];
250265
static char sPlayerAuth[24];
251266
static char sPlayerTeam[8];
252267
static char sPlayerState[8];
253268

254-
FormatEx(sPlayerID, sizeof(sPlayerID), "%d", GetClientUserId(player));
255-
FormatEx(sPlayerName, sizeof(sPlayerName), "\"%N\"", player);
269+
FormatEx(sPlayerName, sizeof(sPlayerName), "%N", player);
270+
FormatEx(sPlayerNameQuoted, sizeof(sPlayerNameQuoted), "\"%s\"", sPlayerName);
256271

257272
if (!GetClientAuthId(player, authType, sPlayerAuth, sizeof(sPlayerAuth)))
258273
FormatEx(sPlayerAuth, sizeof(sPlayerAuth), "STEAM_ID_PENDING");
259274

260-
if (IsPlayerAlive(player))
275+
bool alive = IsPlayerAlive(player);
276+
if (alive)
261277
FormatEx(sPlayerState, sizeof(sPlayerState), "alive");
262278
else
263279
FormatEx(sPlayerState, sizeof(sPlayerState), "dead");
264280

265-
if (InfectIsClientInfected(player))
281+
bool zombie = InfectIsClientInfected(player);
282+
if (zombie)
266283
FormatEx(sPlayerTeam, sizeof(sPlayerTeam), "zombie");
267284
else
268285
FormatEx(sPlayerTeam, sizeof(sPlayerTeam), "human");
@@ -272,12 +289,12 @@ void RoundEndDisplayStats()
272289
if (!IsClientInGame(client))
273290
continue;
274291

275-
PrintToConsole(client, "# %8s %40s %24s %5s %6s",
276-
sPlayerID, sPlayerName, sPlayerAuth, sPlayerState, sPlayerTeam);
292+
PrintToConsole(client, "# %8d %40s %24s %5s %6s", userid, sPlayerNameQuoted, sPlayerAuth, sPlayerState, sPlayerTeam);
277293
}
278294

279-
LogMessage("# %8s %40s %24s %5s %6s",
280-
sPlayerID, sPlayerName, sPlayerAuth, sPlayerState, sPlayerTeam);
295+
LogMessage("# %8d %40s %24s %5s %6s", userid, sPlayerNameQuoted, sPlayerAuth, sPlayerState, sPlayerTeam);
296+
297+
APIOnRoundEndPlayer(userid, sPlayerName, sPlayerAuth, alive, zombie);
281298
}
282299
}
283300

0 commit comments

Comments
 (0)