· 6 years ago · Jul 10, 2019, 12:06 PM
1
2/* SQL Tables
3
4CREATE TABLE IF NOT EXISTS `promo_code` (
5 `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
6 `code` VARCHAR(50) CHARACTER SET LATIN1 COLLATE LATIN1_GENERAL_CS NOT NULL DEFAULT '',
7 `nameid` INT(11) NOT NULL DEFAULT '0',
8 `amount` INT(11) NOT NULL DEFAULT '0',
9 `count` INT(11) NOT NULL DEFAULT '0',
10 `left` INT(11) NOT NULL DEFAULT '0',
11 `gm_aid` INT(11) UNSIGNED NOT NULL DEFAULT '0',
12 `gm_cid` INT(11) UNSIGNED NOT NULL DEFAULT '0',
13 `time` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
14 PRIMARY KEY (`id`)
15) ENGINE=MyISAM;
16
17CREATE TABLE IF NOT EXISTS `promo_code_log` (
18 `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
19 `code` VARCHAR(50) CHARACTER SET LATIN1 COLLATE LATIN1_GENERAL_CS NOT NULL DEFAULT '',
20 `aid` INT(11) UNSIGNED NOT NULL DEFAULT '0',
21 `cid` INT(11) UNSIGNED NOT NULL DEFAULT '0',
22 `time` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
23 PRIMARY KEY (`id`)
24) ENGINE=MyISAM;
25
26*/
27
28
29
30//prontera,165,107,3 script Claim Reward#promo_code 862,{
31// doevent "promo_code_main::OnTalk";
32//}
33
34- script promo_code_main FAKE_NPC,{
35 function func_RandString;
36 function func_PromoCode;
37
38 OnInit:
39 .gm_level = 60;
40 setarray .promo_code_length,10,15;
41 .max_item_per_code = 10;
42 .query_limit = 50;
43 bindatcmd "promo",strnpcinfo(3)+"::OnAtcommand";
44 bindatcmd "addcode",strnpcinfo(3)+"::OnTalk";
45 end;
46
47 function func_RandString {
48 .@length = getarg( 0 );
49 .@type = getarg( 1,0 );
50
51 if ( .@type & 1 ) .@string_list$ = .@string_list$ + "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
52 if ( .@type & 2 ) .@string_list$ = .@string_list$ + "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
53 if ( .@type & 4 ) .@string_list$ = .@string_list$ + "0123456789";
54
55 if ( .@string_list$ != "" ) {
56 .@total_length = getstrlen( .@string_list$ );
57 while ( getstrlen( .@rand_string$ ) < .@length )
58 .@rand_string$ = .@rand_string$ + charat( .@string_list$,rand( .@total_length ) );
59 }
60
61 return .@rand_string$;
62 }
63
64 function func_PromoCode {
65 .@code$ = getarg( 0,"" );
66
67 query_sql( "SELECT `nameid`,`amount`,`left` FROM `promo_code` WHERE `code` LIKE '"+escape_sql( .@code$ )+"' LIMIT "+.query_limit,.@nameid,.@amount,.@left );
68 .@size = getarraysize( .@nameid );
69 if ( .@size <= 0 ) {
70 mes "Invalid Promo Codes";
71 }
72 else if ( .@left > 0 ) {
73 mes "-^FF0000 "+.@code$+"^000000";
74 mes " ";
75 for ( .@i = 0; .@i < .@size; .@i++ ) {
76 mes " > "+.@amount[.@i]+" x "+getitemname( .@nameid[.@i] );
77 }
78 next;
79 if ( select( "Claim","Cancel" ) == 1 ) {
80 .@aid = getcharid(3);
81 .@cid = getcharid(0);
82 query_sql( "SELECT `id`,`time` FROM `promo_code_log` WHERE `code` LIKE '"+.@code$+"' AND ( `aid` = "+.@aid+" OR `cid` = "+.@cid+" )",.@id,.@time$ );
83
84 if ( .@id ) {
85 mes "You claimed this Promo Code since "+.@time$;
86 }
87 else {
88 query_sql( "SELECT `left` FROM `promo_code` WHERE `code` LIKE '"+escape_sql( .@code$ )+"' LIMIT "+.query_limit,.@left );
89 if ( .@left > 0 ) {
90 query_sql( "UPDATE `promo_code` SET `left` = `left` - 1 WHERE `code` LIKE '"+escape_sql( .@code$ )+"'" );
91 for ( .@i = 0; .@i < .@size; .@i++ )
92 getitem .@nameid[.@i],.@amount[.@i];
93
94 .@sql$ = "INSERT INTO `promo_code_log` "
95 + "( `code`,`aid`,`cid`,`time` ) "
96 + "VALUES "
97 + "( '"+.@code$+"', "+.@aid+", "+.@cid+", NOW() )";
98 query_sql( .@sql$ );
99 }
100 else {
101 mes "Promo Code No longer available.";
102 }
103 }
104 }
105 }
106 else {
107 mes "Promo Code no longer available.";
108 }
109 close;
110 }
111
112 OnAtcommand:
113 if ( .@atcmd_parameters$ == "" ) {
114 dispbottom "Usage : "+.@atcmd_command$+" <promo code>";
115 }
116 else {
117 func_PromoCode( .@atcmd_parameters$ );
118 }
119 end;
120
121
122 OnTalk:
123 .@gm_level = getgmlevel();
124 .@not_gm = ( .@gm_level < .gm_level || !.gm_level || !.@gm_level );
125
126 mes "Pomo Code";
127 next;
128 switch ( select(
129 "Submit Promo Code",
130 ( .@not_gm )? "":"^FF0000[GM]^000000 List Promo Code",
131 ( .@not_gm )? "":"^FF0000[GM]^000000 Create Promo Code",
132 ( .@not_gm )? "":"^FF0000[GM]^000000 Delete Promo Code",
133 "Information"
134 )) {
135 case 1:
136 mes "Enter Promo Code";
137 input .@code$;
138 func_PromoCode( .@code$ );
139 break;
140 case 2:
141 query_sql( "SELECT `code`,`left`,`count` FROM `promo_code` WHERE `left` > 0 GROUP BY `code` ORDER BY `time` DESC LIMIT "+.query_limit,.@code$,.@left,.@count );
142 .@size = getarraysize( .@code$ );
143 if ( .@size ) {
144 mes "Promo Code List:";
145 for ( .@i = 0; .@i < .@size; .@i++ )
146 mes "-^FF0000 "+.@code$[.@i]+" ^777777("+.@left[.@i]+"/"+.@count[.@i]+" left)^000000";
147 }
148 else {
149 mes "Dont have any available codes.";
150 }
151 break;
152 case 3:
153 do {
154 mes "Code : "+.@promo_code$;
155 mes "Limit : "+.@promo_limit;
156 mes "Items :";
157 for ( .@i = 0; .@i < .@promo_item_size; .@i++ )
158 mes " > "+.@promo_amount[.@i]+" x "+getitemname( .@promo_itemid[.@i] );
159
160 .@option = select(
161 "Generate Promo Code",
162 "Set Limit",
163 "Set Items",
164 ( .@promo_limit && .@promo_item_size && .@promo_code$ != "" ) ? "Complete" : "",
165 "Cancel"
166 );
167
168 switch ( .@option ) {
169 case 1:
170 switch ( select(
171 "Randomly Generate",
172 "Manually Input",
173 "Back"
174 )) {
175 case 1:
176 .@promo_code$ = func_RandString( rand( .promo_code_length[0] ,.promo_code_length[1] ), 1|2|4 );
177 break;
178 case 2:
179 while ( input( .@promo_code$,4,50 ) );
180 default:
181 break;
182 }
183 break;
184 case 2:
185 mes "This code can use how many times ?";
186 input .@promo_limit,0,10000;
187 break;
188 case 3:
189 do {
190 next;
191 mes "Item List:";
192 for ( .@i = 0; .@i < .@promo_item_size; .@i++ )
193 mes " > "+.@promo_amount[.@i]+" x "+getitemname( .@promo_itemid[.@i] );
194
195 .@option = select(
196 ( .@promo_item_size < .max_item_per_code ) ? "Add Item" : "",
197 ( .@promo_item_size ) ? "Delete Item" : "",
198 "Back"
199 );
200
201 switch ( .@option ) {
202 case 1:
203 mes "Enter Item ID";
204 input .@itemid,0,42300;
205 .@temp_itemname$ = getitemname( .@itemid );
206 if ( .@temp_itemname$ != "null" ) {
207 .@item_type = getiteminfo( .@itemid,2 );
208 .@max_amount = ( .@item_type == IT_ARMOR || .@item_type == IT_WEAPON ) ? 100 : 30000;
209 mes "How many "+.@temp_itemname$;
210 input .@amount,0,.@max_amount;
211 if ( .@amount ) {
212 mes "Added "+.@amount+" x "+getitemname( .@itemid );
213 .@promo_itemid[.@promo_item_size] = .@itemid;
214 .@promo_amount[.@promo_item_size] = .@amount;
215 .@promo_item_size++;
216 }
217 }
218 break;
219 case 2:
220 .@temp_menu$ = "";
221 for ( .@i = 0; .@i < .@promo_item_size; .@i++ )
222 .@temp_menu$ = .@temp_menu$ + .@promo_amount[.@i] + " x " + getitemname( .@promo_itemid[.@i] ) + ":";
223 .@i = select( .@temp_menu$ + "Back" ) - 1;
224 if ( .@i < .@promo_item_size ) {
225 deletearray .@promo_itemid[.@i],1;
226 deletearray .@promo_amount[.@i],1;
227 .@promo_item_size--;
228 }
229 break;
230 default:
231 break;
232 }
233 } while ( .@option < 3 );
234 break;
235 case 4:
236 if ( .@option == 4 && .@promo_item_size && .@promo_code$ != "" ) {
237 .@gm_aid = getcharid(3);
238 .@gm_cid = getcharid(0);
239 for ( .@i = 0; .@i < .@promo_item_size; .@i++ ) {
240 .@sql$ = "INSERT INTO `promo_code` "
241 + "( `code`,`nameid`,`amount`,`count`,`left`,`gm_aid`,`gm_cid`,`time` ) "
242 + "VALUES "
243 + "( '"+.@promo_code$+"', "+.@promo_itemid[.@i]+", "+.@promo_amount[.@i]+", "+.@promo_limit+", "+.@promo_limit+", "+.@gm_aid+", "+.@gm_cid+", NOW() )";
244 query_sql( .@sql$ );
245 }
246 mes "Promo Code Added.";
247 }
248 break;
249 default:
250 break;
251 }
252 next;
253 } while ( .@option < 4 );
254 break;
255 case 4:
256 query_sql( "SELECT `code` FROM `promo_code` WHERE `left` > 0 GROUP BY `code` ORDER BY `time` DESC LIMIT "+.query_limit,.@code$ );
257 .@size = getarraysize( .@code$ );
258 if ( .@size ) {
259 for ( .@i = 0; .@i < .@size; .@i++ )
260 .@menu$ = .@menu$ + .@code$[.@i] + ":";
261
262 .@i = select( .@menu$ ) - 1;
263 if ( select( "Delete","Cancel" ) == 1 ) {
264 query_sql( "UPDATE `promo_code` SET `left` = 0 WHERE `code` LIKE '"+escape_sql( .@code$[.@i] )+"'" );
265 mes "Removed Promo Code.";
266 }
267 }
268 else {
269 mes "Dont have any available codes.";
270 }
271 break;
272 default:
273 mes "This is Promo Code NPC.";
274 mes "You give me a code, then I will give you certain items.";
275 break;
276 }
277 close;
278
279}