Skip to content

Commit

Permalink
Merge pull request #22 from d3m37r4/fix-server-crash-when-starting-wa…
Browse files Browse the repository at this point in the history
…rmup

Fix server crash when starting warmup
  • Loading branch information
byjumpe authored Dec 9, 2023
2 parents 2e44735 + b4236dc commit ff66005
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 13 deletions.
5 changes: 5 additions & 0 deletions cstrike/addons/amxmodx/scripting/regg/config.inl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ enum config_section_s {
};

enum _:game_cvars_s {
Float:GCRoundTime,
GCRoundInfinite[32],
Float:GCForcerespawn,
GCRefillBpammoWeapons,
Expand Down Expand Up @@ -106,6 +107,10 @@ registerCvars() {
changeGameCvars() {
new pcvar;

pcvar = get_cvar_pointer("mp_roundtime");
GameCvars[GCRoundTime] = get_pcvar_float(pcvar);
set_pcvar_float(pcvar, 0.0);

pcvar = get_cvar_pointer("mp_round_infinite");
get_pcvar_string(pcvar, GameCvars[GCRoundInfinite], charsmax(GameCvars[GCRoundInfinite]));
set_pcvar_num(pcvar, 1);
Expand Down
18 changes: 15 additions & 3 deletions cstrike/addons/amxmodx/scripting/regg/functions.inl
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@ bool:start(const ReGG_Mode:mode) {

Mode = mode;
set_member_game(m_bCompleteReset, true);
set_member_game(m_bGameStarted, true);

rg_round_end(
.tmDelay = 3.0,
.st = WINSTATUS_DRAW,
.event = ROUND_END_DRAW,
.message = "GunGame Mod started!",
.sentence = "",
.message = "GunGame Mod started!",
.sentence = "",
.trigger = true
);
DebugMode && log_amx("GunGame Mod started!");

return true;
}
Expand All @@ -46,7 +48,17 @@ bool:finish(const killer, const victim) {

Mode = ReGG_ModeNone;
set_member_game(m_bCompleteReset, true);
rg_restart_round();

rg_round_end(
.tmDelay = 3.0,
.st = WINSTATUS_DRAW,
.event = ROUND_END_DRAW,
.message = "Game over!",
.sentence = "",
.trigger = true
);
DebugMode && log_amx("GunGame Mod finished!");

return true;
}

Expand Down
5 changes: 5 additions & 0 deletions cstrike/addons/amxmodx/scripting/regg_core.sma
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ new Players[MAX_PLAYERS + 1][player_s];
new Teams[2][team_s];
new WeaponIdType:GrenadeWeapons[MAX_GRENADE_WEAPONS], GrenadeWeaponsNum;

new bool:DebugMode;

#include "regg/config.inl"
#include "regg/forwards.inl"
#include "regg/hooks.inl"
Expand All @@ -57,6 +59,9 @@ public plugin_init() {
registerForwards();
loadCfg();
loadIni();

DebugMode = bool:(plugin_flags() & AMX_FLAG_DEBUG);
DebugMode && log_amx("Debug mode is enable!");
}

public plugin_cfg() {
Expand Down
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 ff66005

Please sign in to comment.