@@ -23,13 +23,33 @@ export class GameMode {
2323
2424 constructor ( ) {
2525 this . configure ( ) ;
26+
27+ // Register event listeners for dota engine events
2628 ListenToGameEvent ( "game_rules_state_change" , ( ) => this . OnStateChange ( ) , undefined ) ;
2729 ListenToGameEvent ( "npc_spawned" , event => this . OnNpcSpawned ( event ) , undefined ) ;
30+
31+ // Register event listeners for events from the UI
32+ CustomGameEventManager . RegisterListener ( "ui_panel_closed" , ( _ , data ) => {
33+ print ( `Player ${ data . PlayerID } has closed their UI panel.` ) ;
34+
35+ // Respond by sending back an example event
36+ const player = PlayerResource . GetPlayer ( data . PlayerID ) ! ;
37+ CustomGameEventManager . Send_ServerToPlayer ( player , "example_event" , {
38+ myNumber : 42 ,
39+ myBoolean : true ,
40+ myString : "Hello!" ,
41+ myArrayOfNumbers : [ 1.414 , 2.718 , 3.142 ]
42+ } ) ;
43+
44+ // Also apply the panic modifier to the sending player's hero
45+ const hero = player . GetAssignedHero ( ) ;
46+ hero . AddNewModifier ( hero , undefined , modifier_panic . name , { duration : 5 } ) ;
47+ } ) ;
2848 }
2949
3050 private configure ( ) : void {
31- GameRules . SetCustomGameTeamMaxPlayers ( DOTATeam_t . DOTA_TEAM_GOODGUYS , 3 ) ;
32- GameRules . SetCustomGameTeamMaxPlayers ( DOTATeam_t . DOTA_TEAM_BADGUYS , 3 ) ;
51+ GameRules . SetCustomGameTeamMaxPlayers ( DotaTeam . GOODGUYS , 3 ) ;
52+ GameRules . SetCustomGameTeamMaxPlayers ( DotaTeam . BADGUYS , 3 ) ;
3353
3454 GameRules . SetShowcaseTime ( 0 ) ;
3555 GameRules . SetHeroSelectionTime ( heroSelectionTime ) ;
@@ -39,13 +59,13 @@ export class GameMode {
3959 const state = GameRules . State_Get ( ) ;
4060
4161 // Add 4 bots to lobby in tools
42- if ( IsInToolsMode ( ) && state == DOTA_GameState . DOTA_GAMERULES_STATE_CUSTOM_GAME_SETUP ) {
62+ if ( IsInToolsMode ( ) && state == GameState . CUSTOM_GAME_SETUP ) {
4363 for ( let i = 0 ; i < 4 ; i ++ ) {
4464 Tutorial . AddBot ( "npc_dota_hero_lina" , "" , "" , false ) ;
4565 }
4666 }
4767
48- if ( state === DOTA_GameState . DOTA_GAMERULES_STATE_CUSTOM_GAME_SETUP ) {
68+ if ( state === GameState . CUSTOM_GAME_SETUP ) {
4969 // Automatically skip setup in tools
5070 if ( IsInToolsMode ( ) ) {
5171 Timers . CreateTimer ( 3 , ( ) => {
@@ -55,7 +75,7 @@ export class GameMode {
5575 }
5676
5777 // Start game once pregame hits
58- if ( state === DOTA_GameState . DOTA_GAMERULES_STATE_PRE_GAME ) {
78+ if ( state === GameState . PRE_GAME ) {
5979 Timers . CreateTimer ( 0.2 , ( ) => this . StartGame ( ) ) ;
6080 }
6181 }
@@ -76,11 +96,8 @@ export class GameMode {
7696 private OnNpcSpawned ( event : NpcSpawnedEvent ) {
7797 // After a hero unit spawns, apply modifier_panic for 8 seconds
7898 const unit = EntIndexToHScript ( event . entindex ) as CDOTA_BaseNPC ; // Cast to npc since this is the 'npc_spawned' event
99+ // Give all real heroes (not illusions) the meepo_earthbind_ts_example spell
79100 if ( unit . IsRealHero ( ) ) {
80- Timers . CreateTimer ( 1 , ( ) => {
81- unit . AddNewModifier ( unit , undefined , modifier_panic . name , { duration : 8 } ) ;
82- } ) ;
83-
84101 if ( ! unit . HasAbility ( "meepo_earthbind_ts_example" ) ) {
85102 // Add lua ability to the unit
86103 unit . AddAbility ( "meepo_earthbind_ts_example" ) ;
0 commit comments