Author Topic: Patch [committed]: $On Gameplay Start scripting hook  (Read 1220 times)

0 Members and 1 Guest are viewing this topic.

Offline zookeeper

  • *knock knock* Who's there? Poe. Poe who?
  • 210
Patch [committed]: $On Gameplay Start scripting hook
As discussed here, all the current methods of getting a piece of script to run once when the mission gameplay starts are somewhat hacky (checking mission time, setting a flag variable, etc), so this patch adds a hook for precisely that purpose.

Code: [Select]
Index: freespace2/freespace.cpp
===================================================================
--- freespace2/freespace.cpp (revision 8049)
+++ freespace2/freespace.cpp (working copy)
@@ -5199,6 +5199,8 @@
  extern button_info Multi_ship_status_bi;
  memset(&Multi_ship_status_bi, 0, sizeof(button_info));
 
+ Script_system.RunCondition(CHA_GAMEPLAYSTART);
+
  Start_time = f2fl(timer_get_approx_seconds());
  //Framecount = 0;
  mprintf(("Entering game at time = %7.3f\n", Start_time));
Index: parse/scripting.cpp
===================================================================
--- parse/scripting.cpp (revision 8049)
+++ parse/scripting.cpp (working copy)
@@ -56,6 +56,7 @@
  {"On Mouse Released", CHA_MOUSERELEASED, 0},
  {"On State End", CHA_ONSTATEEND, 0},
  {"On Mission Start", CHA_MISSIONSTART, 0},
+ {"On Gameplay Start", CHA_GAMEPLAYSTART, 0},
  {"On HUD Draw", CHA_HUDDRAW, 0},
  {"On Ship Collision", CHA_COLLIDESHIP, 0},
  {"On Weapon Collision", CHA_COLLIDEWEAPON, 0},
Index: parse/scripting.h
===================================================================
--- parse/scripting.h (revision 8049)
+++ parse/scripting.h (working copy)
@@ -52,19 +52,20 @@
 #define CHA_SPLASHSCREEN 10
 #define CHA_GAMEINIT 11
 #define CHA_MISSIONSTART 12
-#define CHA_MISSIONEND 13
-#define CHA_MOUSEMOVED 14
-#define CHA_MOUSEPRESSED 15
-#define CHA_MOUSERELEASED 16
-#define CHA_KEYPRESSED 17
-#define CHA_KEYRELEASED 18
-#define CHA_ONSTATESTART 19
-#define CHA_ONSTATEEND 20
-#define CHA_ONWEAPONDELETE 21
-#define CHA_ONWPEQUIPPED 22
-#define CHA_ONWPFIRED 23
-#define CHA_ONWPSELECTED 24
-#define CHA_ONWPDESELECTED 25
+#define CHA_GAMEPLAYSTART 13
+#define CHA_MISSIONEND 14
+#define CHA_MOUSEMOVED 15
+#define CHA_MOUSEPRESSED 16
+#define CHA_MOUSERELEASED 17
+#define CHA_KEYPRESSED 18
+#define CHA_KEYRELEASED 19
+#define CHA_ONSTATESTART 20
+#define CHA_ONSTATEEND 21
+#define CHA_ONWEAPONDELETE 22
+#define CHA_ONWPEQUIPPED 23
+#define CHA_ONWPFIRED 24
+#define CHA_ONWPSELECTED 25
+#define CHA_ONWPDESELECTED 26
 
 // management stuff
 void scripting_state_init();

Sorry about the mess with the renumberings, but that really needed to be next to $On Mission Start.
« Last Edit: November 29, 2011, 04:00:57 pm by zookeeper »

 

Offline Aardwolf

  • 211
  • Posts: 16,384
    • Minecraft
Re: Patch: $On Gameplay Start scripting hook
I was just thinking about that!  :yes:

 

Offline zookeeper

  • *knock knock* Who's there? Poe. Poe who?
  • 210
Re: Patch [committed]: $On Gameplay Start scripting hook
Unfortunately, the above patch doesn't make hv.Player available. This should fix that:

Code: [Select]
Index: freespace.cpp
===================================================================
--- freespace.cpp (revision 8101)
+++ freespace.cpp (working copy)
@@ -5202,8 +5202,15 @@
  extern button_info Multi_ship_status_bi;
  memset(&Multi_ship_status_bi, 0, sizeof(button_info));
 
+ // Make hv.Player available in "On Gameplay Start" hook -zookeeper
+ if(Player_obj)
+ Script_system.SetHookObject("Player", Player_obj);
+
  Script_system.RunCondition(CHA_GAMEPLAYSTART);
 
+ if (Player_obj)
+ Script_system.RemHookVar("Player");
+
  Start_time = f2fl(timer_get_approx_seconds());
  //Framecount = 0;
  mprintf(("Entering game at time = %7.3f\n", Start_time));