Skip to content

Instantly share code, notes, and snippets.

@packer-
Created December 11, 2017 12:40
Show Gist options
  • Save packer-/f38333818e3f8d67e2e839dccfd8b3a6 to your computer and use it in GitHub Desktop.
Save packer-/f38333818e3f8d67e2e839dccfd8b3a6 to your computer and use it in GitHub Desktop.
//
// Warmup Limiter & Notifier
// -------------------------
// version: 0.45
// by packer - April 29th 2017
//
// This scripts notifies clients about warmup mode and
// calls restart if soft or hard time limit is reached.
//
// No client is connected (soft limit):
// 1) Server restarts if *wln_wup_limit_soft* is exceeded and
// *wln_restart_msg_echo* is echoed to server console
//
// A client is connected (hard limit):
// 1) Map is restarted if *wln_wup_limit_hard* is exceeded and
// *wln_restart_msg_say* is sent as message
// 2) During warmup a notification *wln_msg_notify* is sent
// to clients every *wln_notify_time* seconds
//
// How to run:
// exec script_warmup_limitnofiy.cfg
// wln_run
// user settings:
set wln_wup_limit_hard "60" // in minutes
set wln_wup_limit_soft "30" // in minutes
set wln_notify_time "2.5" // in minutes
set wln_defer "5" // in seconds - loop timer
set wln_msg_notify "^2Currently in ^1warmup ^2stage. Press ^3F4 ^2to ready up!^7"
set wln_restart_msg_say "^1Warmup ^2stage of $wln_wup_limit_hard min exceeded... ^3Restarting^2...^7"
set wln_restart_msg_echo "^1Warmup ^2stage of $wln_wup_limit_soft min exceeded... ^3Restarting^2...^7"
// --------------------------------------------------------------------------------
// enforce unlimited warmup (make sure the game does not bypass the script)
g_warmup_limit -1
// initialize internal script variables
set _wln_wup_limit_hard_sec "0"
set _wln_wup_limit_soft_sec "0"
set _wln_notify_time_sec "0"
set _wln_wup_stage "0"
set _wln_clients "0"
set _wln_has_client "0"
set _wln_time "0"
set _wln_limit "0"
set _wln_notify_mod "0"
set _wln_notify "0"
// convert minutes to seconds
sv_cmd rpn /_wln_wup_limit_hard_sec $wln_wup_limit_hard 60 mul def
sv_cmd rpn /_wln_wup_limit_soft_sec $wln_wup_limit_soft 60 mul def
sv_cmd rpn /_wln_notify_time_sec $wln_notify_time 60 mul def
// aliases to get globals: warmup stage and time
alias wln_get_clients "prvm_globalget server player_count _wln_clients"
alias wln_get_wup_stage "prvm_globalget server warmup_stage _wln_wup_stage"
alias wln_get_time "prvm_globalget server time _wln_time"
// aliases to define if conditions
alias wln_check_client "sv_cmd rpn /_wln_has_client $_wln_clients 0 gt def"
alias wln_check_limit "sv_cmd rpn /_wln_limit $1 $_wln_time gt def" // we pass hard or soft limit
alias wln_check_notify "sv_cmd rpn /_wln_notify_mod $_wln_time $_wln_notify_time_sec mod def"
alias wln_check_notify2 "sv_cmd rpn /_wln_notify $wln_defer $_wln_notify_mod gt def"
// check if warmup is active
alias wln_if_warmup "wln_get_wup_stage; wln_if_warmup2"
alias wln_if_warmup2 "wln_if_warmup_${_wln_wup_stage}"
alias wln_if_warmup_1 "wln_if_client" // we are in warmup stage
alias wln_if_warmup_0 "wln_continue"
// check if client is connected (includes bots)
alias wln_if_client "wln_get_clients; wln_check_client; wln_if_clients2"
alias wln_if_clients2 "wln_if_client_${_wln_has_client}"
alias wln_if_client_1 "wln_if_limit $_wln_wup_limit_hard_sec" // without client
alias wln_if_client_0 "wln_if_limit $_wln_wup_limit_soft_sec" // with client
// check if time exceeds warmup limit
alias wln_if_limit "wln_get_time; wln_check_limit $1; wln_if_limit2"
alias wln_if_limit2 "wln_if_limit_${_wln_limit}_${_wln_has_client}"
alias wln_if_limit_0_0 "wln_restart" // limit reached, without client (soft)
alias wln_if_limit_0_1 "wln_restart" // limit reached, with client (hard)
alias wln_if_limit_1_0 "wln_continue" // limit not reached, without client
alias wln_if_limit_1_1 "wln_if_notify" // limit not reached, with client
// check if a notification shall be sent
alias wln_if_notify "wln_check_notify; wln_check_notify2; wln_if_notify2"
alias wln_if_notify2 "wln_if_notify_${_wln_notify}"
alias wln_if_notify_1 "say \"$wln_msg_notify\"; wln_continue"
alias wln_if_notify_0 "wln_continue"
// restart command
alias wln_restart_1 "say $wln_restart_msg_say"
alias wln_restart_0 "echo $wln_restart_msg_echo"
alias wln_restart "wln_restart_${_wln_has_client}; defer 3 \"restart; wln_continue\""
// loop statement
alias wln_continue "defer $wln_defer wln_if_warmup"
// main
alias wln_run "wln_if_warmup"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment