Advertisement
Guest User

Untitled

a guest
Feb 20th, 2011
1,875
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 15.56 KB | None | 0 0
  1. #include <a_samp>
  2.  
  3. #define MAX         MAX_PLAYERS
  4. #define PRESSED(%0) (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
  5. #define Weapons_Dialog   9457
  6.  
  7.  
  8. //Edit here as you wish!
  9. #define Reward_Cash 15000
  10. #define Reward_Score 50
  11. enum E_OBJECTS
  12. {
  13.     Float:pObjectX[ MAX_PLAYERS],
  14.     Float:pObjectY[ MAX_PLAYERS],
  15.     Float:pObjectZ[ MAX_PLAYERS]
  16. };
  17.  
  18. new Float:Random_Object_Speed[18] =
  19. {
  20.     0.8, 0.9, 1.0,
  21.     1.1, 1.2, 1.3,
  22.     1.4, 1.5, 1.6,
  23.     1.6, 1.8, 2.0,
  24.     2.2, 2.3, 2.5,
  25.     2.1, 2.5, 2.0
  26. },
  27.     RangePickup[ 7 ],
  28.     Objects_Count[ MAX ] = 0,
  29.     AimObject[ 50 ][ E_OBJECTS ],
  30.     Shooting[ MAX ],
  31.     PlayerObjects[ MAX ],
  32.     Objects_Hit2[ MAX ],
  33.     Objects_Missed[ MAX ],
  34.     A_Objects[ 50 ][ MAX ],
  35.     Float:OnArrow[ 3 ][ MAX ],
  36.    
  37.    
  38. Float:
  39.         Pickup_Pos[ 7 ][ 3 ] =
  40. {
  41.     {809.2676,1668.9481,5.2813},
  42.     {806.3400,1668.8962,5.2813},
  43.     {803.0370,1668.8966,5.2813},
  44.     {800.2703,1668.8964,5.2813},
  45.     {797.1923,1668.8964,5.2813},
  46.     {794.1580,1668.8971,5.2875},
  47.     {795.9923,1681.0208,5.2813}
  48.  
  49. };
  50. //------------------------------------------------
  51.  
  52. public OnPlayerConnect( playerid )
  53. {
  54.     SendClientMessage( playerid, 0xFFBF00FF, "Shooting Range:{FFFFFF} Have some fun at the shooting range! Type {FFBF00}/range");
  55.    
  56.     return 1;
  57. }
  58.  
  59. public OnPlayerDisconnect( playerid, reason )
  60. {
  61.     if ( Shooting[ playerid ] )FinishShootingRange( playerid );
  62.        
  63.  
  64.     return 1;
  65. }
  66. public OnFilterScriptInit()
  67. {
  68.     print("\n\t\t\t\16-Shooting Range by Zh3r0-\17\n\t\t\t\t   Loaded\n");
  69.    
  70.     for ( new p = 0; p < MAX_OBJECTS; p ++ )
  71.     {
  72.         for ( new x = 0; x < MAX_PLAYERS; x ++ )
  73.         {
  74.             if ( IsPlayerConnected( x ) )
  75.             {
  76.                 DestroyPlayerObject( x, p );
  77.             }
  78.         }
  79.     }
  80.    
  81.     for ( new p = 0; p < sizeof( Pickup_Pos )-1; p ++ )
  82.     {
  83.         RangePickup[ p ]  = CreatePickup( 1318, 2, Pickup_Pos[ p ][ 0 ], Pickup_Pos[ p ][ 1 ], Pickup_Pos[ p ][ 2 ] );
  84.     }
  85.    
  86.     RangePickup[ 6 ]  = CreatePickup( 1239, 2, Pickup_Pos[ 6 ][ 0 ], Pickup_Pos[ 6 ][ 1 ], Pickup_Pos[ 6 ][ 2 ] );
  87.    
  88.     return 1;
  89. }
  90.  
  91. public OnPlayerUpdate( playerid )
  92. {
  93.     if ( Shooting [ playerid ] )
  94.     {
  95.         if ( !PlayerToPoint( 1.4,  playerid, OnArrow[ 0 ][ playerid ], OnArrow[ 1 ][ playerid ], OnArrow[ 2 ][ playerid ] ) )
  96.         {
  97.             FinishShootingRange( playerid );
  98.             SendClientMessage( playerid, 0xFFBF00FF, "Shooting Range: {FFFFFF}You left the shooting range!");
  99.         }
  100.    
  101.     }
  102.     return 1;
  103. }
  104.  
  105. public OnPlayerDeath( playerid, killerid, reason )
  106. {
  107.     if ( Shooting[ playerid ] )
  108.     {
  109.         SendClientMessage( playerid, 0xFFBF00FF, "Shooting Range: {FFFFFF}You died while in the Shooting Range. Quit!");
  110.         FinishShootingRange( playerid );
  111.     }
  112.     return 1;
  113. }
  114. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  115. {
  116.     if (PRESSED(KEY_FIRE))
  117.     {
  118.         if ( Shooting[ playerid ] )
  119.         {
  120.             for(new i = 0; i <MAX_OBJECTS; i++)
  121.             {
  122.                 if(IsValidPlayerObject( playerid, A_Objects[ i ][ playerid ] ) )
  123.                 {
  124.                     new Float:oPos[ 3 ];
  125.                     GetPlayerObjectPos( playerid, A_Objects[ i ][ playerid ], oPos[ 0 ], oPos[ 1 ], oPos[ 2 ] );
  126.                     if ( IsPlayerAiming ( playerid, oPos[ 0 ], oPos[ 1 ], oPos[ 2 ], 0.2 ) )
  127.                     {
  128.                         if ( GetPlayerWeapon( playerid ) == 31 ||
  129.                              GetPlayerWeapon( playerid ) == 33 ||
  130.                              GetPlayerWeapon( playerid ) == 34 ||
  131.                              GetPlayerWeapon( playerid ) == 30)
  132.                         {
  133.                             if ( PlayerObjects[ playerid ] > 0 )
  134.                             {
  135.                                 DestroyPlayerObject( playerid, A_Objects[ i ][ playerid ] );
  136.  
  137.                                 --PlayerObjects[ playerid ];
  138.                                 ++Objects_Hit2[ playerid ];
  139.                                
  140.                                 if ( PlayerObjects[ playerid ] == 0 && Objects_Hit2[ playerid ] != 20 )
  141.                                 {
  142.                                     Objects_Missed[ playerid ] = 20 - Objects_Hit2[ playerid ];
  143.                                     MoveObjectsForPlayerAgain( playerid );
  144.                                 }
  145.                                 else if ( Objects_Hit2[ playerid ] == 20 )
  146.                                 {
  147.                                     DestroyPlayerObject( playerid, A_Objects[ i ][ playerid ] );
  148.                                     PlayerObjects[ playerid ] --;
  149.                                     FinishShootingRange( playerid );
  150.  
  151.                                     ShowPlayerDialog( playerid, 2593, DIALOG_STYLE_MSGBOX, "{FFBF00}Shooting Range:{FFFFFF} Shooting trial finished!",\
  152.                                     "{FFBF00}[ {FFFFFF}Reward{FFBF00} ]\n\
  153.                                     {00FF00}$"#Reward_Cash"{FFFFFF} dollars\n\
  154.                                     {00FF40}+"#Reward_Score"{FFFFFF} score\n\n\
  155.                                     Go and have some more fun! Move to another shooting place!", "Close", "");
  156.                                     ResetPlayerWeapons( playerid );
  157.                                     GivePlayerMoney( playerid, Reward_Cash );
  158.                                     SetPlayerScore( playerid, GetPlayerScore( playerid ) + Reward_Score );
  159.                                 }
  160.                             }
  161.                         }
  162.                         else
  163.                         {
  164.                             SendClientMessage( playerid, 0xFFBF00FF, "Shooting Range: {FFFFFF}This weapon is not allowed! ({FFBF00}Allowed Weapons:{FFBF40} Country Rifle, Sniper, M4, Ak47{FFFFFF})");
  165.                             FinishShootingRange( playerid );
  166.                             SetPlayerPos( playerid, 795.8624, 1685.6016, 5.2813 );
  167.                         }
  168.                     }
  169.                 }
  170.             }
  171.         }
  172.     }
  173.     return 1;
  174. }
  175. public OnPlayerObjectMoved(playerid,objectid)
  176. {
  177.    for ( new i = 0; i <MAX_OBJECTS; i++ )
  178.     {
  179.         if ( objectid == A_Objects[ i ][ playerid ] )
  180.         {
  181.             if ( IsValidPlayerObject( playerid, A_Objects[ i ][ playerid ] ) )
  182.             {
  183.                 DestroyPlayerObject( playerid, A_Objects[ i ][ playerid ] );
  184.                
  185.                 PlayerObjects[playerid]--;
  186.                 if ( PlayerObjects[playerid] == 0 && Objects_Hit2[playerid] != 20)
  187.                 {
  188.                     Objects_Missed[playerid] = 20 - Objects_Hit2[playerid];
  189.                     MoveObjectsForPlayerAgain( playerid );
  190.                 }
  191.             }
  192.         }
  193.     }
  194.     return 1;
  195. }
  196.  
  197. public OnPlayerPickUpPickup( playerid, pickupid )
  198. {
  199.     new p = 0;
  200.     for ( ;p < 6; ++p)
  201.     {
  202.    
  203.         if ( pickupid == RangePickup[ p ]  && !Shooting[ playerid ])
  204.         {
  205.             ShowPlayerDialog( playerid, Weapons_Dialog, DIALOG_STYLE_LIST, "{FFFFFF}Choose your weapon:", "{FFBF00}Country Rifle\n\
  206.                                                                                                            {FFBF00}Sniper\n\
  207.                                                                                                            {FFBF00}M4\n\
  208.                                                                                                            {FFBF00}AK47", "Select", "Exit" );
  209.         }
  210.     }
  211.    if ( pickupid == RangePickup[ 6 ] )
  212.     {
  213.         new Str[ 1024 ];
  214.         format( Str, 1024, "%s\n\n\
  215.                             {FFBF00}[{FFFFFF} Credits {FFBF00}]\n\
  216.                             {FFBF00}Zh3r0 \t\t{FFFFFF}- Creator\n\
  217.                             {FFBF00}DeatheR \t{FFFFFF}- Some functions(Almost all)\n\
  218.                             {FFBF00}niCe \t\t{FFFFFF}- {FFBF00}IsPlayerAimingAt{FFFFFF} function\n\nHave Fun!\n",Info());
  219.                            
  220.         ShowPlayerDialog( playerid, 2593, DIALOG_STYLE_MSGBOX, "{FFBF00}Shooting Range: {FFFFFF}Information", Str, "Close", "");
  221.     }
  222.  
  223.     return 1;
  224. }
  225.  
  226.  
  227. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  228. {
  229.     if ( dialogid == Weapons_Dialog )
  230.     {
  231.         if ( response )
  232.         {
  233.             ResetPlayerWeapons( playerid );
  234.            
  235.             switch( listitem )
  236.             {
  237.                 case 0: GivePlayerWeapon( playerid, 33, 99999 ),SendClientMessage( playerid, 0xFFBF00FF, "Shooting Range:{FFFFFF} You selected {FFBF00}Country Rifle{FFFFFF} as your weapon!");
  238.                 case 1: GivePlayerWeapon( playerid, 34, 99999 ),SendClientMessage( playerid, 0xFFBF00FF, "Shooting Range:{FFFFFF} You selected {FFBF00}Sniper{FFFFFF} as your weapon!");
  239.                 case 2: GivePlayerWeapon( playerid, 31, 99999 ),SendClientMessage( playerid, 0xFFBF00FF, "Shooting Range:{FFFFFF} You selected {FFBF00}M4{FFFFFF} as your weapon!");
  240.                 case 3: GivePlayerWeapon( playerid, 30, 99999 ),SendClientMessage( playerid, 0xFFBF00FF, "Shooting Range:{FFFFFF} You selected {FFBF00}AK47{FFFFFF} as your weapon!");
  241.             }
  242.             GetPlayerPos( playerid, OnArrow[ 0 ][ playerid ], OnArrow[ 1 ][ playerid ] ,OnArrow[ 2 ][ playerid ] );
  243.             Shooting[ playerid ] = 1;
  244.             PlayerObjects[playerid] = 20;
  245.             Objects_Hit2[ playerid ] = 0;
  246.            
  247.             LoadAimObjects( playerid );
  248.  
  249.             for(new i=0; i<=20; i++)
  250.             {
  251.                 new rand_val = random( sizeof( Random_Object_Speed ) );
  252.                 MovePlayerObject(playerid, A_Objects[i][playerid], 790.6284, AimObject[i][pObjectY][playerid], AimObject[i][pObjectZ][playerid], Random_Object_Speed[rand_val]);
  253.             }
  254.            
  255.             GameTextForPlayer( playerid, "~r~~n~~n~~n~~n~~n~~n~~n~Start shooting!", 2000, 3 );
  256.         }
  257.        
  258.  
  259.     }
  260.     return 1;
  261. }
  262. stock MoveObjectsForPlayerAgain( playerid )
  263. {
  264.    new ObjectsMiss = Objects_Missed[ playerid ];
  265.     PlayerObjects[ playerid ] = ObjectsMiss;
  266.  
  267.     for(new x = 0; x < ObjectsMiss; x++)
  268.     {
  269.         CreateAimObject( x ,playerid);
  270.     }
  271.  
  272.     for(new x = 0; x <= ObjectsMiss; x++)
  273.     {
  274.         new rand_val = random( sizeof ( Random_Object_Speed ) );
  275.         MovePlayerObject(playerid, A_Objects[ x ][ playerid ], 790.6284, AimObject[ x ][ pObjectY ][ playerid ], AimObject[ x ][ pObjectZ ][ playerid ], Random_Object_Speed[ rand_val ] );
  276.     }
  277. }
  278.  
  279. FinishShootingRange( p )
  280. {
  281.    Objects_Count[ p ] = 0;
  282.    Shooting[ p ] = 0;
  283.    Objects_Missed[ p ] = 0;
  284.    ResetPlayerWeapons( p );
  285.    for ( new i = 0; i < 30; i++)
  286.     {
  287.         DestroyPlayerObject(p, A_Objects[ i ][ p ] );
  288.     }
  289.     PlayerObjects[ p  ] = 0;
  290.    Objects_Hit2[ p ] = 0;
  291.     return 1;
  292. }
  293. LoadAimObjects( p )
  294. {
  295.     //Did it this way due to some loop mallfunction
  296.     //( Keept creating on and on when a player would join )
  297.    CreateAimObject( 0, p );
  298.     CreateAimObject( 1, p );
  299.     CreateAimObject( 2, p );
  300.     CreateAimObject( 3, p );
  301.     CreateAimObject( 4, p );
  302.     CreateAimObject( 5, p );
  303.     CreateAimObject( 6, p );
  304.     CreateAimObject( 7, p );
  305.     CreateAimObject( 8, p );
  306.     CreateAimObject( 9, p );
  307.     CreateAimObject( 10, p );
  308.     CreateAimObject( 11, p );
  309.     CreateAimObject( 12, p );
  310.     CreateAimObject( 13, p );
  311.     CreateAimObject( 14, p );
  312.     CreateAimObject( 15, p );
  313.     CreateAimObject( 16, p );
  314.     CreateAimObject( 17, p );
  315.     CreateAimObject( 18, p );
  316.     CreateAimObject( 19, p );
  317. }
  318. public OnPlayerCommandText(playerid, cmdtext[])
  319. {
  320.     if(!strcmp(cmdtext,"/test"))
  321.     {
  322.         new str[256];
  323.         format( str, 265, "PlayerObjects = %d | Objects_Hit = %d", PlayerObjects[ playerid ], Objects_Hit2[ playerid ] );
  324.         SendClientMessage( playerid, -1, str);
  325.         return 1;
  326.     }
  327.    if(!strcmp(cmdtext,"/re"))
  328.     {
  329.         if ( !Shooting[ playerid ] )
  330.             return SendClientMessage( playerid, 0xFFBF00FF, "Shooting Range: {FFFFFF}You are not shooting!");
  331.         else
  332.         FinishShootingRange( playerid );
  333.         return 1;
  334.     }
  335.    
  336.     if(!strcmp(cmdtext,"/range"))
  337.     {
  338.         ShowPlayerDialog
  339.         (
  340.             playerid,
  341.             2593,
  342.             DIALOG_STYLE_MSGBOX,
  343.             "{FFFFFF}Shooting Range",
  344.             Info(),
  345.             "Close",
  346.             ""
  347.         );
  348.         SetPlayerPos( playerid, 795.8624, 1685.6016, 5.2813 );
  349.         return 1;
  350.     }
  351.     return 1;
  352. }
  353.  
  354. Info()
  355. {
  356.     new Str[ 1024 ];
  357.     strcat2( Str, "\t\t\t\t       {FF0000}Shooting Range\n\n");
  358.     strcat2( Str, "{FFBF00}Information{FFFFFF}\n");
  359.     strcat2( Str, "- The Shooting Range was made by {FFBF00}Zh3r0{FFFFFF} on date {FFBF00}20/02/2011{FFFFFF}.\n");
  360.     strcat2( Str, "- It has {FFBF00}6{FFFFFF} pickups placed on the shooting place.\n");
  361.     strcat2( Str, "- When you enter a pickup(arrow) some random objects will appear, shoot them!\n");
  362.     strcat2( Str, "- After you finish the shooting, you will be rewarded with moneys and score!\n");
  363.     strcat2( Str, "- Use command {FFBF00}/re{FFFFFF} to exit the Shooting Field( Or simply while shooting leave the field )\n");
  364.     strcat2( Str, "- You can select with which weapon you want to shoot.( {FFBF00}Shotgun, Sniper, M4, Ak47{FFFFFF} )\n");
  365.     return Str;
  366. }
  367.  
  368. strcat2( string[], string2[] ) return strcat( string, string2, 1024 );
  369.  
  370.  
  371. PlayerToPoint(Float:radi, playerid, Float:x, Float:y, Float:z)
  372. {
  373.     new Float:oldposx, Float:oldposy, Float:oldposz;
  374.     new Float:tempposx, Float:tempposy, Float:tempposz;
  375.     GetPlayerPos(playerid, oldposx, oldposy, oldposz);
  376.     tempposx = (oldposx -x);
  377.     tempposy = (oldposy -y);
  378.     tempposz = (oldposz -z);
  379.     if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
  380.     {
  381.         return 1;
  382.     }
  383.     return 0;
  384. }
  385.  
  386. Float:getRand(Float:ll, Float:ul)
  387. {
  388.    new ulv = floatround(ul, floatround_ceil);
  389.    new llv = floatround(ll, floatround_floor);
  390.     new range = ulv-llv;
  391.     new Float:number = ll+(rand()%range);
  392.     return number;
  393. }
  394. stock rand()
  395. {
  396.     new rand_num = random(32767);
  397.     return rand_num;
  398. }
  399. stock CreateAimObject(oid,playerid)
  400. {
  401.     new Float:x = getRand(810.3989, 830.9512);
  402.     new Float:y = getRand(1618.3936,1632.4587);
  403.     new Float:z = getRand(5.4932, 10.4932);
  404.  
  405.     AimObject[oid][pObjectX][playerid] = x;
  406.     AimObject[oid][pObjectY][playerid] = y;
  407.     AimObject[oid][pObjectZ][playerid] = z;
  408.    
  409.     //DestroyPlayerObject( playerid, A_Objects[oid][playerid] );
  410.     A_Objects[oid][playerid] = CreatePlayerObject(playerid, 1600 , AimObject[oid][pObjectX][playerid], AimObject[oid][pObjectY][playerid], AimObject[oid][pObjectZ][playerid], 0.00000000,16.32929716,97.11634627);
  411.     return 1;
  412. }
  413. Float:DistanceCameraTargetToLocation(Float:CamX, Float:CamY, Float:CamZ, Float:ObjX, Float:ObjY, Float:ObjZ, Float:FrX, Float:FrY, Float:FrZ)
  414. {
  415.     new Float:TGTDistance;
  416.  
  417.     TGTDistance = floatsqroot((CamX - ObjX) * (CamX - ObjX) + (CamY - ObjY) * (CamY - ObjY) + (CamZ - ObjZ) * (CamZ - ObjZ));
  418.  
  419.     new Float:tmpX, Float:tmpY, Float:tmpZ;
  420.  
  421.     tmpX = FrX * TGTDistance + CamX;
  422.     tmpY = FrY * TGTDistance + CamY;
  423.     tmpZ = FrZ * TGTDistance + CamZ;
  424.  
  425.     return floatsqroot((tmpX - ObjX) * (tmpX - ObjX) + (tmpY - ObjY) * (tmpY - ObjY) + (tmpZ - ObjZ) * (tmpZ - ObjZ));
  426. }
  427. //===================================//
  428. stock Float:GetPointAngleToPoint(Float:x2, Float:y2, Float:X, Float:Y)
  429. {
  430.     new Float:DX, Float:DY;
  431.     new Float:angle;
  432.  
  433.     DX = floatabs(floatsub(x2,X));
  434.     DY = floatabs(floatsub(y2,Y));
  435.  
  436.     if (DY == 0.0 || DX == 0.0)
  437.     {
  438.         if(DY == 0 && DX > 0) angle = 0.0;
  439.         else if(DY == 0 && DX < 0) angle = 180.0;
  440.         else if(DY > 0 && DX == 0) angle = 90.0;
  441.         else if(DY < 0 && DX == 0) angle = 270.0;
  442.         else if(DY == 0 && DX == 0) angle = 0.0;
  443.     }
  444.     else
  445.     {
  446.         angle = atan(DX/DY);
  447.         if(X > x2 && Y <= y2) angle += 90.0;
  448.         else if(X <= x2 && Y < y2) angle = floatsub(90.0, angle);
  449.         else if(X < x2 && Y >= y2) angle -= 90.0;
  450.         else if(X >= x2 && Y > y2) angle = floatsub(270.0, angle);
  451.     }
  452.     return floatadd(angle, 90.0);
  453. }
  454. //===================================//
  455. stock GetXYInFrontOfPoint(&Float:x, &Float:y, Float:angle, Float:distance)
  456. {
  457.     x += (distance * floatsin(-angle, degrees));
  458.     y += (distance * floatcos(-angle, degrees));
  459. }
  460. //===================================//
  461. stock IsPlayerAiming(playerid, Float:x, Float:y, Float:z, Float:radius)
  462. {
  463.     new Float:camera_x,Float:camera_y,Float:camera_z,Float:vector_x,Float:vector_y,Float:vector_z;
  464.     GetPlayerCameraPos(playerid, camera_x, camera_y, camera_z);
  465.     GetPlayerCameraFrontVector(playerid, vector_x, vector_y, vector_z);
  466.  
  467.     new Float:vertical, Float:horizontal;
  468.  
  469.     switch (GetPlayerWeapon(playerid))
  470.     {
  471.         case 34,35,36:
  472.         {
  473.             if (DistanceCameraTargetToLocation(camera_x, camera_y, camera_z, x, y, z, vector_x, vector_y, vector_z) < radius) return true;
  474.             return false;
  475.         }
  476.         case 30,31:
  477.         {
  478.             vertical = 4.0;
  479.             horizontal = -1.6;
  480.         }
  481.         case 33:
  482.         {
  483.             vertical = 2.7;
  484.             horizontal = -1.0;
  485.         }
  486.         default:
  487.         {
  488.             vertical = 6.0;
  489.             horizontal = -2.2;
  490.         }
  491.     }
  492.     new Float:angle = GetPointAngleToPoint(0, 0, floatsqroot(vector_x*vector_x+vector_y*vector_y), vector_z) - 270.0;
  493.     new Float:resize_x, Float:resize_y, Float:resize_z = floatsin(angle+vertical, degrees);
  494.     GetXYInFrontOfPoint(resize_x, resize_y, GetPointAngleToPoint(0, 0, vector_x, vector_y)+horizontal, floatcos(angle+vertical, degrees));
  495.  
  496.     if (DistanceCameraTargetToLocation(camera_x, camera_y, camera_z, x, y, z, resize_x, resize_y, resize_z) < radius) return true;
  497.     return false;
  498. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement