Advertisement
Guest User

Untitled

a guest
Aug 20th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.59 KB | None | 0 0
  1. ///scrSaveGame(saveposition)
  2. ///saves the game
  3. ///argument0 - sets whether the game should save the player's current location or just save the deaths/time
  4.  
  5. var savePosition = argument0;
  6.  
  7. //save the player's current location variables if the script is currently set to (we don't want to save the player's location if we're just updating death/time)
  8. if (savePosition)
  9. {
  10. global.saveRoom = room_get_name(room);
  11. global.savePlayerX = objPlayer.x;
  12. global.savePlayerY = objPlayer.y;
  13. global.saveGrav = global.grav;
  14.  
  15. //check if player is saving inside of a wall or in the ceiling when the player's position is floored to prevent save locking
  16. with (objPlayer)
  17. {
  18. if (!place_free(floor(global.savePlayerX),global.savePlayerY))
  19. {
  20. global.savePlayerX += 1;
  21. }
  22.  
  23. if (!place_free(global.savePlayerX,floor(global.savePlayerY)))
  24. {
  25. global.savePlayerY += 1;
  26. }
  27.  
  28. if (!place_free(floor(global.savePlayerX),floor(global.savePlayerY)))
  29. {
  30. global.savePlayerX += 1;
  31. global.savePlayerY += 1;
  32. }
  33. }
  34.  
  35. //floor player position to match standard engine behavior
  36. global.savePlayerX = floor(global.savePlayerX);
  37. global.savePlayerY = floor(global.savePlayerY);
  38.  
  39. for (var i = 0; i < global.secretItemTotal; i++)
  40. {
  41. global.saveSecretItem[i] = global.secretItem[i];
  42. }
  43.  
  44. for (var i = 0; i < global.bossItemTotal; i++)
  45. {
  46. global.saveBossItem[i] = global.bossItem[i];
  47. }
  48.  
  49. global.saveGameClear = global.gameClear;
  50.  
  51. //Stage Variables
  52. global.saveWolfieItem[0] = global.wolfieItem[0];
  53. global.saveWolfieItem[1] = global.wolfieItem[1];
  54. global.saveZebVars = global.zebVars;
  55. global.saveHubX = global.hubX
  56. global.saveHubY = global.hubY
  57. }
  58.  
  59. //create a map for save data
  60. var saveMap = ds_map_create();
  61.  
  62. ds_map_add(saveMap,"death",global.death);
  63. ds_map_add(saveMap,"time",global.time);
  64. ds_map_add(saveMap,"timeMicro",global.timeMicro);
  65.  
  66. ds_map_add(saveMap,"difficulty",global.difficulty);
  67. ds_map_add(saveMap,"saveRoom",global.saveRoom);
  68. ds_map_add(saveMap,"savePlayerX",global.savePlayerX);
  69. ds_map_add(saveMap,"savePlayerY",global.savePlayerY);
  70. ds_map_add(saveMap,"saveGrav",global.saveGrav);
  71.  
  72. for (var i = 0; i < global.secretItemTotal; i++)
  73. {
  74. ds_map_add(saveMap,"saveSecretItem["+string(i)+"]",global.saveSecretItem[i]);
  75. }
  76.  
  77. for (var i = 0; i < global.bossItemTotal; i++)
  78. {
  79. ds_map_add(saveMap,"saveBossItem["+string(i)+"]",global.saveBossItem[i]);
  80. }
  81.  
  82. ds_map_add(saveMap,"saveGameClear",global.saveGameClear);
  83.  
  84. //Custom variables
  85. ds_map_add(saveMap,"saveWolfieItem[0]",global.saveWolfieItem[0]);
  86. ds_map_add(saveMap,"saveWolfieItem[1]",global.saveWolfieItem[1]);
  87. ds_map_add(saveMap,"saveZebVars",global.saveZebVars);
  88. ds_map_add(saveMap,"saveHubX",global.saveHubX);
  89. ds_map_add(saveMap,"saveHubY",global.saveHubY);
  90.  
  91. //add md5 hash to verify saves and make them harder to hack
  92. ds_map_add(saveMap,"mapMd5",md5_string_unicode(json_encode(saveMap)+global.md5StrAdd));
  93.  
  94. //save the map to a file
  95. if (global.extraSaveProtection) //use ds_map_secure function
  96. {
  97. ds_map_secure_save(saveMap,"Data\save"+string(global.savenum));
  98. }
  99. else //use text file
  100. {
  101. //open the save file
  102. var f = file_text_open_write("Data\save"+string(global.savenum));
  103.  
  104. //write map to the save file with base64 encoding
  105. file_text_write_string(f,base64_encode(json_encode(saveMap)));
  106.  
  107. file_text_close(f);
  108. }
  109.  
  110. //destroy the map
  111. ds_map_destroy(saveMap);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement