EyesOfAHawk

Wheel of Fortune

Jun 13th, 2018
960
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 7.66 KB | None | 0 0
  1. //===== Hercules Script ======================================
  2. //= Wheel of Fortune
  3. //===== By ===================================================
  4. //= Habilis
  5. //= Edited by Myriad
  6. //===== Version ==============================================
  7. //= 1.02 - June 26, 2018
  8. // - Fixed @wheel_of_fortune end command.
  9. //= 1.01 - June 14, 2018
  10. // - Added @wheel_of_fortune GM command (level 98+).
  11. // - Merged S_Pay and S_Loop subs into main line of text.
  12. // - S_Gamble is now S_Spin and it will 'return' instead of
  13. //  calling back to the initial sub.
  14. //= 1.00 - June 13, 2018
  15. // - Initial script edit for Habilis.
  16. //===== Description ==========================================
  17. //= Wheel of fortune something.
  18. //============================================================
  19.  
  20. -   script  Wheel_of_Fortune    FAKE_NPC ,{
  21.  
  22. OnInit:
  23.     disablenpc("Wheel of Fortune#Main");
  24.     disablenpc("Hussein#WOF");
  25.     .EventName$ = "[Wheel Of Fortune]";
  26.     end;
  27.  
  28. OnMinute39:
  29. OnStart:
  30.     .Start = true;
  31.     query_sql("DELETE FROM `acc_reg_num_db` WHERE `key`='#freewheelfortunespin';");
  32.     announce(sprintf("%s : The event will begin in 1 minute, near the center of Prontera.", .EventName$), bc_blue | bc_all);
  33.     initnpctimer();
  34.     end;
  35.  
  36. OnTimer60000: // 1 min
  37.     enablenpc("Wheel of Fortune#Main");
  38.     enablenpc("Hussein#WOF");
  39.     announce(sprintf("%s : Come to Prontera and test your luck, everyone got some free spins!", .EventName$), bc_blue | bc_all);
  40.     end;
  41.  
  42. OnTimer1800000: // 30 mins
  43.     announce(sprintf("%s : One more minute, do your last spin!", .EventName$), bc_blue | bc_all);
  44.     end;
  45.  
  46. OnTimer1860000: // 31 mins
  47. OnStop:
  48.     .Start = false;
  49.     stopnpctimer();
  50.     disablenpc("Wheel of Fortune#Main");
  51.     disablenpc("Hussein#WOF");
  52.     end;
  53.  
  54. OnCommand:
  55.     if (.@atcmd_numparameters != 1) {
  56.         dispbottom(sprintf("Usage: %s <start/end>", .@atcmd_command$), 0x00FF00);
  57.         dispbottom(sprintf("%s failed.", .@atcmd_command$), 0x00FF00);
  58.         end;
  59.     }
  60.  
  61.     if (.@atcmd_parameters$[0] == "start") {
  62.         if (!.Start)
  63.             donpcevent(sprintf("%s::OnStart", strnpcinfo(NPC_NAME)));
  64.         else {
  65.             dispbottom("The Wheel of Fortune has already started.", 0x00FF00);
  66.             dispbottom(sprintf("%s failed.", .@atcmd_command$), 0x00FF00);
  67.         }
  68.     } else if (.@atcmd_parameters$[0] == "end") {
  69.         if (.Start)
  70.             donpcevent(sprintf("%s::OnStop", strnpcinfo(NPC_NAME)));
  71.         else {
  72.             dispbottom("The Wheel of Fortune is not active.", 0x00FF00);
  73.             dispbottom(sprintf("%s failed.", .@atcmd_command$), 0x00FF00);
  74.         }
  75.     } else {
  76.         dispbottom(sprintf("Usage: %s <start/end>", .@atcmd_command$), 0x00FF00);
  77.         dispbottom(sprintf("%s failed.", .@atcmd_command$), 0x00FF00);
  78.     }
  79.     end;
  80. }
  81.  
  82. prontera,155,176,3  script  Wheel of Fortune#Main   2_SLOT_MACHINE,{
  83.    
  84. OnTalk:
  85.     if (#freewheelfortunespin == 0)
  86.         #freewheelfortunespin = .Free_Spins;
  87.  
  88.     if (getd(.Event_Points_Variable$) < .Points_Cost && #freewheelfortunespin < 0) {
  89.         mesf("[^0055FF%s^000000]", .EventName$);
  90.         mes("You are out of Event");
  91.         mes("Points and have no more");
  92.         mes("free spins. Come back");
  93.         mes("next time for more!");
  94.         close();
  95.     }
  96.  
  97.     .@mes$ = (#freewheelfortunespin > 0) ? sprintf(", but you, my friend, have %d free spin%s!", #freewheelfortunespin, (#freewheelfortunespin == 1) ? "" : "s") : ".";
  98.     cutin("aca_salim02", 2);
  99.     addtimer(1, sprintf("%s::OnEnd", strnpcinfo(NPC_NAME)));
  100.     mesf("[^0055FF%s^000000]", .EventName$);
  101.     mes("Do you want to spin the wheel?");
  102.     mesf("It costs ^FF0000%d Event points^000000 to play%s", .Points_Cost, .@mes$);
  103.     next();
  104.  
  105.     while (true) {
  106.         .@val = getd(.Event_Points_Variable$);
  107.         if (.@val < .Points_Cost && #freewheelfortunespin < 0)
  108.             callsub(S_End);
  109.         switch (select(
  110.             (#freewheelfortunespin > 0) ? sprintf("Yes! Use free spin! (%d left)", #freewheelfortunespin) : "",
  111.             (.@val > 0) ? sprintf("Yes! Use Event Points. (%d remaining)", .@val) : "",
  112.             "No (Leave)"
  113.         )) {
  114.         // pay with free spin
  115.         case 1:
  116.             if (#freewheelfortunespin > 0) {
  117.                 if ((#freewheelfortunespin -= 1) < 1)
  118.                     #freewheelfortunespin = -1;
  119.                 callsub(S_Spin);
  120.             } else
  121.                 callsub(S_End);
  122.             break;
  123.  
  124.         // Pay with points 
  125.         case 2:
  126.             if ((.@val = getd(.Event_Points_Variable$)) >= .Points_Cost) {
  127.                 setd(.Event_Points_Variable$, (.@val -= .Points_Cost));
  128.                 dispbottom(sprintf("%s : You now have %d event points.", .ServerName$, .@val));
  129.                 callsub(S_Spin);
  130.             } else {
  131.                 cutin("aca_salim02", 2);
  132.                 mesf("[^0055FF%s^000000]", .EventName$);
  133.                 mes("Awww, you don't have enough to gamble...");
  134.                 mes(" ");
  135.                 mes("Have you ever heard?");
  136.                 mes("'Money isn't all that matters' Got it?");
  137.                 mes("Byeeeeeeeeeeeeee ;)");
  138.                 callsub(S_End);
  139.             }
  140.             break;
  141.  
  142.         default:
  143.             callsub(S_End);
  144.         }
  145.     }
  146.  
  147. // Wheel spin animation
  148. S_Spin:
  149.     .@Sector = rand(.Sector_Range[0], .Sector_Range[1]);
  150.     .@Display = .@Sector * 2 - 1;
  151.     .@Speed = .Spin_Speed;
  152.    
  153.     for (.@i = 0; .@i < .nbTurns; .@i++) {
  154.         .@b = .Cutin_Range[0];
  155.         while (.@b <= .Cutin_Range[1]) {
  156.             cutin(sprintf("%s%d", .Cutin$, .@b), 4);
  157.             sleep2(.@Speed);
  158.             .@b++;
  159.             .@Speed++;
  160.         }
  161.     }
  162.    
  163.     .@b = .Cutin_Range[0];
  164.     while (.@b < .@Display) {
  165.         cutin(sprintf("%s%d", .Cutin$, .@b), 4);
  166.         sleep2(.@Speed);
  167.         .@b++;
  168.     }
  169.  
  170.     cutin(sprintf("%s%d", .Cutin$, .@b), 4);
  171.  
  172.     if (.Prize_ID[.@Sector] == -1) {
  173.         // Free spin
  174.         if (.Sound_Effects)
  175.             soundeffect("wheel_jackpot.wav", 0);
  176.         announce(sprintf("[%s] : Wow, %dx more Free spins!!!", .EventName$, .Prize_Qty[.@Sector]), bc_blue | bc_self);
  177.         #freewheelfortunespin = #freewheelfortunespin == -1 ? .Prize_Qty[.@Sector] : #freewheelfortunespin + .Prize_Qty[.@Sector];
  178.     } else if (.Prize_ID[.@Sector] == 0) {
  179.         // nothing
  180.         if (.Sound_Effects)
  181.             soundeffect("wheel_lost.wav", 0);
  182.         announce(sprintf("[%s] : Awwww, no luck in your gamble, more luck in love...", .EventName$), bc_blue | bc_self);
  183.     } else {
  184.         // item
  185.         if (.Sound_Effects)
  186.             soundeffect("wheel_won.wav", 0);
  187.         announce(sprintf("[%s] : %dx %s - enjoy your prize!", .EventName$, .Prize_Qty[.@Sector], getitemname(.Prize_ID[.@Sector])), bc_blue | bc_self);
  188.         getitem(.Prize_ID[.@Sector], .Prize_Qty[.@Sector]);
  189.     }
  190.  
  191.     sleep2(1000);
  192.     if (getd(.Event_Points_Variable$) < .Points_Cost && #freewheelfortunespin < 0) {
  193.         mesf("[^0055FF%s^000000]", .EventName$);
  194.         mes("You are out of Event");
  195.         mes("Points and have no more");
  196.         mes("free spins. Come back");
  197.         mes("next time for more!");
  198.         close();
  199.     }
  200.     return;
  201.    
  202. S_End:
  203.     close2();
  204. OnEnd:
  205.     cutin("", 255);
  206.     end;
  207.    
  208. OnInit:
  209.     .ServerName$ = "[Your boring server]";
  210.     .EventName$ = "Wheel Of Fortune";
  211.     bindatcmd("wheel_of_fortune", "Wheel_of_Fortune::OnCommand", 98, 98, false);
  212.     .Event_Points_Variable$ = "#LROEVENTPOINTS"; // The name of your event points variable
  213.     .Spin_Speed = 50; // What is the base spin speed? (ms)
  214.     .nbTurns = 2; // Idk what this is?
  215.     .Points_Cost = 100; // How many 'points' does it cost for a spin?
  216.     .Free_Spins = 1; // How many free spins does a player get?
  217.     .Sound_Effects = true; // Enable sound effects? (true/false)
  218.  
  219.     // You must have a total of 10 prizes. DO NOT remove 0 or -1 from the array and do not
  220.     // change their order.
  221.     setarray(.Prize_ID[1], -1, 31024, 31026, 31008, 31020, 31017, 31010, 31016, 0, 31009);
  222.     setarray(.Prize_Qty[1], 2,     1,     1,     1,     3,     3,     1,     3, 0,     3);
  223.  
  224.     // Don't touch below
  225.     .Cutin$ = "WheelOfFortune_";
  226.     setarray(.Sector_Range, 1, 10); // Sector range
  227.     setarray(.Cutin_Range, 0, 19); // Cutin range
  228.     end;
  229. }
  230.  
  231. prontera,159,178,3  script  Hussein#WOF 1_M_MERCHANT,{
  232.     .@name$ = "[Hussein]";
  233.     cutin("aca_salim02", 2);
  234.     mes(.@name$);
  235.     mes("I command you to spin");
  236.     mes("the Wheel of Fortune!");
  237.     next();
  238.     getmapxy(.@map$, .@x, .@y, UNITTYPE_NPC, "Wheel of Fortune#Main");
  239.     warp(.@map$, .@x - 1, .@y - 2, 0);
  240.     doevent("Wheel of Fortune#Main::OnTalk");
  241.     end;
  242. }
Add Comment
Please, Sign In to add comment