Guest User

KaM_Remake_Mines_Script

a guest
Dec 26th, 2019
120
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //a script for replenishing mines
  2. //when game starts, it search the map and saves positions and tile numbers of all mineable tiles
  3. //during the game, it replaces mineable tiles with starting tiles when called,
  4. //effectively restoring mined tiles
  5. //should be compatible with about any map
  6. //no idea if there was something like an "onTileChanged" event at the time of writing
  7. //that would allow a much cleaner and faster script
  8. //this script can make map loading several seconds longer and
  9. //cause a minor "hiccup" every time replenishing is called
  10.  
  11. var
  12. infminOptions: array [1..27] of integer; //these variables are used in the script (copy and paste them under var)
  13. infminTiles: array [1..256] of array [1..256] of array [1..4] of integer;
  14. infmini1,infmini2,infmini3: integer;
  15. infminp1,infminp2: integer;
  16.  
  17. //Following 2 procedures replenish mines, insert them between variables and game procedures that call them
  18. Procedure SetInfiniteMines; //this procedure saves the original state of the map
  19. begin
  20. for infmini1:= 1 to 14 do
  21. begin
  22. infminOptions [infmini1]:=infmini1+127;
  23. end;
  24. infminOptions [14]:=195;
  25. for infmini1:= 1 to 12 do
  26. begin
  27. infminOptions [infmini1+15]:=infmini1+143;
  28. end;
  29.  
  30. infminp1:=1;
  31. infminp2:=1;
  32.  
  33. for infmini1:=1 to States.MapWidth-1 do
  34. for infmini2:=1 to States.MapHeight-1 do
  35. begin
  36. for infmini3:=1 to 27 do
  37. if (States.MapTileType(infmini1,infmini2) = infminOptions [infmini3]) then
  38. begin
  39. infminTiles[infminp1][infminp2][1]:=infmini1;
  40. infminTiles[infminp1][infminp2][2]:=infmini2;
  41. infminTiles[infminp1][infminp2][3]:=States.MapTileType(infmini1,infmini2);
  42. infminTiles[infminp1][infminp2][4]:=States.MapTileRotation(infmini1,infmini2);
  43. infminp2:=infminp2+1;
  44. end;
  45. if (infminp2 = States.MapWidth-1) then
  46. begin
  47. infminp2:=1;
  48. infminp1:=infminp1+1;
  49. end;
  50. end;
  51. end;
  52.  
  53. Procedure ReplenishMines; //this procedure restores the original state of the map
  54. begin
  55. if infminp1 = 1 then
  56. begin
  57. for infmini1:=1 to infminp2 do
  58. begin
  59. Actions.MapTileSet (infminTiles[1][infmini1][1],infminTiles[1][infmini1][2],infminTiles[1][infmini1][3],infminTiles[1][infmini1][4]);
  60. end;
  61. end;
  62. if infminp1 <> 1 then
  63. begin
  64. for infmini1:=1 to (infminp1-1) do
  65. for infmini2:=1 to States.MapWidth-1 do
  66. begin
  67. Actions.MapTileSet (infminTiles[infmini1][infmini2][1],infminTiles[infmini1][infmini2][2],infminTiles[infmini1][infmini2][3],infminTiles[infmini1][infmini2][4]);
  68. end;
  69. for infmini2:=1 to infminp2 do Actions.MapTileSet (infminTiles[infminp1][infmini2][1],infminTiles[infminp1][infmini2][2],infminTiles[infminp1][infmini2][3],infminTiles[infminp1][infmini2][4]);
  70. end;
  71. end;
  72. //these 2 procedures need to be called in game's procedures to do their job
  73.  
  74.  
  75. procedure OnMissionStart;
  76. begin
  77. SetInfiniteMines; //has to be called before replenishing starts
  78. end;
  79.  
  80.  
  81.  
  82.  
  83.  
  84. procedure OnTick;
  85. begin
  86. if (States.GameTime mod 300 = 5) then //every 30 seconds (300 ticks), can be set to whatever map maker wants
  87. ReplenishMines;
  88. end;
RAW Paste Data