Advertisement
Guest User

Untitled

a guest
Jul 24th, 2015
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.01 KB | None | 0 0
  1. // Class names are always upper-case as in C / C++
  2. Class 1 L2F_Delevel : L2FBaseNPC
  3. {
  4. parameter:
  5.     // Parameters are always prefixed by what I'll be
  6.     // using them for or what they hold.
  7.  
  8.     // HTML names are written: ServerName.NPCName.TitleOfPageOrFunction
  9.     string htmlHello            = "L2F.Delevel.Hello.htm";
  10.     string htmlChooseLevel      = "L2F.Delevel.ChooseLvel.htm";
  11.     string htmlConfirmDelevel   = "L2F.Delevel.Confirm.htm";
  12.  
  13.     // Ask's are listed at 1k increments.
  14.     // Sub-Asks remain within the same 1K range but
  15.     // incremented by 100.
  16.     int askChooseLevel      = 1000;
  17.     int askConfirmLevel     = 1100;
  18.  
  19.     // Cookies
  20.     string cookieDesiredLevel = "L2F.Delevel.DesiredLevel";
  21.  
  22.     // errors
  23.     string errMsgInvalidCurrentLevel = "Your current level must be greater than the one selected.";
  24.     string errMsgInvalidConformation = "You did not correctly confirm your delevel request.";
  25.  
  26. handler:
  27.  
  28. EventHandler TALKED(talker)
  29. {
  30.     myself.ShowPage(talker, htmlHello);
  31. }
  32.  
  33. EventHandler MENU_SELECTED(talker, ask, reply, fhtml0, i0)
  34. {
  35.     // We use the AdvExt compiler which does not support using switch
  36.     // statements with class constants. Have to use a bunch of if's here.
  37.     // I don't think it's much slower as long as you return correctly.
  38.  
  39.     if (ask == askChooseLevel)
  40.     {
  41.         // Reply = The level they'd like to be set to
  42.         // selected in HTML via dropdown or input box.
  43.  
  44.         // Player should not be able to select
  45.         // a level greater or equal to their own.
  46.         if (talker.level < reply)
  47.         {
  48.             myself.FHTML_SetFileName(fhtml0, htmlGlobalErrorPage); // Defined in L2FBaseNPC superclass.
  49.             myself.FHTML_SetStr(fhtml0, "ERROR_TITLE", "L2F > Invalid Level Selected");
  50.             myself.FHTML_SetStr(fhtml0, "ERROR_MSG", errMsgInvalidCurrentLevel);
  51.             myself.FHTML_SetStr(fhtml0, "ERROR_REDIRECT_PAGE", htmlHello); // Location where the "OK" button sends you.
  52.         myself.ShowFHTML(talker, fhtml0);            
  53.         return;
  54.         }
  55.  
  56.         myself.SetCookie(talker, cookieDesiredLevel, reply);
  57.         myself.ShowPage(talker, htmlConfirmDelevel);
  58.         return;
  59.     }
  60.  
  61.     if (ask == askConfirmLevel)
  62.     {
  63.         // Reply = The result of whatever you asked
  64.         // them to input in the HTML to confirm they really
  65.         // want to be deleveled.
  66.  
  67.         // Ensure the verification checks out.
  68.         if (reply != YOUR_VERIFICATION_OPTION)
  69.         {
  70.             myself.FHTML_SetFileName(fhtml0, htmlGlobalErrorPage); // Defined in L2FBaseNPC superclass.
  71.             myself.FHTML_SetStr(fhtml0, "ERROR_TITLE", "L2F > DeLevel Verification Failed");
  72.             myself.FHTML_SetStr(fhtml0, "ERROR_MSG", errMsgINvalidConformation);
  73.             myself.FHTML_SetStr(fhtml0, "ERROR_REDIRECT_PAGE", htmlHello);
  74.         myself.ShowFHTML(talker, fhtml0);            
  75.         return;
  76.         }
  77.  
  78.         // Everything went well, Set their level using the cookie we set earlier.
  79.         return;
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement