Guest User

Untitled

a guest
Feb 7th, 2025
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.66 KB | None | 0 0
  1. // main global script file
  2.  
  3. // called when the game starts, before the first room is loaded
  4. function game_start()
  5. {
  6. }
  7.  
  8. // called on every game cycle, except when the game is blocked
  9. function repeatedly_execute()
  10. {
  11. LabelInfo.Text = Game.GetLocationName(mouse.x, mouse.y) ;
  12. }
  13.  
  14. // called on every game cycle, even when the game is blocked
  15. function repeatedly_execute_always()
  16. {
  17. }
  18.  
  19. // called when a key is pressed
  20. function on_key_press(eKeyCode keycode)
  21. {
  22. if (IsGamePaused())
  23. {
  24. // game paused, so don't react to any keypresses
  25. keycode = 0;
  26. }
  27. else if (keycode == eKeyCtrlQ)
  28. {
  29. // Ctrl-Q will quit the game
  30. QuitGame(1);
  31. }
  32. else if (keycode == eKeyF9)
  33. {
  34. // F9 will restart the game
  35. RestartGame();
  36. }
  37. else if (keycode == eKeyF12)
  38. {
  39. // F12 will save a screenshot to the save game folder
  40. SaveScreenShot("screenshot.pcx");
  41. }
  42. else if (keycode == eKeyCtrlS)
  43. {
  44. // Ctrl-S will give the player all defined inventory items
  45. Debug(0, 0);
  46. }
  47. else if (keycode == eKeyCtrlV)
  48. {
  49. // Ctrl-V will show game engine version and build date
  50. Debug(1, 0);
  51. }
  52. else if (keycode == eKeyCtrlA)
  53. {
  54. // Ctrl-A will show walkable areas
  55. Debug(2, 0);
  56. }
  57. else if (keycode == eKeyCtrlX)
  58. {
  59. // Ctrl-X will let the player teleport to any room
  60. Debug(3, 0);
  61. }
  62. }
  63.  
  64. function do_room_action(MouseButton button)
  65. {
  66. if (button == eMouseRight && player.ActiveInventory != null) {
  67. player.ActiveInventory = null;
  68. mouse.Mode = eModePointer;
  69. }
  70. else if (GetLocationType(mouse.x, mouse.y) != eLocationNothing)
  71. {
  72. // clicked on something
  73. if (player.ActiveInventory == null)
  74. {
  75. if (button == eMouseLeft) {
  76. Room.ProcessClick(mouse.x, mouse.y, eModeInteract);
  77. }
  78. else {
  79. Room.ProcessClick(mouse.x, mouse.y, eModeLookat);
  80. }
  81. }
  82. else
  83. {
  84. if (button == eMouseLeft)
  85. {
  86. // left click to use inventory on target
  87. Room.ProcessClick(mouse.x, mouse.y, eModeUseinv);
  88. }
  89. else
  90. {
  91. // right click to deselect inventory item
  92. player.ActiveInventory = null;
  93. Mouse.Mode = eModePointer;
  94. }
  95. }
  96. }
  97. else
  98. {
  99. // click on nothing
  100. if (player.ActiveInventory == null)
  101. {
  102. // left click to walk
  103. Room.ProcessClick(mouse.x, mouse.y, eModeWalkto);
  104. }
  105. else
  106. {
  107. // right click to deselect inventory item
  108. player.ActiveInventory = null;
  109. Mouse.Mode = eModePointer;
  110. }
  111. }
  112. }
  113.  
  114. function do_inventory_action(MouseButton button, InventoryItem* item)
  115. {
  116. if (button == eMouseLeftInv)
  117. {
  118. if (player.ActiveInventory == null)
  119. {
  120. // left click to set active inventory item
  121. player.ActiveInventory = item;
  122. }
  123. else if (item.ID != player.ActiveInventory.ID)
  124. {
  125. // left click to use active inventory on another item
  126. item.RunInteraction(eModeUseinv);
  127. }
  128. else
  129. {
  130. // left click item on itself to deselect it
  131. player.ActiveInventory = null;
  132. Mouse.Mode = eModePointer;
  133. }
  134. }
  135. else
  136. {
  137. if (player.ActiveInventory == null)
  138. {
  139. // right click to look at inventory item
  140. item.RunInteraction(eModeLookat);
  141. }
  142. else
  143. {
  144. // right click to deselect inventory item
  145. player.ActiveInventory = null;
  146. Mouse.Mode = eModePointer;
  147. }
  148. }
  149. }
  150.  
  151. //----------------------------------------------------------------------------------------------------
  152. // on_mouse_click()
  153. //----------------------------------------------------------------------------------------------------
  154. function on_mouse_click(MouseButton button)
  155. {
  156. // when mouse is clicked, text label is cleared
  157. if (LabelInfo != null)
  158. {
  159. LabelInfo.Text = "";
  160. }
  161.  
  162. if (!IsGamePaused() && (button == eMouseLeft || button == eMouseRight))
  163. {
  164. do_room_action(button);
  165. }
  166. else if (button == eMouseLeftInv || button == eMouseRightInv)
  167. {
  168. // InventoryItem.GetAtScreenXY could return null here
  169. // so using game.inv_activated instead is a safer option
  170. do_inventory_action(button, inventory[game.inv_activated]);
  171. }
  172. }
  173.  
  174. function dialog_request(int param) {
  175. }
  176. function ButtonSave_OnClick(GUIControl *control, MouseButton button)
  177. {
  178. Display("Game Saved.");
  179. SaveGameSlot(0, "Saved Game");
  180. }
  181.  
  182. function ButtonLoad_OnClick(GUIControl *control, MouseButton button)
  183. {
  184. if (Game.GetSaveSlotDescription(0) != null) RestoreGameSlot(0);
  185. }
  186.  
  187. function ButtonRestart_OnClick(GUIControl *control, MouseButton button)
  188. {
  189. RestartGame();
  190. }
  191.  
  192. function ButtonQuit_OnClick(GUIControl *control, MouseButton button)
  193. {
  194. QuitGame(0);
  195. }
Advertisement
Add Comment
Please, Sign In to add comment