Guest User

Untitled

a guest
Apr 18th, 2011
425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 6.57 KB | None | 0 0
  1.  
  2. /*
  3. *
  4.     *
  5.         adm_Bomb 2.0 (Author: Admantis)
  6.         *
  7.             * Features
  8.                 - Easy to configure system.
  9.                 - Can set the bomb shop coordenates
  10.                 - Can set the bomb cost
  11.                 - After a time the bomb will explode (can set too)
  12.                 - Can set realistic features (beep, object on ground)
  13.  
  14.             * Commands
  15.                 - /buybomb
  16.                 - /givebomb
  17.                 - /plantbomb
  18.  
  19.             * Disclaimer
  20.                 - Credits are not needed, just don't claim it as yours
  21.                 - You may not re-release this or sell it
  22.  
  23.             * Notes
  24.                 - Please report any bugs to Admantis via SA:MP forums PM
  25.                 - I'm not responsible of how this could harm your server
  26.                 - You need the command processor 'zcmd' to use this
  27.                 - Slow computers may lag at the bomb explosion
  28.             *
  29.         *
  30.     *
  31. *
  32. */
  33.  
  34. #include    a_samp
  35. #include    zcmd
  36. #include    sscanf2
  37.  
  38. #define     ShopX         0.000   // Change me, I'm the X place of bomb shop!
  39. #define     ShopY         0.000   // Change me, I'm the Y place of bomb shop!
  40. #define     ShopZ         0.000   // Change me, I'm the Z place of bomb shop!
  41. #define     ShopV         0       // Change me, I'm the virtual world of bomb shop!
  42. #define     Cost          25000   // Change me, I'm the cost of the bomb!
  43. #define     BombTimer     30      // Change me, I'm in how many seconds will the bomb blow up!
  44. #define     Realism       1       // Change me, I'm the one who toggles realism options! (0=false/1=true)
  45. #define     Explosions    5       // Change me, I'm how many explosions will happen when bombs blow!
  46.  
  47. /*
  48.     TBA: More realism and features options.
  49.     Realism includes;
  50.         * Beep sound when you are close to the bomb.
  51.         * Bomb object.
  52.     It's up to you to use it!
  53. */
  54.  
  55. new iPlanter;
  56. new Timer;
  57. new Float:fBombX;
  58. new Float:fBombY;
  59. new Float:fBombZ;
  60.  
  61. forward Explode();
  62. forward Beep();
  63. forward ResetPlant(playerid);
  64.  
  65.  
  66. public OnPlayerConnect(playerid)
  67. {
  68.     SetPVarInt(playerid, "Bomb", 0);
  69.     SetPVarInt(playerid, "Plant", 0);
  70.     return 1;
  71. }
  72.  
  73. public OnPlayerDisconnect(playerid, reason)
  74. {
  75.     SetPVarInt(playerid, "Bomb", 0);
  76.     SetPVarInt(playerid, "Plant", 0);
  77.     if (iPlanter == playerid) iPlanter = 0;
  78.     return 1;
  79. }
  80.  
  81. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  82. {
  83.     if (dialogid == 1)
  84.     {
  85.         if (response)
  86.         {
  87.             SetPVarInt(playerid, "Bomb", 1);
  88.             GivePlayerMoney(playerid, -Cost);
  89.             ShowPlayerDialog(playerid, 0, 0, "{CC0000}Success", "{FFFFFF}You have bought a bomb", "Close", "");
  90.             return 1;
  91.         }
  92.     }
  93.     return 1;
  94. }
  95.  
  96. public ResetPlant(playerid)
  97. {
  98.     return SetPVarInt(playerid, "Plant", 0);
  99. }
  100.  
  101. public Beep()
  102. {
  103.     for(new I = 0; I < MAX_PLAYERS; I++)
  104.     {
  105.         if (IsPlayerInRangeOfPoint(I, 15.0, fBombX, fBombY, fBombZ))
  106.         {
  107.             PlayerPlaySound(I, 1056, 0.0, 0.0, 0.0);
  108.         }
  109.     }
  110.     return 1;
  111. }
  112.  
  113. public Explode()
  114. {
  115.     new Bombs;
  116.     do
  117.     {
  118.         Bombs += 1;
  119.         CreateExplosion(fBombX, fBombY, fBombZ, 2, 20);
  120.     }
  121.     while (Bombs != Explosions);
  122.     SendClientMessage(iPlanter, -1, "{FFFFFF}Your bomb has {CC0000}exploded sucessfully");
  123.     #if Realism == 1
  124.     {
  125.         KillTimer(Timer);
  126.     }
  127.     #endif
  128.     return 1;
  129. }
  130.    
  131. stock IsAtBombShop(playerid)
  132. {
  133.     if (IsPlayerInRangeOfPoint(playerid, 3, ShopX, ShopY, ShopZ)
  134.     && (GetPlayerVirtualWorld(playerid) == ShopV)) return 1;
  135.     return 0;
  136. }
  137.  
  138. stock CanAffordBomb(playerid)
  139. {
  140.     if (GetPlayerMoney(playerid) > Cost) return 1;
  141.     return 0;
  142. }
  143.  
  144. stock RecentlyPlanted(playerid)
  145. {
  146.     if (GetPVarInt(playerid, "Plant") == 1) return 1;
  147.     return 0;
  148. }
  149.  
  150. CMD:buybomb(playerid, params[])
  151. {
  152.     new szString[124];
  153.     format(szString, 124, "{FFFFFF}Are you sure you want to buy a bomb for {00CC00}%d$?", Cost);
  154.     if (!IsAtBombShop(playerid))
  155.     {
  156.         SendClientMessage(playerid, -1, "{CC0000}Error: {FFFFFF}You are not at the {CC0000}bomb shop");
  157.         return 1;
  158.     }
  159.     if (!CanAffordBomb(playerid))
  160.     {
  161.         SendClientMessage(playerid, -1, "{CC0000}Error: {FFFFFF}You can't afford this {CC0000}bomb");
  162.         return 1;
  163.     }
  164.     if (GetPVarInt(playerid, "Bomb") == 1)
  165.     {
  166.         SendClientMessage(playerid, -1, "{CC0000}Error: {FFFFFF}You already have a {CC0000}bomb");
  167.         return 1;
  168.     }
  169.     return ShowPlayerDialog(playerid, 1, 0, "{CC0000}Confirmation", szString, "Yes", "No");
  170. }
  171.  
  172. CMD:givebomb(playerid, params[])
  173. {
  174.     new szString[124], szDestName[24], szpName[24], iDest, Float:fDestX, Float:fDestY, Float:fDestZ;
  175.     if (sscanf(params, "u", iDest))
  176.     {
  177.         SendClientMessage(playerid, -1, "{CC0000}Usage:{FFFFFF} /givebomb [playerid/PartOfName]");
  178.         return 1;
  179.     }
  180.     GetPlayerPos(iDest, fDestX, fDestY, fDestZ);
  181.     if (!IsPlayerInRangeOfPoint(playerid, 3, fDestX, fDestY, fDestZ))
  182.     {
  183.         SendClientMessage(playerid, -1, "{CC0000}Error: {FFFFFF}You are not {CC0000}near the player!");
  184.         return 1;
  185.     }
  186.     if (GetPVarInt(iDest, "Bomb") == 1)
  187.     {
  188.         SendClientMessage(playerid, -1, "{CC0000}Error: {FFFFFF}This player already has {CC0000}a bomb!");
  189.         return 1;
  190.     }
  191.     if (iDest == INVALID_PLAYER_ID)
  192.     {
  193.         SendClientMessage(playerid, -1, "{CC0000}Error: {FFFFFF}This player is {CC0000}not online!");
  194.         return 1;
  195.     }
  196.     GetPlayerName(iDest, szDestName, 24);
  197.     GetPlayerName(playerid, szpName, 24);
  198.     format(szString, 124, "{FFFFFF}You've given a bomb to {CC0000}%s(%d)", szDestName, iDest);
  199.     SendClientMessage(playerid, -1, szString);
  200.     format(szString, 124, "{FFFFFF}You've recived a bomb from {CC0000}%s(%d)", szpName, playerid);
  201.     SendClientMessage(iDest, -1, szString);
  202.     SetPVarInt(playerid, "Bomb", 0);
  203.     SetPVarInt(iDest, "Bomb", 1);
  204.     return 1;
  205. }
  206.  
  207. CMD:plantbomb(playerid, params[])
  208. {
  209.     if (GetPVarInt(playerid, "Bomb") == 0)
  210.     {
  211.         SendClientMessage(playerid, -1, "{CC0000}Error: {FFFFFF}You do not have a {CC0000}bomb!");
  212.         return 1;
  213.     }
  214.     if (GetPVarInt(playerid, "Plant") == 1)
  215.     {
  216.         SendClientMessage(playerid, -1, "{CC0000}Error: {FFFFFF}You need to wait before {CC0000}planting again!");
  217.         return 1;
  218.     }
  219.     new Float:fpX, Float:fpY, Float:fpZ, szString[124];
  220.     GetPlayerPos(playerid, fpX, fpY, fpZ);
  221.     fBombX = fpX;
  222.     fBombY = fpY;
  223.     fBombZ = fpZ-1.5;
  224.     SetTimer("Explode", BombTimer * 1000, 0);
  225.     SetTimerEx("ResetPlant", 20 * 60 * 1000, false, "i", playerid);
  226.     SetPVarInt(playerid, "Bomb", 0);
  227.     SetPVarInt(playerid, "Plant", 1);
  228.     ApplyAnimation(playerid, "BOMBER", "BOM_Plant", 4.0, 0, 0, 0, 0, 0); // Place Bomb
  229.     iPlanter = playerid;
  230.     format(szString, 124, "{FFFFFF}You have planted a bomb in your location and it will explode in {CC0000}%d seconds", BombTimer);
  231.     SendClientMessage(playerid, -1, szString);
  232.     #if Realism == 1
  233.     {
  234.         CreateObject(1252, fpX, fpY, fpZ-1.4, 0, 0, 0); // 'fpZ-1.4' may be inaccurate. Be aware.
  235.         Timer = SetTimer("Beep", 4000, 1);
  236.     }
  237.     #endif
  238.     return 1;
  239. }
Advertisement
Add Comment
Please, Sign In to add comment