Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2012
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.73 KB | None | 0 0
  1. //====================================================================================
  2. //Script Name: Vote For Points NPC Script for FluxCP
  3. //SVN: Tested in rAthena r156513
  4. //Developed By: JayPee Mateo
  5. //Version: 1.0
  6. //Requirement(s): FluxCP V4P Addon
  7. //Description: This is a npc script for FluxCP Vote for points in order for the players
  8. //to claim their vote points
  9. //====================================================================================
  10.  
  11. prontera,164,156,3 script VoteForPoints 89,{
  12.  
  13. //Function Prototypes
  14. function garbagecol;//Garbage collection for the Character variables
  15. garbagecol();
  16. function add_item; //Syntanx: add_item(ITEMID,QUANTITY,POINTS,CATEGORY);
  17. function makeCategory;//This will return a list of the categories
  18. function getItemsByCat;//This will return the list of items associated to the particular category
  19. function getItemDetails;//This will return the details of the item
  20. function getPoints;//This will return the points of the player stored in the database
  21. function updatePoints;//This will updates the points of the player stored in the database
  22.  
  23.  
  24. //NPC Name
  25. set .npcname$,"[ VotePoints ]";
  26.  
  27. //Initialization of the Rewards
  28. add_item(555,1,100,"Hello");
  29. add_item(556,2,101,"Hello");
  30. add_item(557,3,101,"Hello1");
  31.  
  32.  
  33. //Script Start
  34. mes .npcname$;
  35. mes "Hi! Do you want to exchange your vote points?:";
  36. switch(select("Yes, I want to exchange my points:See my points"))
  37. {
  38. case 1:
  39. next;
  40. mes .npcname$;
  41. mes "Please choose a category:";
  42. set .@selected,select(makeCategory())-1;
  43. next;
  44. mes .npcname$;
  45. mes "Please the item you want:";
  46. set .@selected,select(getItemsByCat(@listCat$[.@selected]))-1;
  47.  
  48. next;
  49. mes .npcname$;
  50. set .@ritemid,getItemDetails(@itemKeys[.@selected],"itemid");
  51. set .@rquantity,getItemDetails(@itemKeys[.@selected],"quantity");
  52. set .@rpoints,getItemDetails(@itemKeys[.@selected],"points");
  53. mes "Item ID:"+.@ritemid;
  54. mes "Item Name: "+getitemname(.@ritemid);
  55. mes "Item Quantity: "+.@rquantity+" pc(s).";
  56. mes "Required Points: "+.@rpoints+" pt(s).";
  57. mes "\n";
  58. mes "Do you want to this item?";
  59. if(select("Yes:No")==1)
  60. {
  61. set .@points,getPoints(getcharid(3));
  62. if(.@points>=.@rpoints)
  63. {
  64. next;
  65. mes .npcname$;
  66. updatePoints(getcharid(3),.@rpoints);
  67. getitem .@ritemid,.@rquantity;
  68. mes "Here you go!. Thank you for voting. Don't forget to vote again. :D";
  69. }
  70. else
  71. mes "Sorry, you do not have enough points for this item.";
  72. }
  73. else
  74. {
  75. next;
  76. mes .npcname$;
  77. mes "Okay bye!";
  78. }
  79. garbagecol();
  80. close;
  81. case 2:
  82. next;
  83. mes .npcname$;
  84. set .@points,getPoints(getcharid(3));
  85. mes "You currently have "+.@points+" pt(s).";
  86. garbagecol();
  87. close;
  88. }
  89. end;
  90.  
  91. //Functions Bodies
  92. function updatePoints {
  93. set .@account_id,getarg(0);
  94. set .@usedPoints,getarg(1);
  95. query_sql("UPDATE `cp_v4p_voters` SET points=(points-"+.@usedPoints+") WHERE account_id='"+.@account_id+"'");
  96. return;
  97. }
  98.  
  99. function getPoints {
  100. set .@account_id,getarg(0);
  101. query_sql("SELECT `points` FROM `cp_v4p_voters` WHERE account_id="+.@account_id+" LIMIT 1",.@points);
  102. if(getarraysize(.@points)==0)
  103. return 0;
  104. return .@points[0];
  105. }
  106.  
  107. function getItemDetails {
  108. set .@key,getarg(0); //Key
  109. set .@detail$,getarg(1); //What details to return such as ItemID, Points, Quantity, Category
  110.  
  111. if(strtolower(.@detail$) == strtolower("ItemID"))
  112. return @itemID[.@key];
  113. else if(strtolower(.@detail$) == strtolower("Quantity"))
  114. return @itemQ[.@key];
  115. else if(strtolower(.@detail$) == strtolower("Points"))
  116. return @points[.@key];
  117. else if(strtolower(.@detail$) == strtolower("Category"))
  118. return @category$[.@key];
  119. }
  120.  
  121. function getItemsByCat {
  122. set .@selectedCat$,getarg(0);
  123. set .@make_string$,"";
  124. set .@x,0;
  125. for(set .@i,0; .@i<getarraysize(@category$); set .@i,.@i+1)
  126. {
  127. if(strtolower(.@selectedCat$) == strtolower(@category$[.@i]))
  128. {
  129. setarray @itemKeys[.@x],.@i;
  130. if(.@make_string$ == "")
  131. set .@make_string$,getitemname(@itemID[.@i]);
  132. else
  133. set .@make_string$,.@make_string$+":"+getitemname(@itemID[.@i]);
  134.  
  135. set .@x,.@x+1;
  136. }
  137. }
  138. return .@make_string$;
  139. }
  140.  
  141.  
  142. function makeCategory {
  143. set .@make_string$,"";
  144. for(set .@i,0; .@i<getarraysize(@category$); set .@i,.@i+1)
  145. {
  146. if(.@make_string$ == "")
  147. {
  148. setarray @listCat$[getarraysize(@listCat$)],@category$[.@i];
  149. set .@make_string$,@category$[.@i];
  150. }
  151. else
  152. {
  153. if(compare(.@make_string$,@category$[.@i])==0)
  154. {
  155. setarray @listCat$[getarraysize(@listCat$)],@category$[.@i];
  156. set .@make_string$,.@make_string$+":"+@category$[.@i];
  157. }
  158. }
  159. }
  160. return .@make_string$;
  161. }
  162.  
  163. function add_item
  164. {
  165. set .@itemID,getarg(0,-1); //IteID
  166. set .@itemQ,getarg(1,-1); //Item Quantity
  167. set .@points,getarg(2,-1);
  168. set .@cat$,getarg(3,"Uncategorized"); //Category
  169.  
  170.  
  171. if(.@itemID == -1)
  172. {
  173. debugmes "Invalid Item ID. Script not completely loaded.";
  174. end;
  175. }
  176. else if(.@itemQ == -1)
  177. {
  178. debugmes "Invalid Item Quantity. Script not completely loaded.";
  179. end;
  180. }
  181. else if(.@points == -1)
  182. {
  183. debugmes "Points assignment error. Script not completely loaded.";
  184. end;
  185. }
  186. set .@key,getarraysize(@itemID);
  187. setarray @itemID[.@key],.@itemID;
  188. setarray @itemQ[.@key],.@itemQ;
  189. setarray @points[.@key],.@points;
  190. setarray @category$[.@key],.@cat$;
  191. return 1; //return 1 as success
  192. }
  193.  
  194. function garbagecol{
  195. deletearray @itemID[0],128;
  196. deletearray @itemQ[0],128;
  197. deletearray @points[0],128;
  198. deletearray @category$[0],128;
  199. deletearray @listCat$[0],128;
  200. deletearray @itemKeys[0],128;
  201. return;
  202. }
  203. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement