Skip to content

Commit

Permalink
Fix server crash when starting warmup. Minor changes in mechanics.
Browse files Browse the repository at this point in the history
  • Loading branch information
d3m37r4 committed Dec 8, 2023
1 parent 8ad4785 commit b4236dc
Showing 1 changed file with 38 additions and 10 deletions.
48 changes: 38 additions & 10 deletions cstrike/addons/amxmodx/scripting/regg_warmup.sma
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ enum _:hook_s {
HookChain:HookHasRestrictItem,
HookChain:HookPlayerSpawn,
HookChain:HookPlayerKilled,
HookChain:HookRoundEnd,
};
new HookChain:Hooks[hook_s];

Expand Down Expand Up @@ -52,6 +53,8 @@ new SyncHud;

new bool:DebugMode;

#define getLangKey(%0) fmt("%l", %0)

public plugin_init() {
register_plugin("[ReGG] WarmUp", REGG_VERSION_STR, "Jumper & d3m37r4");

Expand Down Expand Up @@ -88,6 +91,7 @@ public ReGG_StartPre(const ReGG_Mode:mode) {
return PLUGIN_HANDLED;
}

// Block the launch of mod and call start of warmup
Mode = mode;
startWarmUp();

Expand Down Expand Up @@ -125,6 +129,17 @@ public CBasePlayer_Killed_Post(const id) {
return HC_CONTINUE;
}

public RoundEnd_Pre(WinStatus:status, ScenarioEventEndRound:event, Float:tmDelay) {
if(Status == StatusStarted && status == WINSTATUS_DRAW && event == ROUND_GAME_COMMENCE) {
return HC_CONTINUE;
}

SetHookChainArg(1, ATYPE_INTEGER, WINSTATUS_NONE);
SetHookChainArg(2, ATYPE_INTEGER, ROUND_NONE);
stopWarmUp();
return HC_CONTINUE;
}

public startWarmUp() {
if(Status == StatusStarted) {
return;
Expand All @@ -136,11 +151,15 @@ public startWarmUp() {
toggleHooks(StateEnable);

set_member_game(m_bCompleteReset, false);
rg_restart_round();
rg_round_end(
.tmDelay = 0.0,
.st = WINSTATUS_DRAW,
.event = ROUND_GAME_COMMENCE,
.message = _replace_string_ex(getLangKey("REGG_WARMUP_START"), "$n", "^r", true),
.sentence = "",
.trigger = true
);

set_task(float(WarmupTime), "stopWarmUp");

client_print(0, print_center, "%L", LANG_PLAYER, "REGG_WARMUP_START");
DebugMode && log_amx("Warmup mode is started!");
}

Expand All @@ -163,25 +182,24 @@ public stopWarmUp() {
ClearSyncHud(player, SyncHud);
}

ReGG_Start(Mode);

client_print(0, print_center, "%L", LANG_PLAYER, "REGG_WARMUP_END");

ReGG_Start(Mode);
DebugMode && log_amx("Warmup mode is finished!");
}

registerHooks() {
Hooks[HookHasRestrictItem] = RegisterHookChain(RG_CBasePlayer_HasRestrictItem, "CBasePlayer_HasRestrictItem_Pre", false);
Hooks[HookPlayerSpawn] = RegisterHookChain(RG_CBasePlayer_Spawn, "CBasePlayer_Spawn_Post", true);
Hooks[HookPlayerKilled] = RegisterHookChain(RG_CBasePlayer_Killed, "CBasePlayer_Killed_Post", true);
Hooks[HookRoundEnd] = RegisterHookChain(RG_RoundEnd, "RoundEnd_Pre", false);
}

toggleHooks(state_s:_state) {
for(new i; i < hook_s; i++) {
if(!Hooks[i]) {
continue;
if(Hooks[i]) {
_state == StateEnable ? EnableHookChain(Hooks[i]) : DisableHookChain(Hooks[i]);
}

_state == StateEnable ? EnableHookChain(Hooks[i]) : DisableHookChain(Hooks[i]);
}
}

Expand Down Expand Up @@ -234,3 +252,13 @@ restoreGameCvars() {
pcvar = get_cvar_pointer("mp_weapons_allow_map_placed");
set_pcvar_num(pcvar, GameCvars[GCWeaponsAllowMapPlaced]);
}

// https://github.com/d3m37r4/AMXX_Plugins/blob/aecab54d525389c0cc9cc274ff87a518b9369521/Simple_WarmUp_Mode/simple_warmup_mode.sma#L514
stock _replace_string_ex(const _buffer[], const _search[], const _string[], bool:_caseSensitive = true) {
new buffer[MAX_FMT_LENGTH];

formatex(buffer, charsmax(buffer), _buffer);
replace_string(buffer, charsmax(buffer), _search, _string, _caseSensitive);

return buffer;
}

0 comments on commit b4236dc

Please sign in to comment.