Skip to content

Commit

Permalink
rework tickets
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyShorokhov committed Apr 15, 2024
1 parent 62af7a4 commit f965c7a
Showing 1 changed file with 91 additions and 32 deletions.
123 changes: 91 additions & 32 deletions cstrike/addons/amxmodx/scripting/ReDeathmatch/Features/Tickets.inc
Original file line number Diff line number Diff line change
@@ -1,67 +1,126 @@
static bool: redm_tickets
static redm_tickets_count
static g_respawnsCount[any: TeamName]

static g_respawnsCount[TeamName]
static redm_tickets
static Float: redm_tickets_hud_update_freq

Tickets_Init() {
RegisterHookChain(RG_CBasePlayer_Killed, "CBasePlayer_Killed", .post = true)

set_task(1.0, "Think_UpdateHUD", .flags = "b")
RegisterHookChain(RG_CSGameRules_FPlayerCanRespawn, "CSGameRules_FPlayerCanRespawn", .post = true)

bind_pcvar_num(
create_cvar(
"redm_tickets", "0",
"redm_tickets", "150",
.has_min = true, .min_val = 0.0,
.has_max = true, .max_val = 1.0,
.flags = _FCVAR_BOOLEAN,
.description = "Is round ticketing enabled?"
.flags = _FCVAR_INTEGER,
.description = "Number of times a team can ^n\
have players respawn before they stop ^n\
being able to respawn. ^n\
`0` - disabled"
),
redm_tickets
)
bind_pcvar_num(
hook_cvar_change(get_cvar_pointer("redm_tickets"), "CvarChange_redm_tickets")

bind_pcvar_float(
create_cvar(
"redm_tickets_count", "150",
"redm_tickets_hud_update_freq", "1.0",
.has_min = true, .min_val = 0.0,
.has_max = false,
.flags = _FCVAR_INTEGER,
.description = "Number of times a team can ^n\
have players respawn before they stop ^n\
being able to respawn."
),
redm_tickets_count
.flags = _FCVAR_FLOAT,
.description = "Tickets HUD update frequency."
),
redm_tickets_hud_update_freq
)

CTickets_UpdateHUD()
}

public CvarChange_redm_tickets(const cvar, const oldValue[], const value[]) {
CTickets_UpdateHUD()
for (new player = 1; player <= MaxClients; player++) {
if (!is_user_connected(player))
continue

new TeamName: team = get_member(player, m_iTeam)
if (CTickets_TeamTicketsLeft(team) == 0)
continue

CTickets_PreventPlayerSpawning(player, .isSpawnAvailable = true)
}
}

Tickets_RestartRound() {
arrayset(g_respawnsCount, 0, sizeof(g_respawnsCount))
Think_UpdateHUD()

CTickets_UpdateHUD()
}

public CBasePlayer_Killed(const player, const killer, const gib) {
if (!IsActive())
return

if (redm_tickets <= 0)
return

new TeamName: team = get_member(player, m_iTeam)
g_respawnsCount[team]++

if (CTickets_TeamTicketsLeft(team) != 0)
return

CTickets_PreventPlayerSpawning(player)
}

public CSGameRules_FPlayerCanRespawn(const player) {
if (!IsActive())
return HC_CONTINUE

if (redm_tickets <= 0)
return HC_CONTINUE

new TeamName: team = get_member(player, m_iTeam)
if (g_respawnsCount[team]++ < redm_tickets_count)

SetHookChainReturn(ATYPE_INTEGER, CTickets_TeamTicketsLeft(team) != 0)
return HC_SUPERCEDE
}

public CTickets_UpdateHUD() {
if (!IsActive())
return

// Prevent player spawn
set_member(player, m_flRespawnPending, 99999999.0)

if (redm_tickets <= 0)
return

CTickets_ShowPlayerTicketsHUD(.player = 0)

const taskId = 9999
remove_task(taskId)
set_task_ex(redm_tickets_hud_update_freq, "CTickets_UpdateHUD", .id = taskId)
}

public Think_UpdateHUD() {
static CTickets_ShowPlayerTicketsHUD(const player = 0) {
set_dhudmessage(
.red = 200,
.green = 200,
.blue = 200,
.y = 0.15,
.y = 0.14,
.effects = 0,
.fadeintime = 0.0,
.fadeouttime = 0.0,
.holdtime = 1.1
.holdtime = (redm_tickets_hud_update_freq + 0.1)
)

show_dhudmessage(player, "T [ %03d - %03d ] CT",
CTickets_TeamTicketsLeft(TEAM_TERRORIST),
CTickets_TeamTicketsLeft(TEAM_CT)
)
}

new ticketsLeft_CT = max(0, redm_tickets_count - g_respawnsCount[TEAM_CT])
new ticketsLeft_T = max(0, redm_tickets_count - g_respawnsCount[TEAM_TERRORIST])
static Float: CTickets_PreventPlayerSpawning(const player, const bool: isSpawnAvailable = false) {
set_member(player, m_flRespawnPending, isSpawnAvailable ? get_gametime() : 9999999.0)

new message[192]
format(message, 100, "T [ %03d - %03d ] CT", ticketsLeft_T, ticketsLeft_CT)
show_dhudmessage(0, "%s", message)
}
return get_member(player, m_flRespawnPending)
}

static CTickets_TeamTicketsLeft(const TeamName: team) {
return max(0, redm_tickets - g_respawnsCount[team])
}

0 comments on commit f965c7a

Please sign in to comment.