Advertisement
Innos

Promotional Codes 1.0.2

Jun 4th, 2013
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.27 KB | None | 0 0
  1. //===== Custom Script ===========================================================
  2. //= Promotional Codes
  3. //===== By: =====================================================================
  4. //= Arzzzae
  5. //===== Current Version: ========================================================
  6. //= 1.0.2
  7. //===== Compatible With: ========================================================
  8. //= Latest svn
  9. //===== Description: ============================================================
  10. //= Adds 2 custom atcommands. @claim for players to claim
  11. //= promotional code created by Game Masters. @code is for
  12. //= administrators to add/view/delete promotional codes.
  13. //===== Additional Comments: ====================================================
  14. //= 1.0 - Initial Release.
  15. //= 1.0.1 - Only 1 SQL Table with confirmed and close Code
  16. //= 1.0.2 - Code can be used only from one Player or every Account on time.
  17. //===============================================================================
  18.  
  19. /*
  20. DROP TABLE IF EXISTS `reward_codes`;
  21. CREATE TABLE IF NOT EXISTS `reward_codes` (
  22.   `code` VARCHAR(10) NOT NULL DEFAULT '',
  23.   `nameid` INT(11) UNSIGNED NOT NULL DEFAULT '0',
  24.   `item_name` VARCHAR(45) NOT NULL DEFAULT '',
  25.   `amount` SMALLINT(6) UNSIGNED NOT NULL DEFAULT '0',
  26.   `time_created` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
  27.   `redeem_time` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
  28.   `account_id` INT(11) UNSIGNED NOT NULL DEFAULT '0',
  29.   `confirmed` INT(11) UNSIGNED NOT NULL DEFAULT '0',
  30.   PRIMARY KEY (`code`)
  31. ) ENGINE=MYISAM;
  32. */
  33.  
  34. -   script  promoclaim  -1,{
  35.  
  36. OnInit:
  37.     bindatcmd "claim",strnpcinfo(3)+"::OnClaim";
  38.     bindatcmd "code",strnpcinfo(3)+"::OnEditCode",99,0;
  39.     end;
  40.    
  41. OnClaim:
  42.     mes "^FF0000 Enter a new promotional code.";
  43.     input .@pc$;
  44.     close2;
  45.  
  46.                 if ( query_sql("SELECT nameid,amount FROM `reward_codes` WHERE `code`='"+escape_sql(.@pc$)+"'", .@item,.@amt) == 0) {
  47.                     dispbottom "Invalid promotional code.";
  48.                     end;
  49.                     }
  50. //-> Check if code confirmed to 1                  
  51.                 else if (query_sql("SELECT code,confirmed FROM `reward_codes` WHERE `code`='"+escape_sql(.@pc$)+"' AND `confirmed`='1'")) {
  52.                     dispbottom "This promotional code already claimed.";
  53.                     end;
  54.                     }
  55. //-> v1.0.2 Code can use more than 1
  56.                 else if (#pcode$ == .@pc$) {dispbottom "You have used this Code already."; end;}
  57.                 else if (query_sql("SELECT code,confirmed FROM `reward_codes` WHERE `code`='"+escape_sql(.@pc$)+"' AND `confirmed` >= '2'")) {
  58.                     getitem .@item,.@amt;
  59.                     dispbottom "Promotional code successfuly redeemed.";
  60.                     query_sql("update `reward_codes` SET `confirmed` = `confirmed` + 1 WHERE `code` = " + .@pc$);
  61.                     set #pcode$,.@pc$;
  62.                     end;
  63.                     }
  64. //-----------------------------------
  65.                 else {
  66.                     getitem .@item,.@amt;
  67.                     dispbottom "Promotional code successfuly redeemed.";
  68. //-> INSERT INTO change to UPDATE / WHERE Code set confirmed to 1
  69.                     Query_SQL( "UPDATE `reward_codes` SET `redeem_time`=NOW(),`account_id`='"+getcharid(3)+"',`confirmed`='1' WHERE `code` = " + .@pc$ );
  70.                     end;
  71.                     }
  72.                
  73. OnEditCode:
  74.    
  75.     menu "Setup a new promotional code",ncode,"View existing codes",vcode,"Delete exisiting codes",dcode,"Cancel",cancel;
  76.    
  77.     ncode:
  78.        
  79.         set .@clength,4; //Promotional Code Length
  80.        
  81.        
  82.         input .@pcode$;
  83.             if (getstrlen(.@pcode$)!=.@clength) {
  84.                 dispbottom "Codes must be 4 characters long.";
  85.                 end;
  86.                 }
  87.             mes "You have entered ^FF0000"+.@pcode$+"^000000 as the code.";
  88.             mes "Are you sure?";
  89.             next;
  90.             if(select("Yes:No, thanks")==2) close;
  91.             query_sql ("SELECT COUNT(code) FROM `reward_codes` WHERE `code`='"+escape_sql(.@pcode$)+"'", .@pcode_exists);
  92.             if (.@pcode_exists) {
  93.                 dispbottom "Sorry, that code already exist.";
  94.                 end;
  95.             }
  96.             mes "Please set a reward for the players who has entered the code.";
  97.             input .@reward;
  98.             next;
  99.             if (.@reward == 0) {
  100.                 dispbottom "Sorry, that is an invalid item id.";
  101.                 close;
  102.             }
  103.             set .@iname$, getitemname(.@reward);
  104.             mes "Item number ^FF0000"+.@reward+"^000000";
  105.             mes "is equivalent to ^FF0000"+.@iname$+"^000000.";
  106.             mes "Are you sure?";
  107.             next;
  108.             if(select("Yes:No, thanks")==2) close;
  109.             mes "How many ^FF0000"+.@iname$+"^000000.?";
  110.             input .@amount;
  111.             next;
  112.             if (.@amount == 0) {
  113.                 dispbottom "Sorry, that is an invalid amount number.";
  114.                 close;
  115.             }
  116.            
  117.             mes "Are you sure?";
  118.             next;
  119.             if(select("Yes:No, thanks")==2) close;
  120. //-> both entry in 1 table         
  121.             query_sql ("INSERT INTO `reward_codes` (code,nameid,item_name,amount,time_created,redeem_time,account_id,confirmed) VALUES ('"+.@pcode$+"', "+.@reward+", '"+.@iname$+"', "+.@amount+", NOW(), '0000-00-00 00:00:00', '0', '0')");
  122.  
  123. //-> v1.0.2 - Code can use more than 1 (set confirmed 2)
  124.             mes "Code for more than 1 use?";
  125.             if(select("Yes:No")==2) close;
  126.             Query_SQL( "UPDATE `reward_codes` SET `confirmed`='2' WHERE `code` = " + .@pcode$ );
  127. //-------------------------------------    
  128.             dispbottom "Promotional Code ^FF0000"+.@pcode$+" ^000000is now activated and the reward is ^FF0000"+.@amount+" "+.@iname$+".";
  129.             close;
  130.    
  131.     vcode:
  132. //-> show confirmed yes/no
  133.         set .@nb, query_sql("SELECT code, item_name, amount, confirmed FROM `reward_codes` ORDER BY time_created DESC LIMIT 20", .@code$, .@nid$, .@amount, .@conf);   
  134.  
  135.             if (.@nb == 0) {
  136.             dispbottom "No exisiting codes.";
  137.             end;
  138.             }
  139.             dispbottom "=============================================";
  140.             dispbottom "==============  EXISITING CODES  ==============";
  141.             dispbottom " 0: Open     1:Closed     2+: Free for all    ";
  142.             dispbottom "=============================================";
  143.             for(set .@i,0; .@i < .@nb; set .@i,.@i+1)
  144.             dispbottom ""+.@code$[.@i]+" (  Reward: "+.@amount[.@i]+" "+.@nid$[.@i]+" ) Used: "+.@conf[.@i]+" ";
  145.             dispbottom "=============================================";
  146.             end;
  147.            
  148.     dcode:
  149.         input .@dcode$;
  150.             query_sql ("SELECT COUNT(code) FROM `reward_codes` WHERE `code`='"+escape_sql(.@dcode$)+"'", .@pcode_exists);
  151.             if (.@pcode_exists) {
  152.                 mes "Would you like to delete that code?";
  153.                 next;
  154.                 if(select("Yes:No, thanks")==2) close;
  155.                
  156.                 query_sql ("DELETE FROM `reward_codes` WHERE `code`='"+escape_sql(.@dcode$)+"'");
  157.                 dispbottom "Promotional code successfuly deleted.";
  158.                 close;
  159.             }
  160.             dispbottom "Promotional code not found.";
  161.             end;
  162.    
  163.     cancel:
  164.         close;
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement