· 6 years ago · May 19, 2019, 05:56 AM
1/*
2________________ ______ ________
3___ |_____ /________ /______ ___ __ \_____
4__ /| | __ /_ __ \_ __ \ _ \ __ /_/ / __ \
5_ ___ / /_/ / / /_/ / /_/ / __/ _ _, _// /_/ /
6/_/ |_\__,_/ \____//_.___/\___/ /_/ |_| \____/
7
8*/
9
10/*
11
12CREATE TABLE IF NOT EXISTS `ero_gm_reward` (
13 `id` int(11) NOT NULL AUTO_INCREMENT,
14 `gm_aid` int(11) NOT NULL default '0',
15 `gm_name` varchar(30) NOT NULL default '',
16 `nameid` int(11) NOT NULL default '0',
17 `amount` int(11) unsigned NOT NULL default '0',
18 `refine` tinyint(3) unsigned NOT NULL default '0',
19 `card1` smallint(4) unsigned NOT NULL default '0',
20 `card2` smallint(4) unsigned NOT NULL default '0',
21 `card3` smallint(4) unsigned NOT NULL default '0',
22 `card4` smallint(4) unsigned NOT NULL default '0',
23 `format_name` varchar(30) NOT NULL default 'null',
24 `reward_time` datetime NOT NULL default '0000-00-00 00:00:00',
25 `status` tinyint(1) NOT NULL default '0',
26 `claim_aid` int(11) NOT NULL default '0',
27 `claim_name` varchar(30) NOT NULL DEFAULT '',
28 `claim_time` datetime NOT NULL default '0000-00-00 00:00:00',
29 `note` varchar(255) NOT NULL default 'none',
30 PRIMARY KEY (`id`)
31) ENGINE=MyISAM;
32
33*/
34
35
36sec_in02.gat,161,161,2 script GM Rewarder#gmreward 4_F_KAFRA9,{
37 doevent "gm_reward_main::OnTalk";
38}
39
40
41- shop gm_reward_shop -1,909:-1
42
43- script gm_reward_main -1,{
44 function func_sql_reward;
45 function func_item_name;
46 function func_list_char;
47 function func_display_card;
48 function func_list_reward;
49 function func_view_reward;
50
51 OnInit:
52 .gm_level = 60;
53 .shop_name$ = "gm_reward_shop";
54 end;
55
56 OnTalk:
57 .@gm_level = getgmlevel();
58 .@not_gm = ( .@gm_level < .gm_level || !.gm_level || !.@gm_level );
59
60 cutin "kafra_09",2;
61 mes "^FF0000[ GM Reward - Introduction ]^000000";
62 mes "Hi "+strcharinfo(0)+", what can I do for you today?";
63 next;
64 switch ( select(
65 ( .@not_gm )? "Check Pending Reward":"",
66 ( .@not_gm )? "Check Reward History":"",
67 ( .@not_gm )? "":"^FF0000[GM]^000000 Send Reward",
68 ( .@not_gm )? "":"^FF0000[GM]^000000 Delete Reward",
69 ( .@not_gm )? "":"^FF0000[GM]^000000 Check History",
70 "Information"
71 )) {
72 case 1:
73 mes "^FF0000[ GM Reward - Pending Reward ]^000000";
74 mes "I will show you a list of rewards that are still not yet claimed.";
75 func_list_reward( "`claim_name` = '"+escape_sql( strcharinfo(0) )+"' AND `status` = 0" );
76 break;
77 case 2:
78 mes "^FF0000[ GM Reward - History ]^000000";
79 mes "I will show you a list of rewards that are claimed previously.";
80 func_list_reward( "`claim_name` = '"+escape_sql( strcharinfo(0) )+"' AND `status` = 1" );
81 break;
82 case 3:
83 mes "^FF0000[ GM Reward - Setup ]^000000";
84 mes "Please place all the items that you want to sent to player into the selling shop window.";
85 // close2;
86 callshop .shop_name$,2;
87 npcshopattach .shop_name$;
88 end;
89 case 4:
90 mes "^FF0000[ GM Reward - Remove Rewards ]^000000";
91 mes "I will show you a list of rewards that are sent out but not yet claimed.";
92 func_list_reward( "`status` = 0" );
93 break;
94 case 5:
95 mes "^FF0000[ GM Reward - Reward History ]^000000";
96 mes "I will show you a list of recent rewards based on the status you selected.";
97 .@i = select( "Pending Reward","Claimed Reward","Deleted Reward" ) - 1;
98 func_list_reward( "`status` = "+.@i );
99 break;
100 default:
101 mes "^FF0000[ GM Reward - Information ]^000000";
102 mes "Hi, I work for Game Master. I assist GM to distribute or manage the rewards setup by GM.";
103 break;
104 }
105 close2;
106 cutin "",255;
107 end;
108
109 OnSellItem:
110 cutin "kafra_09",2;
111 mes "^FF0000[ GM Reward - Checklist ]^000000";
112 if ( getgmlevel() < .gm_level ) {
113 mes "You're not authorized to perform this actions.";
114 }
115 else {
116 .@reward_size = getarraysize( @sold_nameid );
117 if ( .@reward_size < 1 ) {
118 mes "Failed, no items found in the list.";
119 }
120 else {
121 mes "Enter Player name:";
122 mes "^777777------------------------------^000000";
123 for ( .@i = 0; .@i < .@reward_size; .@i++ ) {
124 mes "^6495ED# ^000000"+func_item_name( @sold_nameid[.@i],@sold_quantity[.@i],@sold_refine[.@i] );
125 .@item_type = getiteminfo( @sold_nameid[.@i],2 );
126 if ( .@item_type == IT_ARMOR || .@item_type == IT_WEAPON )
127 func_display_card( @sold_card1[.@i],@sold_card2[.@i],@sold_card3[.@i],@sold_card4[.@i] );
128 }
129 .@player_name$ = func_list_char();
130 if ( .@player_name$ != "" ) {
131 next;
132 mes "^FF0000[ GM Reward - Confirmation ]^000000";
133 mes "Player: ^FF0000"+.@player_name$+"^000000";
134 mes "^777777------------------------------^000000";
135 for ( .@i = 0; .@i < .@reward_size; .@i++ ) {
136 mes "^6495ED > ^000000"+func_item_name( @sold_nameid[.@i],@sold_quantity[.@i],@sold_refine[.@i] );
137 .@item_type = getiteminfo( @sold_nameid[.@i],2 );
138 if ( .@item_type == IT_ARMOR || .@item_type == IT_WEAPON )
139 func_display_card( @sold_card1[.@i],@sold_card2[.@i],@sold_card3[.@i],@sold_card4[.@i] );
140 }
141 if ( select( "Confirm","Cancel" ) == 1 ) {
142 next;
143 mes "^FF0000[ GM Reward - Confirmation ]^000000";
144 mes "Enter a Title:";
145 do {
146 .@length = input( .@note$,4,70 );
147 .@check = ( compare( .@note$,":" ) || .@length );
148 if ( .@check ) {
149 mes "^777777Invalid title^000000";
150 }
151 }while ( .@check );
152
153 .@gm_aid = getcharid(3);
154 .@gm_name$ = strcharinfo(0);
155
156 query_sql( "SELECT `account_id`,`char_id`,`online` FROM `char` WHERE `name` = '"+escape_sql( .@player_name$ )+"' LIMIT 1",.@player_aid,.@player_cid,.@online );
157
158 for ( .@i = 0; .@i < .@reward_size; .@i++ ) {
159 .@formatted_name$ = func_item_name( @sold_nameid[.@i],@sold_quantity[.@i],@sold_refine[.@i] );
160 if ( func_sql_reward( .@gm_aid,escape_sql( .@gm_name$ ),@sold_nameid[.@i],@sold_quantity[.@i],@sold_refine[.@i],escape_sql( .@formatted_name$ ),@sold_card1[.@i],@sold_card2[.@i],@sold_card3[.@i],@sold_card4[.@i],.@player_aid,.@player_name$,.@note$ ) )
161 dispbottom "[Reward Sent] "+.@player_name$+" - "+.@formatted_name$;
162 else
163 dispbottom "[Reward Sent Failure] "+.@player_name$+" - "+.@formatted_name$;
164 }
165
166 if ( .@player_aid > 0 && isloggedin( .@player_aid,.@player_cid ) ) {
167 message .@player_name$,"You received "+.@reward_size+" reward(s) from "+.@gm_name$;
168 message .@gm_name$,"You sent "+.@reward_size+" reward(s) to "+.@player_name$;
169 }
170 mes "Rewards sent.";
171 }
172 }
173 }
174 }
175 close2;
176 cutin "",255;
177 end;
178
179 function func_sql_reward {
180
181 if ( getargcount() >= 12 ) {
182 .@gm_aid = getarg(0);
183 .@gm_name$ = getarg(1);
184 .@sold_nameid = getarg(2);
185 .@sold_quantity = getarg(3);
186 .@sold_refine = getarg(4);
187 .@formatted_name$ = getarg(5);
188 .@sold_card1 = getarg(6);
189 .@sold_card2 = getarg(7);
190 .@sold_card3 = getarg(8);
191 .@sold_card4 = getarg(9);
192 .@player_aid = getarg(10);
193 .@player_name$ = getarg(11);
194 .@note$ = getarg(12);
195
196 query_sql( "INSERT INTO `ero_gm_reward` ( `gm_aid`,`gm_name`,`nameid`,`amount`,`refine`,`format_name`,`card1`,`card2`,`card3`,`card4`,`reward_time`,`claim_aid`,`claim_name`,`note` ) VALUES ( "+.@gm_aid+",'"+escape_sql( .@gm_name$ )+"',"+.@sold_nameid+","+.@sold_quantity+","+.@sold_refine+",'"+escape_sql( .@formatted_name$ )+"',"+.@sold_card1+","+.@sold_card2+","+.@sold_card3+","+.@sold_card4+",NOW(),"+.@player_aid+",'"+escape_sql( .@player_name$ )+"','"+.@note$+"' )" );
197 return 1;
198 }
199
200 return 0;
201 }
202
203 function func_item_name {
204 .@item_id = getarg(0);
205 .@amount = getarg(1);
206 .@refine = getarg(2);
207
208 .@string$ = getitemname( .@item_id );
209 .@type = getiteminfo( .@item_id,2 );
210
211 if ( .@string$ == "null" )
212 return "none";
213
214 if ( .@refine )
215 .@string$ = "+"+.@refine+" "+.@string$;
216 if ( .@type == IT_WEAPON || .@type == IT_ARMOR )
217 .@string$ = .@string$ + " ["+getitemslots( .@item_id )+"]";
218 if ( .@amount > 1 )
219 .@string$ = .@amount+" x "+.@string$;
220
221 return .@string$;
222 }
223
224 function func_list_char {
225 __OnInput:
226 while( input( .@player_name$,3,24 ) );
227 query_sql( "SELECT `name`,`class` FROM `char` WHERE `name` LIKE '%"+escape_sql( .@player_name$ )+"%' ORDER BY `name` LIMIT 50",.@temp_name$,.@class );
228 .@temp_name_size = getarraysize( .@temp_name$ );
229
230 if ( .@temp_name_size <= 0 ) {
231 dispbottom "[ GM Reward - Checklist ] '"+.@player_name$+"' doesnt exist.";
232 // next;
233 if( select( "Search another Name","Cancel" ) == 1 ) goto __OnInput;
234 return "";
235 }
236 else if ( .@temp_name_size > 1 ) {
237 dispbottom "[ GM Reward - Checklist ] Pick a player.";
238 for ( .@i = 0; .@i < .@temp_name_size; .@i++ )
239 .@menu$ = .@menu$ + "^FF0000["+jobname( .@class[.@i] )+"] ^000000" + .@temp_name$[.@i] +":";
240 .@i = select( .@menu$ ) - 1;
241 }
242 return .@temp_name$[.@i];
243 }
244
245 function func_display_card {
246 for ( .@i = 0; .@i < 4; .@i++ ) {
247 .@card_id = getarg( .@i );
248 if ( .@card_id ) {
249 .@card_found++;
250 .@card[.@i] = .@card_id;
251 setd( ".@card_"+.@card_id+"_count" ),getd( ".@card_"+.@card_id+"_count" ) + 1;
252 }
253 }
254 if ( .@card_found ) {
255 .@exist_card$ = "#";
256 for ( .@i = 0; .@i < 4; .@i++ )
257 if ( .@card[.@i] ) {
258 if ( !compare( .@exist_card$,"#"+.@card[.@i]+"#" ) )
259 mes " ^6495ED>^000000 "+func_item_name( .@card[.@i],getd( ".@card_"+.@card[.@i]+"_count" ),0 );
260 .@exist_card$ = .@exist_card$ + .@card[.@i] + "#";
261 }
262 }
263 return;
264 }
265
266 function func_list_reward {
267 .@condition$ = getarg( 0,"" );
268
269 query_sql( "SELECT `id`,`nameid`,`amount`,`refine`,`status`,`note` FROM `ero_gm_reward` WHERE "+.@condition$+" ORDER BY `id` DESC LIMIT 50",.@id,.@nameid,.@amount,.@refine,.@status,.@note$ );
270 .@id_size = getarraysize( .@id );
271
272 mes " ";
273 if ( .@id_size <= 0 ) {
274 mes "^FF0000No records are founds.^000000";
275 }
276 else {
277 mes "Found "+.@id_size+" Reward(s).";
278 while( .@id_size > 0 ) {
279
280 .@menu$ = "";
281 for ( .@i = 0; .@i < .@id_size; .@i++ ) {
282 // .@menu$ = .@menu$ + func_item_name( .@nameid[.@i],.@amount[.@i],.@refine[.@i] );
283 .@menu$ = .@menu$ + .@note$[.@i];
284 .@menu$ = .@menu$ + ":";
285 }
286 next;
287 .@reward = select( .@menu$ ) - 1;
288
289 if ( func_view_reward( .@id[.@reward],.@status[.@reward] ) > 0 ) {
290 deletearray .@id[.@reward],1;
291 deletearray .@nameid[.@reward],1;
292 deletearray .@amount[.@reward],1;
293 deletearray .@amount[.@reward],1;
294 deletearray .@status[.@reward],1;
295 .@id_size--;
296 }
297 }
298 }
299 return;
300 }
301
302 function func_view_reward {
303 .@id = getarg(0);
304 .@status = getarg(1);
305
306 if ( .@id <= 0 ) {
307 mes "Invalid Reward - "+.@id;
308 return 0;
309 }
310 else {
311 query_sql( "SELECT `gm_name`,`nameid`,`amount`,`refine`,`reward_time`,`claim_name`,`claim_time`,`note`,`card1`,`card2`,`card3`,`card4` FROM `ero_gm_reward` WHERE `id` = '"+.@id+"' LIMIT 1",.@gm_name$,.@nameid,.@amount,.@refine,.@reward_time$,.@claim_name$,.@claim_time$,.@note$,.@card1,.@card2,.@card3,.@card4 );
312
313 .@item_name$ = func_item_name( .@nameid,.@amount,.@refine );
314 mes "^0055FF[ Reward # "+.@id+" ]^000000";
315 mes "GM : ^777777"+.@gm_name$+"^000000";
316 mes "Player : ^777777"+.@claim_name$+"^000000";
317 mes "Item: ^0055FF"+.@item_name$+"^000000";
318 .@item_type = getiteminfo( .@nameid,2 );
319 if ( .@item_type == IT_ARMOR || .@item_type == IT_WEAPON )
320 func_display_card( .@card1,.@card2,.@card3,.@card4 );
321
322 mes "Date: ^777777"+.@reward_time$+"^000000";
323 mes "Claimed: "+( ( .@status )? "^777777"+.@claim_time$:"^FF0000not yet" )+"^000000";
324 mes "GM Note : ";
325 mes "^777777"+.@note$+"^000000";
326
327 .@char_name$ = strcharinfo(0);
328 .@is_gm = ( getgmlevel() >= .gm_level );
329
330 switch( select(
331 ( .@char_name$ == .@claim_name$ && !.@status && .@claim_time$ == "0000-00-00 00:00:00" ) ? "Claim Reward":"",
332 ( .@is_gm && .@status == 0 ) ? "^FF0000Delete Reward^000000":"",
333 ( .@is_gm && .@status == 2 ) ? "^FF0000Recover Reward^000000":"",
334 "Back"
335 )){
336 default: return 0;
337 case 1:
338 if ( !checkweight( .@nameid,.@amount ) ) {
339 message .@char_name$,"Overweight Detected!";
340 }
341 else {
342 query_sql( "UPDATE `ero_gm_reward` SET `status` = 1,`claim_time` = NOW() WHERE `id` = "+.@id+" LIMIT 1" );
343 getitem2 .@nameid,.@amount,1,.@refine,0,.@card1,.@card2,.@card3,.@card4;
344 message .@char_name$,"Claimed Reward # "+.@id+" - "+.@item_name$;
345 break;
346 }
347 case 2:
348 query_sql( "UPDATE `ero_gm_reward` SET `status` = 2 WHERE `id` = "+.@id+" LIMIT 1" );
349 message .@char_name$,"Deleted Reward # "+.@id+" - "+.@item_name$;
350 break;
351 case 3:
352 query_sql( "UPDATE `ero_gm_reward` SET `status` = 0 WHERE `id` = "+.@id+" LIMIT 1" );
353 message .@char_name$,"Recovered Reward # "+.@id+" - "+.@item_name$;
354 break;
355 }
356 }
357 return 1;
358 }
359}