Advertisement
Guest User

Mauzen

a guest
Aug 29th, 2009
1,117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.28 KB | None | 0 0
  1. #include <a_samp>
  2. #include <a_sampmysql>
  3.  
  4. #define COLOR_RED 0xAA3333AA
  5. #define COLOR_YELLOW 0xFFFF00AA
  6.  
  7. #define MYSQL_ADDRESS "localhost" //Adjust these values to your server
  8. #define MYSQL_NAME "root"
  9. #define MYSQL_PW "abc123"
  10. #define MYSQL_DBNAME "samp"
  11. #define MAX_BOMBS 12
  12.  
  13. #define KEY_DROP_BOMB KEY_HANDBRAKE
  14. #define KEY_NEXT_BOMBTYPE KEY_ANALOG_DOWN
  15. #define KEY_PREV_BOMBTYPE KEY_ANALOG_UP
  16.  
  17. #define FILTERSCRIPT
  18.  
  19. forward GetKeyPressed(code, key);
  20. forward Float:floatrandom(Float:max);
  21. forward Float:GetPlayerDistanceToPoint(playerid, Float:x, Float:y, Float:z);
  22. forward Float:GetGroundZ(Float:x, Float:y);
  23. forward GetVehicleStatID(modelid);
  24. forward DropBomb(playerid);
  25. forward BombTimer(playerid, num);
  26. forward DetonateBomb(playerid, num);
  27. forward CreateSpecialExplosion(num, playerid);
  28. forward ReactivateBomb(playerid, bombnum);
  29. //forward Poison(playerid, Float:dmg); //reactivate for poison gas
  30.  
  31.  
  32. // Free changeable stuff -------------
  33.  
  34. //Names of the bombtypes
  35. new gBombTypes[7][32] = {
  36. "Nothing",
  37. "Normal bomb",
  38. "Fire bomb",
  39. "Big bomb",
  40. "High-precision bomb",
  41. "Posion gas bomb",
  42. "Heavy bomb"
  43. };
  44.  
  45. //{Explosion ID, Radius, Accuracy (Height / this value = max x,y tolerance), bomb model id, bomb model rotation, delay (ms) from touching ground to detonating, minimum time (ms) between drops}
  46. new Float:gBombID[7][7] = {
  47. {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
  48. {11.0, 2.0, 7.0, 1636.0, 270.0, 0.0, 125.0},
  49. {1.0, 4.0, 8.5, 1636.0, 270.0, 0.0, 180.0},
  50. {7.0, 4.5, 10.0, 354.0, 270.0, 0.0, 750.0},
  51. {6.0, 2.0, 25.0, 1636.0, 270.0, 0.0, 1000.0},
  52. {-1.0, 4.5, 10.0, 2780.0, 0.0, 20000.0, 3000.0}, //Explosion ID -1 is used for special explosions
  53. {-1.0, 5.0, 15.0, 345.0, 270.0, 0.0, 10000.0} //for more info look at CreateSpecialExplosion
  54. };
  55.  
  56. //[Vehicle model ID, bombtype 1 allowed, bombtype 2 allowed, ..., bombtype n allowed}
  57. //needs to be expanded, when more bombtypes are available
  58. new gVehicleBombs[16][8] = {
  59. {476, 1, 1, 1, 0, 0, 0, 0}, //Rustler
  60. {593, 1, 0, 1, 0, 0, 0, 0}, //Dodo
  61. {553, 1, 1, 1, 0, 1, 0, 1}, //Nevada
  62. {513, 1, 0, 1, 0, 0, 0, 0}, //Stuntplane
  63. {512, 1, 0, 1, 0, 0, 0, 0}, //Cropdust
  64. {577, 1, 1, 1, 1, 1, 0, 1}, //At-400
  65. {511, 1, 1, 1, 0, 0, 0, 0}, //Beagle
  66. {460, 1, 0, 1, 0, 0, 0, 0}, //Skimmer
  67. {519, 1, 1, 1, 1, 1, 0, 0}, //Shamal
  68. {548, 1, 1, 1, 0, 0, 0, 1}, //Cargobob
  69. {417, 1, 1, 1, 0, 1, 0, 0}, //Leviathan
  70. {487, 1, 1, 1, 0, 0, 0, 0}, //Maverick
  71. {497, 1, 1, 1, 0, 0, 0, 0}, //Police Maverick
  72. {563, 1, 1, 1, 0, 1, 0, 0}, //Raindance
  73. {447, 1, 0, 1, 0, 0, 0, 0}, //Seasparrow
  74. {469, 1, 0, 1, 0, 0, 0, 0} //Sparrow
  75. };
  76.  
  77. new Float:gBombSpeed = 20.0; //Bomb-falling speed
  78. // ----------------------------------
  79. // Global variables ---------------
  80. new bombid[MAX_PLAYERS][MAX_BOMBS]; //Used for different stuff
  81. new bombtime[MAX_PLAYERS][MAX_BOMBS];
  82. new bombcount[MAX_PLAYERS];
  83. new bombarmed[MAX_PLAYERS][MAX_BOMBS];
  84. new Float:targetz[MAX_PLAYERS][MAX_BOMBS];
  85. new boti[MAX_PLAYERS][MAX_BOMBS];
  86. new bfree[MAX_PLAYERS][sizeof gBombTypes];
  87. new btype[MAX_PLAYERS][MAX_BOMBS];
  88. new bptype[MAX_PLAYERS] = 0;
  89. new vmid[MAX_PLAYERS] = -1;
  90.  
  91. /*new poisoned[MAX_PLAYERS]; //For poison gas - reactivate if needed
  92. new poisontimer[MAX_PLAYERS];
  93. new poisonpl[MAX_PLAYERS];*/
  94. // ----------------------------------
  95.  
  96. #if defined FILTERSCRIPT
  97.  
  98. public OnFilterScriptInit()
  99. {
  100. print("\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
  101. print("X Bombing filterscript V0.92 X");
  102. print("X created by Mauzen 7/2008,2009 X");
  103. print("XxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxX");
  104. if(!(samp_mysql_connect(MYSQL_ADDRESS, MYSQL_NAME, MYSQL_PW) == 1) || !(samp_mysql_select_db(MYSQL_DBNAME) == 1)) {
  105. print("Database Error!");
  106. }
  107. print("XxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxX\n");
  108.  
  109.  
  110. return 1;
  111. }
  112.  
  113. public OnFilterScriptExit()
  114. {
  115. samp_mysql_close();
  116. return 1;
  117. }
  118. #endif
  119.  
  120.  
  121. public OnPlayerSpawn(playerid)
  122. {
  123. ApplyAnimation(playerid, "CARRY", "crry_prtial", 4.0, 0, 0, 0, 0, 0);
  124. return 1;
  125. }
  126.  
  127. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  128. {
  129. vmid[playerid] = GetVehicleStatID(GetVehicleModel(vehicleid));
  130. if(vmid[playerid] > -1) {
  131. bptype[playerid] = 0;
  132. }
  133. return 1;
  134. }
  135.  
  136. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  137. {
  138. if(IsPlayerInAnyVehicle(playerid) && (vmid[playerid] > -1)) {
  139. new old[MAX_PLAYERS];
  140. if(GetKeyPressed(newkeys, KEY_NEXT_BOMBTYPE)) {
  141. old[playerid] = bptype[playerid];
  142. bptype[playerid] ++;
  143. if(bptype[playerid] >= sizeof gBombTypes) {
  144. bptype[playerid] = old[playerid];
  145. }
  146. while(gVehicleBombs[vmid[playerid]][bptype[playerid] + 1] <= 0) {
  147. bptype[playerid] ++;
  148. if(bptype[playerid] >= sizeof gBombTypes) {
  149. bptype[playerid] = old[playerid];
  150. return 1;
  151. }
  152. }
  153. new str[64];
  154. format(str, 64, "You have selected %s", gBombTypes[bptype[playerid]]);
  155. SendClientMessage(playerid, COLOR_YELLOW, str);
  156. }
  157. if(GetKeyPressed(newkeys, KEY_PREV_BOMBTYPE)) {
  158. old[playerid] = bptype[playerid];
  159. bptype[playerid] --;
  160. if(bptype[playerid] < 0) {
  161. bptype[playerid] = old[playerid];
  162. }
  163. while(gVehicleBombs[vmid[playerid]][bptype[playerid] + 1] <= 0) {
  164. bptype[playerid] --;
  165. if(bptype[playerid] < 0) {
  166. bptype[playerid] = old[playerid];
  167. return 1;
  168. }
  169. }
  170. new str[64];
  171. format(str, 64, "You have selected %s", gBombTypes[bptype[playerid]]);
  172. SendClientMessage(playerid, COLOR_YELLOW, str);
  173. }
  174. if(GetKeyPressed(newkeys, KEY_DROP_BOMB)) {
  175. DropBomb(playerid);
  176. }
  177. }
  178. return 1;
  179. }
  180.  
  181. // -----------------------------------------------------------------------------
  182.  
  183. //useful stuff
  184.  
  185. public GetKeyPressed(code, key) {
  186. for(new i = 65536; i > 0; i = i / 2) {
  187. if(code >= i) {
  188. code = code - i;
  189. if(i == key) return 1;
  190. }
  191. }
  192. return 0;
  193. }
  194.  
  195. public Float:floatrandom(Float:max) {
  196. new Float:rand;
  197. max = max * 100000;
  198. rand = floatdiv(float(random(floatround(max))), 100000.0);
  199. return rand;
  200. }
  201.  
  202. public Float:GetPlayerDistanceToPoint(playerid, Float:x, Float:y, Float:z) {
  203. new Float:px;
  204. new Float:py;
  205. new Float:pz;
  206. GetPlayerPos(playerid, px, py, pz);
  207. return floatsqroot( floatadd( floatadd( floatpower(floatsub(x, px), 2), floatpower(floatsub(y, py), 2) ), floatpower(floatsub(z, pz), 2) ) );
  208. }
  209.  
  210. public Float:GetGroundZ(Float:x, Float:y) {
  211. new rxy[96];
  212. x = 5.0 * floatround(x / 5.0); //Replace all 5.0 by the MySQL "map resolution"
  213. y = 5.0 * floatround(y / 5.0); //Replace all 5.0 by the MySQL "map resolution"
  214. format(rxy, 96, "SELECT z FROM hmap WHERE x = %d AND y = %d;", floatround(x), floatround(y));
  215. samp_mysql_query(rxy);
  216. samp_mysql_store_result();
  217. samp_mysql_fetch_row(rxy);
  218. return floatstr(rxy);
  219. }
  220.  
  221. public GetVehicleStatID(modelid) {
  222. for(new i = 0; i < sizeof gVehicleBombs; i ++) {
  223. if(gVehicleBombs[i][0] == modelid) {
  224. return i;
  225. }
  226. }
  227. return -1;
  228. }
  229.  
  230. // -----------------------------------------------------------------------------
  231.  
  232. public DropBomb(playerid) {
  233. if(bptype[playerid] != 0) {
  234. if(bfree[playerid][bptype[playerid]] == 0) {
  235. if(bombcount[playerid] < MAX_BOMBS) {
  236. bfree[playerid][bptype[playerid]] = 1;
  237. bombcount[playerid] ++;
  238. new Float:x;
  239. new Float:y;
  240. new Float:z;
  241. new sel;
  242. for(new i = 0; i < MAX_BOMBS; i++) {
  243. if(bombid[playerid][i] <= 0) {
  244. sel = i;
  245. bombid[playerid][i] = 1;
  246. break;
  247. }
  248. }
  249. btype[playerid][sel] = bptype[playerid];
  250. GetVehiclePos(GetPlayerVehicleID(playerid), x, y, z);
  251. new Float:tolerancex = floatsub( floatrandom( floatdiv(z, gBombID[btype[playerid][sel]][2]) ), floatdiv(floatdiv(z, gBombID[btype[playerid][sel]][2]), 2.0));
  252. new Float:tolerancey = floatsub( floatrandom( floatdiv(z, gBombID[btype[playerid][sel]][2]) ), floatdiv(floatdiv(z, gBombID[btype[playerid][sel]][2]), 2.0));
  253. targetz[playerid][sel] = GetGroundZ(x + tolerancex, y + tolerancey);
  254. if(targetz[playerid][sel] == 0.0) {
  255. SendClientMessage(playerid, COLOR_RED, "Warning! The bomb detonator is damaged. Bomb will be activated on default water level.");
  256. }
  257. bombid[playerid][sel] = CreateObject(floatround(gBombID[btype[playerid][sel]][3]), x, y, z - 1, gBombID[btype[playerid][sel]][4], 0, 0);
  258. MoveObject(bombid[playerid][sel], x + tolerancex, y + tolerancey, targetz[playerid][sel] - 1, gBombSpeed);
  259. boti[playerid][sel] = 0;
  260. bombarmed[playerid][sel] = 0;
  261. bombtime[playerid][sel] = SetTimerEx("BombTimer", 100, 1, "ii", playerid, sel);
  262. SetTimerEx("ReactivateBomb", floatround(gBombID[bptype[playerid]][6]), 0, "ii", playerid, bptype[playerid]);
  263. } else {
  264. SendClientMessage(playerid, COLOR_RED, "Too many falling bombs, cannot drop more at once!");
  265. }
  266. } else {
  267. SendClientMessage(playerid, COLOR_RED, "The bomb need to be prepared! Wait a moment...");
  268. }
  269. } else {
  270. }
  271. }
  272.  
  273. public BombTimer(playerid, num) {
  274. new Float:x;
  275. new Float:y;
  276. new Float:z;
  277. GetObjectPos(bombid[playerid][num], x, y, z);
  278. boti[playerid][num] ++;
  279. if(bombarmed[playerid][num]) {
  280. // If you want to add a posion effect to your bomb you need to add a check like this
  281. /*if(btype[playerid][num] == 6) { //Poison gas - reactivcate this, if you want to
  282. for(new i = 0; i < MAX_PLAYERS; i ++) { //look for players near the bomb
  283. if((GetPlayerDistanceToPoint(i, x, y, z) <= gBombID[btype[playerid][num]][1])) {
  284. if(poisoned[i] == 0) {
  285. poisonpl[i] = playerid; //used for kill-detection, not important yet
  286. poisoned[i] = 50; //set the "poison level" of the player
  287. ApplyAnimation(i, "PED", "WALK_DRUNK", 4.1, 1, 1, 1, 1, 1); //if you want to, let him look poisoned ;)
  288. KillTimer(poisontimer[i]);
  289. poisontimer[i] = SetTimerEx("Poison", 200, 1, "if", i, 0.7);
  290. //each time the timer gets called (here 200ms) player 'i' (player next to the bomb) gets '0.7' damage
  291. //and his poison level is decreased by 1 until it reaches 0 again
  292. } else {
  293. poisoned[i] = 50; //if he stays within the poison radius, his poison level does not decrease
  294. }
  295. break;
  296. }
  297. }
  298. }*/
  299. }
  300. if((floatsub(z, targetz[playerid][num] - 1) < 0.1) && !bombarmed[playerid][num]) { //bomb reached ground
  301. if(gBombID[btype[playerid][num]][5] > 0.0) {
  302. SetTimerEx("DetonateBomb", floatround(gBombID[btype[playerid][num]][5]), 0, "ii", playerid, num);
  303. bombarmed[playerid][num] = 1;
  304. } else {
  305. DetonateBomb(playerid, num);
  306. }
  307. }
  308. }
  309.  
  310. public DetonateBomb(playerid, num) {
  311. new Float:x;
  312. new Float:y;
  313. new Float:z;
  314. GetObjectPos(bombid[playerid][num], x, y, z);
  315. KillTimer(bombtime[playerid][num]);
  316. if(floatround(gBombID[btype[playerid][num]][0]) != -1.0) {
  317. CreateExplosion(x, y, z, floatround(gBombID[btype[playerid][num]][0]), gBombID[btype[playerid][num]][1]);
  318. } else {
  319. CreateSpecialExplosion(num, playerid);
  320. }
  321. DestroyObject(bombid[playerid][num]);
  322. bombid[playerid][num] = -1;
  323. bombcount[playerid] --;
  324. }
  325.  
  326. public CreateSpecialExplosion(num, playerid) { //Every explosion wit explosion ID -1 is created here
  327. new Float:x; //You may add a check for your own bombs like the one already existing
  328. new Float:y;
  329. new Float:z;
  330. GetObjectPos(bombid[playerid][num], x, y, z);
  331. if(btype[playerid][num] == 6) { //btype[playerid][num] is the index of the bomb exploding
  332. CreateExplosion(x, y, z, 7, 4.0); //x, y and z are the coordinates of the bomb
  333. CreateExplosion(x, y, z + 5.0, 1, 4.0);
  334. CreateExplosion(x, y, z + 9.0, 1, 3.0);
  335. CreateExplosion(x, y, z + 12.5, 1, 3.0);
  336. CreateExplosion(x + 4.0, y, z, 0, 2.0);
  337. CreateExplosion(x - 4.0, y, z, 0, 2.0);
  338. CreateExplosion(x, y + 4.0, z, 0, 2.0);
  339. CreateExplosion(x, y - 4.0, z, 0, 2.0);
  340. CreateExplosion(x, y - 7.0, z, 1, 3.0);
  341. CreateExplosion(x, y + 7.0, z, 1, 3.0);
  342. CreateExplosion(x + 7.0, y, z, 1, 3.0);
  343. CreateExplosion(x - 7.0, y, z, 1, 3.0);
  344. CreateExplosion(x + 4.0, y + 4.0, z, 1, 4.0);
  345. CreateExplosion(x - 4.0, y - 4.0, z, 1, 4.0);
  346. CreateExplosion(x - 4.0, y + 4.0, z, 1, 4.0);
  347. CreateExplosion(x + 4.0, y - 4.0, z, 1, 4.0);
  348. }
  349. //To add an own explosion create a new check like this:
  350. /*if(btype[playerid][num] == YOUR_BOMB_INDEX) {
  351. ...your explosion...
  352. }*/
  353. }
  354.  
  355. public ReactivateBomb(playerid, bombnum) {
  356. bfree[playerid][bombnum] = 0;
  357. }
  358.  
  359. /*public Poison(playerid, Float:dmg) { //Reactivate for Poison gas bomb
  360. new Float:hp;
  361. GetPlayerHealth(playerid, hp);
  362. if(hp <= 0.0) poisoned[playerid] = -1;
  363. SetPlayerHealth(playerid, hp - dmg);
  364. poisoned[playerid] --;
  365. ApplyAnimation(playerid, "PED", "WALK_DRUNK", 4.1, 1, 1, 1, 1, 1);
  366. if(poisoned[playerid] <= 0) {
  367. KillTimer(poisontimer[playerid]);
  368. ApplyAnimation(playerid, "CARRY", "crry_prtial", 4.0, 0, 0, 0, 0, 0);
  369. }
  370. }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement