Advertisement
Innos

Promotional Codes 2.2

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