Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.76 KB | None | 0 0
  1. //| ------------------------------ Bomb System ------------------------------ |
  2.  
  3. #include a_samp
  4. #include dof2
  5. #define SendFormatMessage(%0,%1,%2) format(String,sizeof(String),%1,%2),SendClientMessage(%0,-1,String)
  6. #define MINE_COST 100
  7. #define MAX_MINES 5
  8. new pName[MAX_PLAYERS][25];
  9. new g_BombStr[128];
  10.  
  11. enum MineInfo
  12. {
  13. bool:IsReady,
  14. bool:Plant,
  15. Float:Pos[3],
  16. Mines,
  17. Mine
  18. };
  19. enum MineInfo2
  20. {
  21. bool:IsReady,
  22. bool:Plant,
  23. Float:Pos[3],
  24. Mines,
  25. Mine2
  26. };
  27. new PlayerInfo2[MAX_PLAYERS][MineInfo];
  28. new PlayerInfo[MAX_PLAYERS][MineInfo];
  29. new Float:Position[3];
  30. new String[128];
  31.  
  32. public OnFilterScriptInit()
  33. {
  34. return 1;
  35. }
  36.  
  37. public OnFilterScriptExit()
  38. {
  39. DOF2_SaveFile();
  40. return 1;
  41. }
  42.  
  43. public OnPlayerConnect(playerid)
  44. {
  45. GetPlayerName(playerid, pName[playerid], MAX_PLAYER_NAME+1);
  46. return 1;
  47. if(!DOF2_FileExists(MFile(playerid))) DOF2_CreateFile(MFile(playerid));
  48. if(DOF2_GetBool(MFile(playerid), "Plant") == true)
  49. {
  50. PlayerInfo[playerid][Plant] = true;
  51. PlayerInfo[playerid][Pos][0] = DOF2_GetFloat(MFile(playerid), "X");
  52. PlayerInfo[playerid][Pos][1] = DOF2_GetFloat(MFile(playerid), "Y");
  53. PlayerInfo[playerid][Pos][2] = DOF2_GetFloat(MFile(playerid), "Z");
  54. PlayerInfo[playerid][Mine] = CreateObject(3385, PlayerInfo[playerid][Pos][0], PlayerInfo[playerid][Pos][1], PlayerInfo[playerid][Pos][2]-1.0, 0.0, 0.0, 0.0);
  55. PlayerInfo[playerid][IsReady] = true;
  56. }
  57. PlayerInfo[playerid][Mines] = DOF2_GetInt(MFile(playerid), "Mines");
  58. return 1;
  59. }
  60.  
  61. public OnPlayerDisconnect(playerid, reason)
  62. {
  63. DOF2_SetBool(MFile(playerid), "Plant", PlayerInfo[playerid][Plant]);
  64. DOF2_SetFloat(MFile(playerid), "X", PlayerInfo[playerid][Pos][0]);
  65. DOF2_SetFloat(MFile(playerid), "Y", PlayerInfo[playerid][Pos][1]);
  66. DOF2_SetFloat(MFile(playerid), "Z", PlayerInfo[playerid][Pos][2]);
  67. DOF2_SetInt(MFile(playerid), "Mines", PlayerInfo[playerid][Mines]);
  68. DestroyObject(PlayerInfo[playerid][Mine]);
  69. DOF2_SaveFile();
  70. return 1;
  71. }
  72. public OnPlayerCommandText(playerid, cmdtext[])
  73. {
  74. new cmd[256], tmp[256], idx;
  75. cmd = strtok(cmdtext, idx);
  76. tmp = strtok(cmdtext, idx);
  77. if(strcmp(cmd, "/Bomb", true) == 0)
  78. {
  79. if(!strlen(tmp)) return SendClientMessage(playerid, -1, "/Bomb [Buy | Use | My] :השתמש כך");
  80. if(!strcmp(tmp, "Buy", true))
  81. {
  82. if(!IsPlayerInAnyVehicle(playerid))return SendClientMessage(playerid, 0xFF0000FF, "! אינך ברכב");
  83. if(PlayerInfo[playerid][Mines] == MAX_MINES) return SendFormatMessage(playerid, "! לא ניתן לקנות יותר מ %d מוקשים", MAX_MINES);
  84. if(GetPlayerMoney(playerid) < MINE_COST) return SendFormatMessage(playerid, "$%s :אין לך מספיק כסף, מחיר כל מוקש", GetNum(MINE_COST));
  85. PlayerInfo[playerid][Mines] ++;
  86. GivePlayerMoney(playerid, -MINE_COST);
  87. SendFormatMessage(playerid, "! קנית מוקש בהצלחה, כעת יש לך: %d מוקשים", PlayerInfo[playerid][Mines]);
  88. return 1;
  89. }
  90. else if(!strcmp(tmp, "Use", true))
  91. {
  92. if(!IsPlayerInAnyVehicle(playerid))return SendClientMessage(playerid, 0xFF0000FF, "! אינך ברכב");
  93. if(PlayerInfo[playerid][Plant] == true) return SendClientMessage(playerid, -1, "! הטמנת כבר מוקש");
  94. if(PlayerInfo[playerid][Mines] == 0) return SendClientMessage(playerid, -1, "! אין לך מוקשים");
  95. GetPlayerPos(playerid, Position[0], Position[1], Position[2]);
  96. PlayerInfo2[playerid][Mine2] = CreateObject(3385, Position[0], Position[1], Position[2]-1.0, 0.0, 0.0, 0.0);
  97. PlayerInfo[playerid][Pos][0] = Position[0];
  98. PlayerInfo[playerid][Pos][1] = Position[1];
  99. PlayerInfo[playerid][Pos][2] = Position[2];
  100. GetPlayerPos(playerid, Position[0], Position[1], Position[2]);
  101. format(g_BombStr, 128, "!~Bomb~! By:{ffffff} %s", pName[playerid]);
  102. PlayerInfo[playerid][Mine] = Create3DTextLabel(g_BombStr, 0xFF0000FF, Position[0], Position[1], Position[2], 35.0,0);
  103. PlayerInfo[playerid][Pos][0] = Position[0];
  104. PlayerInfo[playerid][Pos][1] = Position[1];
  105. PlayerInfo[playerid][Pos][2] = Position[2];
  106. GetPlayerPos(playerid, Position[0], Position[1], Position[2]);
  107. ApplyAnimation(playerid, "BOMBER", "BOM_Plant", 4.0, 0, 0, 0, 0, 0);
  108. PlayerInfo[playerid][Plant] = true;
  109. SendClientMessage(playerid, -1, "! הטמנת מוקש, בהצלחה");
  110. CountDownMine(playerid, 5);
  111. return 1;
  112. }
  113. else if(!strcmp(tmp, "My", true)) return SendFormatMessage(playerid, "! יש לך כעת: %d מוקשים", PlayerInfo[playerid][Mines]);
  114. else SendClientMessage(playerid, -1, "/Bomb [Buy | Use | My] :השתמש כך");
  115. return 1;
  116. }
  117. return 0;
  118. }
  119.  
  120. public OnPlayerUpdate(playerid)
  121. {
  122. GetPlayerPos(playerid, Position[0], Position[1], Position[2]);
  123. for(new i = 0; i < GetMaxPlayers(); i++)
  124. {
  125. if(IsPlayerInRangeOfPoint(playerid, 2.5, PlayerInfo[i][Pos][0], PlayerInfo[i][Pos][1], PlayerInfo[i][Pos][2]) && PlayerInfo[i][IsReady] == true)
  126. {
  127. CreateExplosion(Position[0], Position[1], Position[2], 7, 10);
  128. DestroyObject(PlayerInfo2[i][Mine2]);
  129. Delete3DTextLabel(PlayerInfo[i][Mine]);
  130. PlayerInfo[i][Plant] = false;
  131. PlayerInfo[i][Pos][0] = 0;
  132. PlayerInfo[i][Pos][1] = 0;
  133. PlayerInfo[i][Pos][2] = 0;
  134. PlayerInfo[i][Mines] --;
  135. PlayerInfo[i][IsReady] = false;
  136. }
  137. }
  138. return 1;
  139. }
  140.  
  141. forward CountDownMine(playerid, Sec);
  142. public CountDownMine(playerid, Sec)
  143. {
  144. if(Sec == 0)
  145. {
  146. GameTextForPlayer(playerid, "The Bomb Is Ready", 3000, 3);
  147. PlayerPlaySound(playerid, 1057, 0.0, 0.0, 0.0);
  148. PlayerInfo[playerid][IsReady] = true;
  149. return 1;
  150. }
  151. format(String, sizeof(String), "~g~%d", Sec);
  152. GameTextForPlayer(playerid, String, 1000, 4);
  153. PlayerPlaySound(playerid, 1058, 0.0, 0.0, 0.0);
  154. SetTimerEx("CountDownMine", 1000, false, "%d", playerid, Sec-1);
  155. return 1;
  156. }
  157.  
  158. stock strtok(const Str[], &index)
  159. {
  160. new length = strlen(Str);
  161. while ((index < length) && (Str[index] <= ' '))
  162. {
  163. index++;
  164. }
  165. new offset = index;
  166. new result[20];
  167. while ((index < length) && (Str[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  168. {
  169. result[index - offset] = Str[index];
  170. index++;
  171. }
  172. result[index - offset] = EOS;
  173. return result;
  174. }
  175.  
  176. stock GetNum(num)
  177. {
  178. new string[64];
  179. format(string, sizeof(string), "%d", num);
  180. for(new idx = strlen(string) % 3 == 0 ? 3 : strlen(string) % 3; idx < strlen(string); idx += 4) strins(string, ",", idx);
  181. return string;
  182. }
  183.  
  184. stock MFile(playerid)
  185. {
  186. new File[MAX_PLAYER_NAME+1], PName[MAX_PLAYER_NAME+1];
  187. GetPlayerName(playerid, PName, sizeof(PName));
  188. format(File, sizeof(File), "Bomb/%s.ini", PName);
  189. return File;
  190. }
  191.  
  192. //------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement