Counter-Strike 2 now has hostage scripting. Valve’s update notes, posted Thursday, October 22, add a CSHostage class and six hostage events to the scripting API. Mapmakers can hook every step of a rescue.
Previously on HappyGamer: Cache Map Patched and Demo Chat Locked Down in Latest CS2 Update.
The free-to-play shooter runs on Windows and Linux, according to its Steam page. The patch also adds two new top-level exports, a precache system, and a crash fix.
Earlier: CS2 Update Fixes Rush Pixel Gaps and Castle Clipping.
Six Hostage Events Open Up Rescue Logic
Hostages were closed to scripts before. Now they’re not.
The new events are:
Instance.OnHostagePickUpStart
Instance.OnHostagePickUpAbort
Instance.OnHostagePickUp
Instance.OnHostageDrop
Instance.OnHostageRescue
Instance.OnHostageKill
The CSHostage class backs them up. It has IsBeingPickedUp, IsBeingCarried and IsRescued checks. GetRescuer returns who saved the hostage. GetPickUpStartTime and GetPickUpFinishTime return the pickup timing.
CSPlayerPawn.GetHostage ties a player to the hostage they hold. A custom mode can now reward a rescuer or punish an aborted pickup.
Instance.Precache Hands Over Asset Loading
Instance.Precache returns a CSPrecache object. That object tracks loading on both sides.
IsServerLoading and IsServerLoaded cover the server. IsClientLoading and IsClientLoaded cover the client. IsLoadedForAll tells a script when everyone is ready. Release frees the asset when the script is done.
That means a map can wait for every client before it spawns something heavy.
Console.SetConvar Skips the sv_cheats Check
The new top-level Console export is the biggest scripting change. It ships six convar getters: boolean, number, string, vector, QAngle and color. It also adds SetConvar.
Valve’s note on SetConvar is blunt:
“Console.SetConvar is not restricted by sv_cheats and executes synchronously” – Counter-Strike 2 on Steam
A script can change a convar with cheats off. The change lands immediately, not on the next tick.
Instance.Msg is now Console.Log. Instance.ClientCommand, ServerCommand and RegisterCheatCommand moved to Console too.
GameRules Takes Over Round Control
GameRules is the second new export. It adds StartWarmup, EndWarmup, GetTeamScore, AddTeamScore and TerminateRound.
Scripts can now end a round on command. They can also edit a team’s score directly.
Seven older Instance methods moved over as well:
IsWarmupPeriod
IsFreezePeriod
IsTeamIntroPeriod
GetRoundsPlayed
GetRoundRemainingTime
SetRoundRemainingTime
AddTeamMoney
The old calls still work. Valve marked them deprecated. Existing maps won’t break, but new code should use the new homes.
AddTeamMoney also gets support for CSTeamMoneyReason.NONE with an amount. The same patch fixes a crash in AddTeamMoney when used with that reason.
Radar Elements Leave Rush Behind
radar_element used to show on the radar only in Rush. That limit is gone.
“radar_element can now appear on the radar in every game mode, not just Rush” – Counter-Strike 2 on Steam
A Competitive or Deathmatch map can now put custom markers on the radar. Think objective points or script-spawned targets.
The HUD gets two new top-level custom_hud_layout classes: HUD_TEAMMENU_VISIBLE and HUD_CHAT_VISIBLE. Layouts can now react to the team menu and chat being open.
Move Your Scripts Off the Old Calls
The patch is all API. No weapon, map or economy values changed.
If you maintain a Workshop script, check for Instance.Msg first. Then check the round-state calls. Both have new names and new homes.
Old Instance calls still run. They’re just marked deprecated.