Advertisement
Innos

Promotional Codes 1.0.1

Jun 4th, 2013
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.20 KB | None | 0 0
  1. //===== Custom Script ========================================
  2. //= Promotional Codes
  3. //===== By: ==================================================
  4. //= Arzzzae
  5. //===== Current Version: =====================================
  6. //= 1.0
  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 - Small Edit by Innos
  16. //============================================================
  17.  
  18. /*
  19. DROP TABLE IF EXISTS `reward_codes`;
  20. CREATE TABLE IF NOT EXISTS `reward_codes` (
  21.   `code` VARCHAR(10) NOT NULL DEFAULT '',
  22.   `nameid` INT(11) UNSIGNED NOT NULL DEFAULT '0',
  23.   `item_name` VARCHAR(45) NOT NULL DEFAULT '',
  24.   `amount` SMALLINT(6) UNSIGNED NOT NULL DEFAULT '0',
  25.   `time_created` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
  26.   `redeem_time` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
  27.   `account_id` INT(11) UNSIGNED NOT NULL DEFAULT '0',
  28.   `confirmed` INT(11) UNSIGNED NOT NULL DEFAULT '0',
  29.   PRIMARY KEY (`code`)
  30. ) ENGINE=MYISAM;
  31. */
  32.  
  33. -   script  promoclaim  -1,{
  34.  
  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.                 else {
  56.                     getitem .@item,.@amt;
  57.                     dispbottom "Promotional code successfuly redeemed.";
  58. //-> INSERT INTO change to UPDATE / WHERE Code set confirmed to 1
  59.                     Query_SQL( "UPDATE `reward_codes` SET `redeem_time`=NOW(),`account_id`='"+getcharid(3)+"',`confirmed`='1' WHERE `code` = " + .@pc$ );
  60.                     end;
  61.                     }
  62.                
  63. OnEditCode:
  64.    
  65.     menu "Setup a new promotional code",ncode,"View existing codes",vcode,"Delete exisiting codes",dcode,"Cancel",cancel;
  66.    
  67.     ncode:
  68.        
  69.         set .@clength,4; //Promotional Code Length
  70.        
  71.        
  72.         input .@pcode$;
  73.             if (getstrlen(.@pcode$)!=.@clength) {
  74.                 dispbottom "Codes must be 4 characters long.";
  75.                 end;
  76.                 }
  77.             mes "You have entered ^FF0000"+.@pcode$+"^000000 as the code.";
  78.             mes "Are you sure?";
  79.             next;
  80.             if(select("Yes:No, thanks")==2) close;
  81.             query_sql ("SELECT COUNT(code) FROM `reward_codes` WHERE `code`='"+escape_sql(.@pcode$)+"'", .@pcode_exists);
  82.             if (.@pcode_exists) {
  83.                 dispbottom "Sorry, that code already exist.";
  84.                 end;
  85.             }
  86.             mes "Please set a reward for the players who has entered the code.";
  87.             input .@reward;
  88.             next;
  89.             if (.@reward == 0) {
  90.                 dispbottom "Sorry, that is an invalid item id.";
  91.                 close;
  92.             }
  93.             set .@iname$, getitemname(.@reward);
  94.             mes "Item number ^FF0000"+.@reward+"^000000";
  95.             mes "is equivalent to ^FF0000"+.@iname$+"^000000.";
  96.             mes "Are you sure?";
  97.             next;
  98.             if(select("Yes:No, thanks")==2) close;
  99.             mes "How many ^FF0000"+.@iname$+"^000000.?";
  100.             input .@amount;
  101.             next;
  102.             if (.@amount == 0) {
  103.                 dispbottom "Sorry, that is an invalid amount number.";
  104.                 close;
  105.             }
  106.            
  107.             mes "Are you sure?";
  108.             next;
  109.             if(select("Yes:No, thanks")==2) close;
  110. //-> both entry in 1 table         
  111.             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')");
  112.             dispbottom "Promotional Code ^FF0000"+.@pcode$+" ^000000is now activated and the reward is ^FF0000"+.@amount+" "+.@iname$+".";
  113.             close;
  114.    
  115.     vcode:
  116. //-> show confirmed yes/no
  117.         set .@nb, query_sql("SELECT code, item_name, amount, confirmed FROM `reward_codes` ORDER BY time_created DESC LIMIT 20", .@code$, .@nid$, .@amount, .@conf);   
  118.        
  119.             if (.@nb == 0) {
  120.             dispbottom "No exisiting codes.";
  121.             end;
  122.             }
  123.             dispbottom "=============================================";
  124.             dispbottom "==============  EXISITING CODES  ==============";
  125.             dispbottom "=============================================";
  126.             for(set .@i,0; .@i < .@nb; set .@i,.@i+1)
  127.             dispbottom ""+.@code$[.@i]+" (  Reward: "+.@amount[.@i]+" "+.@nid$[.@i]+" ) Used: "+.@conf[.@i]+" ";
  128.             dispbottom "=============================================";
  129.             end;
  130.            
  131.     dcode:
  132.         input .@dcode$;
  133.             query_sql ("SELECT COUNT(code) FROM `reward_codes` WHERE `code`='"+escape_sql(.@dcode$)+"'", .@pcode_exists);
  134.             if (.@pcode_exists) {
  135.                 mes "Would you like to delete that code?";
  136.                 next;
  137.                 if(select("Yes:No, thanks")==2) close;
  138.                
  139.                 query_sql ("DELETE FROM `reward_codes` WHERE `code`='"+escape_sql(.@dcode$)+"'");
  140.                 dispbottom "Promotional code successfuly deleted.";
  141.                 close;
  142.             }
  143.             dispbottom "Promotional code not found.";
  144.             end;
  145.    
  146.     cancel:
  147.         close;
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement