Advertisement
dagiccross

Mining

Oct 28th, 2014
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.00 KB | None | 0 0
  1. /*=========================================================
  2. Variant Mining
  3. by Mumbles
  4. ===========================================================
  5. Idea: http://goo.gl/ndXr6R
  6. ===========================================================
  7. Description:
  8. A simple mining system; allows for interacting players to
  9. excavate minerals by "mining" them with special equipment
  10. and tools. Minerals disappear and respawn randomly; chance
  11. is determined by configuration.
  12.  
  13. Configuration is mostly done in arrays so that settings may
  14. be changed with no modifications to the script. Duplicate
  15. in additional locations as needed; update the value of
  16. '.var_amount' correspondingly.
  17. ===========================================================
  18. Compatibility:
  19. Optimised for Hercules emulators.
  20. ===========================================================
  21. Changelog:
  22. v1.0 - First version.
  23. v1.0.1 - Fixed issue with success algorithm.
  24. v1.0.2 - Added randomised debris.
  25. v1.0.3 - Added additional locations in Payon Cave.
  26. v2.0 - Optimised for Hercules emulators.
  27. v2.0.1 - Updated algorithms.
  28. v2.0.2 - Added randomised disappearing and respawning.
  29. v2.0.3 - Updated version format.
  30. =========================================================*/
  31.  
  32. - script Variant Mineral#0::mining 1907,{
  33.  
  34. /*-----------------------------------------------------
  35. Script
  36. -----------------------------------------------------*/
  37. // Check equipment
  38. for (.@i = 0; .@i < getarraysize(.equip); .@i++) {
  39. if (!isequipped(.equip[.@i])) {
  40. message strcharinfo(0), "You need to have '"+ getitemname(.equip[.@i]) +"' equipped to mine!";
  41. .@unequipped++;
  42. }
  43. }
  44.  
  45. // Show count of equipment not worn
  46. if (.@unequipped) {
  47. message strcharinfo(0), .@unequipped +" of "+ getarraysize(.equip) +" equipment has not been worn.";
  48. end;
  49. }
  50.  
  51. // Check tools
  52. for (.@i = 0; .@i < getarraysize(.tool); .@i += 2) {
  53. if (countitem(.tool[.@i]) < .tool[.@i + 1]) {
  54. message strcharinfo(0), "You need to bring "+ .tool[.@i + 1] +" "+ getitemname(.tool[.@i]) +" to mine!";
  55. .@gearless++;
  56. }
  57. }
  58.  
  59. // Show count of tools not in inventory
  60. if (.@gearless) {
  61. .@grammar$ = (getarraysize(.tool) > 1 ? "tools were" : "tool was");
  62. message strcharinfo(0), .@gearless +" of "+ getarraysize(.tool) +" "+ .@grammar$ +" not brought.";
  63. end;
  64. }
  65.  
  66. // Progress
  67. message strcharinfo(0), "Mining in progress...";
  68. progressbar "green", .progress;
  69.  
  70. // Delete tools
  71. for (.@i = 0; .@i < getarraysize(.tool); .@i += 2) {
  72. delitem .tool[.@i], .tool[.@i + 1];
  73. }
  74.  
  75. // Audio/visual effects
  76. soundeffect .sound$, 0;
  77. specialeffect .effect;
  78.  
  79. // Drop random debris
  80. getmapxy(.@m$, .@x, .@y, 0);
  81. .@scatter = rand(1, .limit);
  82. for (.@i = 0; .@i < .@scatter; .@i++) {
  83. .@random = rand(2) * (!rand(1) ? -1 : 1);
  84. makeitem .debris, 1, .@m$, .@x + .@random, .@y + .@random;
  85. }
  86.  
  87. // Randomize target mineral to mine
  88. do {
  89. .@target = rand(getarraysize(.mineral));
  90. } while (.@target % 2);
  91.  
  92. // Max range of success
  93. .@range = .success[.@target + 1];
  94.  
  95. // Check if failed
  96. if (rand(1, .@range) != .success[.@target]) {
  97. message strcharinfo(0), "Nothing valuable was excavated...";
  98. } else {
  99. // Get mineral(s)
  100. getitem .mineral[.@target], .mineral[.@target + 1];
  101. message strcharinfo(0), "You have successfully mined "+ .mineral[.@target + 1] +" "+ getitemname(.mineral[.@target]) +"!";
  102. callfunc ("npcmove",1);
  103. }
  104. end;
  105.  
  106.  
  107. OnInit:
  108. // Minerals (constant/ID, amount)
  109. setarray .mineral[0], 1010, 5, 1011, 3, 984, 1, 985, 1, 7807, 1, 7231, 1, 7233, 1, 7232, 1;
  110.  
  111. // Success rate: (x / y)% chance
  112. setarray .success[0], 1, 5, // 4/10 (40%)
  113. 1, 2, // 3/10 (30%)
  114. 4, 5, // 1/25 (4%)
  115. 1, 50; // 1/50 (2%)
  116.  
  117. // Equipment (constant/ID)
  118. setarray .equip[0], 5009, 2218, 7318;
  119.  
  120. // Tools (constant/ID, amount)
  121. setarray .tool[0], 7327, 1;
  122.  
  123. // Mining time (in seconds)
  124. .progress = 1;
  125.  
  126. // Audio/visual effects
  127. .sound$ = "chepet_attack.wav";
  128. .effect = EF_HIT5;
  129.  
  130. // Debris
  131. .debris = 7049; // Stone
  132. .limit = 3; // Scatter limit
  133.  
  134. // Hiding and Respawning
  135. .var_amount = 44; // Amount of Variant Minerals
  136. .hide_chance = 5; // Chance in x to hide (default: 4 [25%])
  137. .respawn_chance = 8; // Chance in x to respawn (default: 2 [50%])
  138. .respawn_rate = 1; // Every x hours (max: 12)
  139. end;
  140.  
  141. }
  142. function script npcmove {
  143. while(1) {
  144. set .@x,rand(0,300); // 0 to 300 random x coordinate
  145. set .@y,rand(0,300); // 0 to 300 random y coordinate
  146. if( checkcell("pvp_n_4-3", .@x, .@y, cell_chkpass)) break;
  147. }
  148. movenpc "Variant Mineral#"+getarg(0), .@x, .@y; //Move NPC
  149. setnpcdisplay "Variant Mineral#"+getarg(0), 1907; // set the npc sprite
  150. end;
  151. }
  152.  
  153. /*-----------------------------------------------------
  154. Duplicates
  155. -----------------------------------------------------*/
  156. pvp_n_4-3,100,92,0 duplicate(mining) Variant Mineral#1 1907
  157. pvp_n_4-3,100,95,0 duplicate(mining) Variant Mineral#2 1907
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement