Skip to content

Commit

Permalink
Feature: New spawns style "random" (#106)
Browse files Browse the repository at this point in the history
* Add `rog.inc`

- ROG is an include file which allows you to generate random valid origins around the map. It could be used to create random player spawns or in Battle Royale mods(PUBG/Fortnite) to spawn the floor loot/drop crates/llamas, etc.

* redm_spawns: add `random` spawn preset

* ConVar `redm_spawn_preset` hot change support

* CvarChange_redm_spawn_preset: rework api usage

* better ConVar desc
  • Loading branch information
wopox1337 committed Mar 28, 2024
1 parent d40db0a commit 6af77ac
Show file tree
Hide file tree
Showing 5 changed files with 431 additions and 2 deletions.
5 changes: 4 additions & 1 deletion cstrike/addons/amxmodx/configs/redm/gamemode_deathmatch.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@
// Minimum distance to the enemy to enable spawn checks.
"redm_randomspawn_dist": "1500",

// Name of the spawn manager
/* Name of the spawn manager style.
`none`,
`preset`,
`random` - (beta) */
"redm_spawn_preset": "preset",

// ReDM: Features
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,22 @@ SpawnManager_Init() {
redm_spawn_preset,
charsmax(redm_spawn_preset)
)
hook_cvar_change(get_cvar_pointer("redm_spawn_preset"), "CvarChange_redm_spawn_preset")

RegisterHookChain(RG_CSGameRules_GetPlayerSpawnSpot, "CSGameRules_GetPlayerSpawnSpot", .post = false)

redm_setstyle(redm_spawn_preset)
}

public CvarChange_redm_spawn_preset(const cvar, const oldValue[], const value[]) {
new bool: result = redm_setstyle(value)
if (result)
return

set_pcvar_string(cvar, oldValue)
LogMessageEx(Warning, "CvarChange_redm_spawn_preset: Spawn preset style `%s` not found!", value)
}

public CSGameRules_GetPlayerSpawnSpot(const player) {
if (!IsActive())
return HC_CONTINUE
Expand Down
5 changes: 4 additions & 1 deletion cstrike/addons/amxmodx/scripting/include/redm.inc
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,11 @@ native redm_addstyle(const name[], const function[])
/**
* Sets the current spawn style handler by name.
* The handler registered to this name will be called after every spawn.
*
* @param name Style preset name.
* @return True if the style has been set, otherwise false.
*/
native redm_setstyle(const name[])
native bool: redm_setstyle(const name[])

/**
* Returns the current style ID.
Expand Down
Loading

0 comments on commit 6af77ac

Please sign in to comment.