Advertisement
Guest User

Untitled

a guest
Nov 7th, 2014
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 4.39 KB | None | 0 0
  1. //script.c
  2.  
  3. +static int buildin_areascript_sub(struct block_list *bl,va_list ap)
  4. +{
  5. +       char *bonus_script =  va_arg(ap,char *);
  6. +       struct script_code *script =  parse_script(bonus_script, "script4each", 0, 0);
  7. +
  8. +       run_script(script,0,bl->id,0);
  9. +
  10. +       return 0;
  11. +}
  12.  
  13. +BUILDIN_FUNC(script4each)
  14. +{
  15. +   int type;
  16. +   const char *bonus_script;
  17. +   struct map_session_data* pl_sd;
  18. +   struct s_mapiterator* iter;
  19. +   struct script_code *script;
  20. +
  21. +   bonus_script = script_getstr(st,2);
  22. +   type = script_getnum(st,3);
  23. +
  24. +   script =  parse_script(bonus_script, "script4each", 0, 0);
  25. +
  26. +   iter = mapit_getallusers();
  27. +
  28. +   switch (type)
  29. +   {
  30. +   case 0:
  31. +           for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  32. +               run_script(script,0,pl_sd->bl.id,0);
  33. +           break;
  34. +
  35. +   case 1:
  36. +       {
  37. +       int map_index;
  38. +
  39. +       if(!script_hasdata(st, 4))
  40. +           break;
  41. +       if(map_mapname2mapid(script_getstr(st,4)) < 0)
  42. +           break;
  43. +
  44. +           map_index = map_mapname2mapid(script_getstr(st,4));
  45. +           for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  46. +           {
  47. +               if(pl_sd->bl.m == map_index)
  48. +                   run_script(script,0,pl_sd->bl.id,0);
  49. +           }
  50. +      
  51. +       }
  52. +       break;
  53. +
  54. +   case 2:
  55. +       {
  56. +           int map_index,x,y,range;
  57. +           struct block_list center;
  58. +
  59. +           if(!script_hasdata(st, 4) || !script_hasdata(st, 5) || !script_hasdata(st, 6) || !script_hasdata(st, 7))
  60. +               break;
  61. +           else
  62. +           {
  63. +               if(map_mapname2mapid(script_getstr(st,4)) < 0)
  64. +                   break;
  65. +
  66. +               x = script_getnum(st,5);
  67. +               y = script_getnum(st,6);
  68. +               range = script_getnum(st,7);
  69. +
  70. +               map_index = map_mapname2mapid(script_getstr(st,4));
  71. +               center.m = map_index;
  72. +               center.x = x;
  73. +               center.y = y;
  74. +
  75. +               map_foreachinrange(buildin_areascript_sub, &center, range, BL_PC, bonus_script);
  76. +           }
  77. +       }
  78. +       break;
  79. +
  80. +   case 3:
  81. +       {
  82. +           TBL_PC *sd;
  83. +           int char_id, party_id;
  84. +
  85. +           if(!script_hasdata(st, 4))
  86. +               break;
  87. +           else
  88. +               char_id = script_getnum(st,4);
  89. +
  90. +           sd = map_charid2sd(char_id);
  91. +           if (!sd) break;
  92. +           party_id = sd->status.party_id;
  93. +
  94. +           if(party_id == 0)
  95. +               break;
  96. +
  97. +           for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  98. +           {
  99. +               if(pl_sd->status.party_id == party_id)
  100. +                   run_script(script,0,pl_sd->bl.id,0);
  101. +           }
  102. +       }
  103. +       break;
  104. +
  105. +   case 4:
  106. +       {
  107. +           TBL_PC *sd;
  108. +           int char_id, guild_id;
  109. +
  110. +           if(!script_hasdata(st, 4))
  111. +               break;
  112. +           else
  113. +               char_id = script_getnum(st,4);
  114. +
  115. +           sd = map_charid2sd(char_id);
  116. +           if (!sd) break;
  117. +           guild_id = sd->status.guild_id;
  118. +
  119. +           if(guild_id == 0)
  120. +               break;
  121. +
  122. +           for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  123. +           {
  124. +               if(pl_sd->status.guild_id == guild_id)
  125. +                   run_script(script,0,pl_sd->bl.id,0);
  126. +           }
  127. +       }
  128. +       break;
  129. +
  130. +   case 5:
  131. +       {
  132. +           int map_index,x0,y0,x1,y1;
  133. +
  134. +           if(!script_hasdata(st, 4) || !script_hasdata(st, 5) || !script_hasdata(st, 6) || !script_hasdata(st, 7) || !script_hasdata(st, 8))
  135. +               break;
  136. +           else
  137. +           {
  138. +               if(map_mapname2mapid(script_getstr(st,4)) < 0)
  139. +                   break;
  140. +
  141. +               x0 = script_getnum(st,5);
  142. +               y0 = script_getnum(st,6);
  143. +               x1 = script_getnum(st,7);
  144. +               y1 = script_getnum(st,8);
  145. +               map_index = map_mapname2mapid(script_getstr(st,4));
  146. +               map_foreachinarea(buildin_areascript_sub,map_index,x0,y0,x1,y1,BL_PC,bonus_script);
  147. +           }
  148. +       }
  149. +       break;
  150. +
  151. +   case 6:
  152. +       {
  153. +           int party_id;
  154. +
  155. +           if(!script_hasdata(st, 4))
  156. +               break;
  157. +           else
  158. +               party_id = script_getnum(st,4);
  159. +
  160. +           for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  161. +           {
  162. +               if(pl_sd->status.party_id == party_id)
  163. +                   run_script(script,0,pl_sd->bl.id,0);
  164. +           }
  165. +       }
  166. +       break;
  167. +
  168. +   case 7:
  169. +       {
  170. +           int guild_id;
  171. +
  172. +           if(!script_hasdata(st, 4))
  173. +               break;
  174. +           else
  175. +               guild_id = script_getnum(st,4);
  176. +
  177. +           for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
  178. +           {
  179. +               if(pl_sd->status.guild_id == guild_id)
  180. +                   run_script(script,0,pl_sd->bl.id,0);
  181. +           }
  182. +       }
  183. +       break;
  184. +
  185. +   default:
  186. +       //ShowError("script4each : %d %s!\n",type,sys_msg(390));
  187. +       ShowError("script4each : %d 是一個錯誤的類型!\n",type);
  188. +       break;
  189. +   }
  190. +
  191. +   if(script)
  192. +       script_free_code(script);
  193. +
  194. +   return 0;
  195. +}
  196.  
  197.  
  198. +BUILDIN_DEF(script4each,"si?????"),
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement