Advertisement
icabit

ref

Aug 30th, 2014
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.32 KB | None | 0 0
  1. //Title: Icabit's Referral System
  2. //Version: 1
  3. //Author: Icabit
  4. //Created: 09/06/2013
  5. //Released: 01/07/
  6. //Compatibility: rAthena | Hercules
  7. //Support: SQL
  8. //Credits:Thank you to the Athena community.
  9. //
  10. // Don't Claim this script as yours..
  11. // Don't Delete This header
  12. // Don't Modify without My Permission
  13. //
  14.  
  15. - script totaltime -1,{
  16.  
  17. //--Start of the Script
  18. OnPCLoginEvent:
  19. set .@harmony,1; // if you have harmony, set this to 1 or more for additional mac address check
  20. set .@myname$, strcharinfo(0);
  21.  
  22. if (.@harmony>=1)
  23. {
  24. query_sql "SELECT `account_id` FROM `totaltime` WHERE `account_id`="+getcharid(3),.@accid;
  25. if (query_sql("SELECT `char`.`name` FROM `char` LEFT JOIN login ON `char`.account_id=login.account_id WHERE login.last_mac=(SELECT last_mac FROM login WHERE account_id="+getcharid(3)+") AND `char`.online=1 AND `char`.char_id!="+getcharid(0), .@name$) >= 1)
  26. {
  27. for (set .@i,0; .@i<getarraysize(.@name$); set .@i,.@i+1) {
  28. if (checkvending(.@name$[.@i]) != 2)
  29. set .@samemac, .@samemac +1;
  30. }
  31. if (.@samemac >= 1) {
  32. announce "Sorry, only 1 account per computer can only be recorded for your game time.", bc_self;
  33. end;
  34. }
  35. }
  36.  
  37. }
  38.  
  39. query_sql "SELECT `account_id` FROM `totaltime` WHERE `account_id`="+getcharid(3),.@accid;
  40. if (.@harmony>=1)
  41. {
  42. query_sql "SELECT `last_mac` FROM `login` WHERE `account_id`="+getcharid(3),.@lastmac$;
  43. if ( .@accid == 0 )
  44. {
  45. query_sql "INSERT INTO `totaltime` VALUES (" + getcharid(3) + ",0,0,0,0,'"+.@lastmac$+"')";
  46. //freebies add here
  47. getitem 31016,1;
  48. getitem 27920,10;
  49. dispbottom "You have Claimed your Freebies";
  50. }
  51. else
  52. {
  53. query_sql "UPDATE `totaltime` SET `mac` = ('" + .@lastmac$ + "') WHERE `account_id`=" + getcharid(3);
  54. }
  55. }
  56. else
  57. {
  58. if ( .@accid == 0 ) { query_sql "INSERT INTO `totaltime` VALUES (" + getcharid(3) + ",0,0,0,0)"; }
  59. //freebies add here
  60. getitem 31016,1;
  61. getitem 27920,10;
  62. dispbottom "You have Claimed your Freebies";
  63. }
  64.  
  65. if( #DailyBonus != gettime(5) ){
  66. dispbottom "You Have Gained Daily Rewards";
  67. getitem 673,1;
  68. set #DailyBonus ,gettime(5);
  69. set totaltime,0;
  70. }
  71. set totaltimeold,totaltime; //copies the current totaltime
  72. set @afk,0;
  73. attachnpctimer ""+strcharinfo(0)+"";
  74. initnpctimer;
  75. // dispbottom .@accid;
  76. // dispbottom .@lastmac$;
  77. end;
  78.  
  79.  
  80. OnTimer60000:
  81. if(isloggedin(strcharinfo(0))) // checks for @autotrade and @afk characters
  82. {
  83. stopnpctimer;
  84. end;
  85. }
  86. //Check if Vending (normal or @at)
  87. if(@afk >= 3) {
  88. getmapxy( .@map$, .@x, .@y, 0 );
  89. if(@map$ == .@map$ && @x == .@x && @y == .@y) {
  90. dispbottom "The total time playing has been stopped because you were idle for "+@afk+" Minutes.";
  91. set @afk, @afk + 1;
  92. }
  93. else
  94. {
  95. set @afk,0;
  96. }
  97. stopnpctimer;
  98. attachnpctimer ""+strcharinfo(0)+"";
  99. initnpctimer;
  100. end;
  101. }
  102. if(checkvending() >= 1 || checkchatting() == 1) {
  103. set @afk, @afk + 1;
  104. stopnpctimer;
  105. attachnpctimer ""+strcharinfo(0)+"";
  106. initnpctimer;
  107. end;
  108. }
  109. else
  110. {
  111. //Check if Idle
  112. getmapxy( .@map$, .@x, .@y, 0 );
  113. if(@map$ == .@map$ && @x == .@x && @y == .@y) {
  114. set @afk, @afk + 1;
  115. }
  116. //If move increases total time of accnt by 1 min
  117. else {
  118. set @afk, 0;
  119. set totaltime,totaltime+1;
  120. if ((totaltime%60)==0){ getitem 673,1; dispbottom "Heres your reward being online for total time in minutes: "+ totaltime; }
  121. if ((totaltime%300)==0){ getitem 671,1; dispbottom "Heres your reward being online for total time in minutes: "+ totaltime; }
  122. }
  123. set @map$, .@map$; set @x, .@x; set @y, .@y;
  124. //Idle Check for 3 minutes
  125. //if(@afk >= 3) {
  126. //dispbottom "The total time playing has been stopped because you were idle for "+@afk+" Minutes.";
  127. //stopnpctimer;
  128. //attachnpctimer ""+strcharinfo(0)+"";
  129. //initnpctimer;
  130. //end;
  131. //}
  132. //dont uncomment this area unless you know what to do and what will happen
  133. //query_sql "UPDATE `totaltime` SET `time` = (`time` + 1) WHERE `account_id`=" + getcharid(3);
  134. //dispbottom "your total time in minutes: "+ totaltime; // for debug purposes
  135. stopnpctimer;
  136. attachnpctimer ""+strcharinfo(0)+"";
  137. initnpctimer;
  138. end;
  139. //recording times or updating database
  140. OnPCLogoutEvent:
  141. set @totalcalc,totaltime-totaltimeold;
  142. query_sql "SELECT MAX(base_level) FROM `char` where account_id=" + getcharid(3),.@maxlvl;
  143. query_sql "UPDATE `totaltime` SET `time` = (`time` + " + @totalcalc + ") WHERE `account_id`=" + getcharid(3);
  144. query_sql "UPDATE `totaltime` SET `level` = (" + .@maxlvl + ") WHERE `account_id`=" + getcharid(3);
  145. end;
  146. }
  147.  
  148. }
  149. //--End of the Script
  150.  
  151. //Time ladder
  152. mellina,64,60,5 script Referral System 837,{
  153.  
  154. set .@harmony,1; // if you have harmony, set this to 1 or more for additional mac address check
  155. set .@mlvlreq,230; //lvl requirement for the newbie to qualify for a point
  156. set .@daysqualify,3; //number of days of gaming time
  157. set .@timequalify,.@daysqualify*24*60; //.@daysqualify stands for days, 24 for hours , 60 for min edit this to your own liking
  158. set .@pointreq,5; //total point requirement in order to claim the reward, this will also determine the length of the list of accounts that the player recruited.
  159. set .@npc$,"[ ^FF0000 Referral System ^000000 ]"; // npc name
  160. set .@glvl,99; // minimum group level to check the list of accounts that had the longest game time/length
  161. set .@llength,10;// length of the list for gm's
  162. set .@Zeny,0; //Zeny reward (0:Disable)
  163. set .@maxZeny,2000000000;// max Zeny of the server
  164. setarray .@itemreward, 7227,677; //item rewards (0:Disable)
  165. setarray .@itemquantity, 120,6;// it should be paired with item reward
  166.  
  167.  
  168. //start of script
  169. mes .@npc$;
  170. mes "What do you want to do?";
  171. switch(select("Time Check:Referral System:Close")){
  172. case 1:
  173. next;
  174. if (getgroupid()>=.@glvl)
  175. {
  176. mes .@npc$;
  177. query_sql "SELECT account_id, time FROM `totaltime` ORDER BY time DESC LIMIT 10",.@nameid,.@time;
  178. for(set .@i,0;.@i<.@llength;set .@i,.@i+1) {
  179. mes "^0000FF"+(.@i+1)+".^000000 " +( (.@nameid[.@i] == 0)? "None":.@nameid[.@i] )+ " - ^FF0000"+(.@time[.@i])+"^000000 Minute(s)";
  180. }
  181. mes " ";
  182. }
  183. query_sql "SELECT `time` FROM `totaltime` WHERE `account_id`="+getcharid(3),.@time;
  184. mes "^0000FF["+strcharinfo(0)+"'s]^000000 total time is ^FF0000"+(.@time)+"^000000 Minute(s).";
  185. close;
  186. break;
  187. case 2:
  188. switch(select("Check Points and Recruits:Your Recruiter:Close")){
  189. case 1:
  190. query_sql "SELECT account_id, time , level FROM `totaltime` WHERE `raccount_id`="+getcharid(3)+" ORDER BY level DESC LIMIT 10",.@name$,.@time,.@level$;
  191. for(set .@i,0;.@i<.@pointreq;set .@i,.@i+1) {
  192. mes "^0000FF"+(.@i+1)+".^000000 " +( (.@name$[.@i] == "")? "None":.@name$[.@i] )+ " - ^FF0000"+(.@time[.@i])+"^000000 Minute(s)";
  193. }
  194. query_sql "SELECT account_id FROM `totaltime` WHERE `time`>= "+.@timequalify+" AND `raccount_id`="+getcharid(3)+" ORDER BY level DESC LIMIT 10 ",.@name1$;
  195. set .@paccounts, getarraysize(.@name1$);
  196. set .@pointearned,0;
  197. for(set .@i,0; .@i<=.@paccounts; set .@i,.@i+1)
  198. {
  199. query_sql "SELECT MAX(base_level) FROM `char` where account_id="+.@name1$,.@maxlvl;
  200. if ( .@maxlvl>=.@mlvlreq ) { set .@pointearned,.@pointearned+1; break; }
  201. }
  202. mes "________________________";
  203. mes "You will earn 1 point for every Recruit you have who's been playing for "+ .@daysqualify +" day(s) worth of game time and he or she must have at least 1 level "+.@mlvlreq+" character in his or her account.";
  204. mes "________________________";
  205. mes "You already have ^FF0000"+ .@pointearned +"^000000 points gained";
  206. mes "________________________";
  207. query_sql "SELECT `claimed` FROM `totaltime` WHERE `account_id`="+getcharid(3),.@clamied;
  208. if (.@clamied==1) mes "Your reward status:^00FF00Already claimed Reward^000000"; close;
  209. if (.@clamied==0)
  210. {
  211. mes "Your reward status:^FF0000Haven't claimed reward^000000";
  212. mes "________________________";
  213. next;
  214. mes .@npc$;
  215. mes "Do you want to claim your reward?";
  216. switch(select("Yes:Close"))
  217. {
  218. case 1:
  219. next;
  220. mes .@npc$;
  221. mes "You will need 10 points to claim your reward...";
  222. mes "________________________";
  223. mes "You already have ^FF0000"+ .@pointearned +"^000000 points gained";
  224. switch(select("Claim Reward:Close"))
  225. {
  226. case 1:
  227. if (.@pointearned>=.@pointreq)
  228. {
  229. next;
  230. mes .@npc$;
  231. if ((Zeny+.@Zeny)>=.@maxZeny)
  232. {
  233. mes "If i reward you will have more than "+ .@maxZeny +" which is the max limit of Zeny in the server...";
  234. mes "Come back once you have lesser Zeny with you";
  235. close;
  236. }
  237. else
  238. {
  239. set Zeny,Zeny + .@Zeny;
  240. for(set .@i, 0; .@i < getarraysize(.@itemreward); set .@i, .@i + 1)
  241. {
  242. if(.@itemreward)
  243. {
  244. getitem .@itemreward[.@i], .@itemquantity[.@i];
  245. }
  246. else
  247. {
  248. break;
  249. }
  250. }
  251. mes "Congratulations you have been rewarded by recruiting Active players :)";
  252. query_sql "UPDATE `totaltime` SET `claimed` = (1) WHERE `account_id`=" + getcharid(3);
  253. close;
  254. }
  255. }
  256. else
  257. {
  258. next;
  259. mes .@npc$;
  260. mes "Sorry, You haven't met the requirements";
  261. mes "come back once you have "+.@pointreq+" points";
  262. close;
  263. }
  264. close;
  265. break;
  266. case 2:
  267. mes .@npc$;
  268. mes "See you later...";
  269. close;
  270. break;
  271. }
  272. break;
  273. case 2:
  274. mes .@npc$;
  275. mes "See you later...";
  276. break;
  277. close;
  278. }
  279. }
  280. close;
  281. break;
  282. case 2:
  283.  
  284. query_sql "SELECT `raccount_id` FROM `totaltime` WHERE `account_id`="+getcharid(3),.@raccountid;
  285. if (.@raccountid==0) // no recruiter
  286. {
  287. mes .@npc$;
  288. mes "Do you want to register your recruiter?";
  289. switch(select("Yes:NO"))
  290. {
  291. case 1:
  292. next;
  293. mes .@npc$;
  294. mes "Kindly Type the Name of Your Recruiter. Make sure you have the right spelling";
  295. set @rname$,0;
  296. input @rname$;
  297. if (@rname$ == strcharinfo(0)) //checks if the player writes his/her own name
  298. {
  299. next;
  300. mes .@npc$;
  301. mes "You can't be your own recruiter";
  302. close;
  303. break;
  304. }
  305. if (@rname$=="") //checks if the recruiter exists
  306. {
  307. next;
  308. mes .@npc$;
  309. mes "Please Enter a The name of your Recruiter";
  310. close;
  311. break;
  312. }
  313. query_sql "SELECT `account_id` FROM `char` WHERE `name`='"+@rname$+"'",.@accid;
  314.  
  315. if (.@accid == getcharid(3)) //checks if he's trying to recruit himself with his other characters
  316. {
  317. next;
  318. mes .@npc$;
  319. mes "You can't use your other character to be your own recruiter";
  320. close;
  321. break;
  322. }
  323. else
  324. {
  325. if(.@harmony >= 1)
  326. { //harmony mac address check
  327. query_sql "SELECT `last_mac` FROM `login` WHERE `account_id`="+getcharid(3),.@lastmac1$;
  328. query_sql "SELECT `last_mac` FROM `login` WHERE `account_id`="+.@accid,.@lastmac2$;
  329. if(.@lastmac1$==.@lastmac2$)
  330. {
  331. next;
  332. mes .@npc$;
  333. mes "You can't use your other account to be your own recruiter";
  334. close;
  335. break;
  336. }
  337. }
  338. query_sql "SELECT `time` FROM `totaltime` WHERE `account_id`="+.@accid,.@rtime;//gets the time of the recruiter
  339. query_sql "SELECT `time` FROM `totaltime` WHERE `account_id`="+getcharid(3),.@rtime2;//gets the the of the newbie
  340. if (.@rtime2>=.@rtime) //compare both times
  341. {
  342. next;
  343. mes .@npc$;
  344. mes "Your recruiter is not qualified..";
  345. mes "Your game time is greater than your recruiter...";
  346. mes "Your recruiter should be more experienced than you..";
  347. close;
  348. break;
  349. }
  350. next;
  351. mes .@npc$;
  352. mes "Are you sure yo want "+ @rname$ +" to be your recruiter?";
  353. mes "^FF0000note^000000 you can't change this any more once you set it up";
  354. switch(select("Yes:No"))
  355. {
  356. case 1:
  357. next;
  358. query_sql "UPDATE `totaltime` SET `raccount_id` = (" + .@accid + ") WHERE `account_id`=" + getcharid(3);
  359. mes "You have listed "+@rname$+" as your recruiter";
  360. break;
  361. close;
  362. case 2:
  363. next;
  364. mes .@npc$;
  365. mes "See you later...";
  366. break;
  367. close;
  368. }
  369. }
  370. case 2:
  371. next;
  372. mes .@npc$;
  373. mes "See you later...";
  374. close;
  375. break;
  376. }
  377. }
  378. else //already recruited
  379. {
  380. next;
  381. mes .@npc$;
  382. mes "You have already been recruited.";
  383. mes "See you later...";
  384. close;
  385. break;
  386. }
  387. close;
  388. break;
  389. case 3:
  390. next;
  391. mes .@npc$;
  392. mes "See you later...";
  393. close;
  394. break;
  395. }
  396. close;
  397. break;
  398. case 3:
  399. next;
  400. mes .@npc$;
  401. mes "See you later...";
  402. close;
  403. break;
  404. }
  405. OnInit:
  406. waitingroom "Referral System",0; // Look on the configuration!
  407. }
  408.  
  409.  
  410. //execute this to your sql database
  411. /*
  412. CREATE TABLE IF NOT EXISTS `totaltime` (
  413. `account_id` int(11) NOT NULL,
  414. `time` int(255) NOT NULL,
  415. `claimed` int(11) NOT NULL,
  416. `raccount_id` int(11) NOT NULL,
  417. `level` int(11) NOT NULL,
  418. `mac` VARCHAR( 18 ) NOT NULL, //remove this line if you don't have harmony/or any mac address detection
  419. PRIMARY KEY (`account_id`)
  420. ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
  421. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement