Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #define MAX MAX_PLAYERS
- #define PRESSED(%0) (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
- #define Weapons_Dialog 9457
- //Edit here as you wish!
- #define Reward_Cash 15000
- #define Reward_Score 50
- enum E_OBJECTS
- {
- Float:pObjectX[ MAX_PLAYERS],
- Float:pObjectY[ MAX_PLAYERS],
- Float:pObjectZ[ MAX_PLAYERS]
- };
- new Float:Random_Object_Speed[18] =
- {
- 0.8, 0.9, 1.0,
- 1.1, 1.2, 1.3,
- 1.4, 1.5, 1.6,
- 1.6, 1.8, 2.0,
- 2.2, 2.3, 2.5,
- 2.1, 2.5, 2.0
- },
- RangePickup[ 7 ],
- Objects_Count[ MAX ] = 0,
- AimObject[ 50 ][ E_OBJECTS ],
- Shooting[ MAX ],
- PlayerObjects[ MAX ],
- Objects_Hit2[ MAX ],
- Objects_Missed[ MAX ],
- A_Objects[ 50 ][ MAX ],
- Float:OnArrow[ 3 ][ MAX ],
- Float:
- Pickup_Pos[ 7 ][ 3 ] =
- {
- {809.2676,1668.9481,5.2813},
- {806.3400,1668.8962,5.2813},
- {803.0370,1668.8966,5.2813},
- {800.2703,1668.8964,5.2813},
- {797.1923,1668.8964,5.2813},
- {794.1580,1668.8971,5.2875},
- {795.9923,1681.0208,5.2813}
- };
- //------------------------------------------------
- public OnPlayerConnect( playerid )
- {
- SendClientMessage( playerid, 0xFFBF00FF, "Shooting Range:{FFFFFF} Have some fun at the shooting range! Type {FFBF00}/range");
- return 1;
- }
- public OnPlayerDisconnect( playerid, reason )
- {
- if ( Shooting[ playerid ] )FinishShootingRange( playerid );
- return 1;
- }
- public OnFilterScriptInit()
- {
- print("\n\t\t\t\16-Shooting Range by Zh3r0-\17\n\t\t\t\t Loaded\n");
- for ( new p = 0; p < MAX_OBJECTS; p ++ )
- {
- for ( new x = 0; x < MAX_PLAYERS; x ++ )
- {
- if ( IsPlayerConnected( x ) )
- {
- DestroyPlayerObject( x, p );
- }
- }
- }
- for ( new p = 0; p < sizeof( Pickup_Pos )-1; p ++ )
- {
- RangePickup[ p ] = CreatePickup( 1318, 2, Pickup_Pos[ p ][ 0 ], Pickup_Pos[ p ][ 1 ], Pickup_Pos[ p ][ 2 ] );
- }
- RangePickup[ 6 ] = CreatePickup( 1239, 2, Pickup_Pos[ 6 ][ 0 ], Pickup_Pos[ 6 ][ 1 ], Pickup_Pos[ 6 ][ 2 ] );
- return 1;
- }
- public OnPlayerUpdate( playerid )
- {
- if ( Shooting [ playerid ] )
- {
- if ( !PlayerToPoint( 1.4, playerid, OnArrow[ 0 ][ playerid ], OnArrow[ 1 ][ playerid ], OnArrow[ 2 ][ playerid ] ) )
- {
- FinishShootingRange( playerid );
- SendClientMessage( playerid, 0xFFBF00FF, "Shooting Range: {FFFFFF}You left the shooting range!");
- }
- }
- return 1;
- }
- public OnPlayerDeath( playerid, killerid, reason )
- {
- if ( Shooting[ playerid ] )
- {
- SendClientMessage( playerid, 0xFFBF00FF, "Shooting Range: {FFFFFF}You died while in the Shooting Range. Quit!");
- FinishShootingRange( playerid );
- }
- return 1;
- }
- public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
- {
- if (PRESSED(KEY_FIRE))
- {
- if ( Shooting[ playerid ] )
- {
- for(new i = 0; i <MAX_OBJECTS; i++)
- {
- if(IsValidPlayerObject( playerid, A_Objects[ i ][ playerid ] ) )
- {
- new Float:oPos[ 3 ];
- GetPlayerObjectPos( playerid, A_Objects[ i ][ playerid ], oPos[ 0 ], oPos[ 1 ], oPos[ 2 ] );
- if ( IsPlayerAiming ( playerid, oPos[ 0 ], oPos[ 1 ], oPos[ 2 ], 0.2 ) )
- {
- if ( GetPlayerWeapon( playerid ) == 31 ||
- GetPlayerWeapon( playerid ) == 33 ||
- GetPlayerWeapon( playerid ) == 34 ||
- GetPlayerWeapon( playerid ) == 30)
- {
- if ( PlayerObjects[ playerid ] > 0 )
- {
- DestroyPlayerObject( playerid, A_Objects[ i ][ playerid ] );
- --PlayerObjects[ playerid ];
- ++Objects_Hit2[ playerid ];
- if ( PlayerObjects[ playerid ] == 0 && Objects_Hit2[ playerid ] != 20 )
- {
- Objects_Missed[ playerid ] = 20 - Objects_Hit2[ playerid ];
- MoveObjectsForPlayerAgain( playerid );
- }
- else if ( Objects_Hit2[ playerid ] == 20 )
- {
- DestroyPlayerObject( playerid, A_Objects[ i ][ playerid ] );
- PlayerObjects[ playerid ] --;
- FinishShootingRange( playerid );
- ShowPlayerDialog( playerid, 2593, DIALOG_STYLE_MSGBOX, "{FFBF00}Shooting Range:{FFFFFF} Shooting trial finished!",\
- "{FFBF00}[ {FFFFFF}Reward{FFBF00} ]\n\
- {00FF00}$"#Reward_Cash"{FFFFFF} dollars\n\
- {00FF40}+"#Reward_Score"{FFFFFF} score\n\n\
- Go and have some more fun! Move to another shooting place!", "Close", "");
- ResetPlayerWeapons( playerid );
- GivePlayerMoney( playerid, Reward_Cash );
- SetPlayerScore( playerid, GetPlayerScore( playerid ) + Reward_Score );
- }
- }
- }
- else
- {
- SendClientMessage( playerid, 0xFFBF00FF, "Shooting Range: {FFFFFF}This weapon is not allowed! ({FFBF00}Allowed Weapons:{FFBF40} Country Rifle, Sniper, M4, Ak47{FFFFFF})");
- FinishShootingRange( playerid );
- SetPlayerPos( playerid, 795.8624, 1685.6016, 5.2813 );
- }
- }
- }
- }
- }
- }
- return 1;
- }
- public OnPlayerObjectMoved(playerid,objectid)
- {
- for ( new i = 0; i <MAX_OBJECTS; i++ )
- {
- if ( objectid == A_Objects[ i ][ playerid ] )
- {
- if ( IsValidPlayerObject( playerid, A_Objects[ i ][ playerid ] ) )
- {
- DestroyPlayerObject( playerid, A_Objects[ i ][ playerid ] );
- PlayerObjects[playerid]--;
- if ( PlayerObjects[playerid] == 0 && Objects_Hit2[playerid] != 20)
- {
- Objects_Missed[playerid] = 20 - Objects_Hit2[playerid];
- MoveObjectsForPlayerAgain( playerid );
- }
- }
- }
- }
- return 1;
- }
- public OnPlayerPickUpPickup( playerid, pickupid )
- {
- new p = 0;
- for ( ;p < 6; ++p)
- {
- if ( pickupid == RangePickup[ p ] && !Shooting[ playerid ])
- {
- ShowPlayerDialog( playerid, Weapons_Dialog, DIALOG_STYLE_LIST, "{FFFFFF}Choose your weapon:", "{FFBF00}Country Rifle\n\
- {FFBF00}Sniper\n\
- {FFBF00}M4\n\
- {FFBF00}AK47", "Select", "Exit" );
- }
- }
- if ( pickupid == RangePickup[ 6 ] )
- {
- new Str[ 1024 ];
- format( Str, 1024, "%s\n\n\
- {FFBF00}[{FFFFFF} Credits {FFBF00}]\n\
- {FFBF00}Zh3r0 \t\t{FFFFFF}- Creator\n\
- {FFBF00}DeatheR \t{FFFFFF}- Some functions(Almost all)\n\
- {FFBF00}niCe \t\t{FFFFFF}- {FFBF00}IsPlayerAimingAt{FFFFFF} function\n\nHave Fun!\n",Info());
- ShowPlayerDialog( playerid, 2593, DIALOG_STYLE_MSGBOX, "{FFBF00}Shooting Range: {FFFFFF}Information", Str, "Close", "");
- }
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- if ( dialogid == Weapons_Dialog )
- {
- if ( response )
- {
- ResetPlayerWeapons( playerid );
- switch( listitem )
- {
- case 0: GivePlayerWeapon( playerid, 33, 99999 ),SendClientMessage( playerid, 0xFFBF00FF, "Shooting Range:{FFFFFF} You selected {FFBF00}Country Rifle{FFFFFF} as your weapon!");
- case 1: GivePlayerWeapon( playerid, 34, 99999 ),SendClientMessage( playerid, 0xFFBF00FF, "Shooting Range:{FFFFFF} You selected {FFBF00}Sniper{FFFFFF} as your weapon!");
- case 2: GivePlayerWeapon( playerid, 31, 99999 ),SendClientMessage( playerid, 0xFFBF00FF, "Shooting Range:{FFFFFF} You selected {FFBF00}M4{FFFFFF} as your weapon!");
- case 3: GivePlayerWeapon( playerid, 30, 99999 ),SendClientMessage( playerid, 0xFFBF00FF, "Shooting Range:{FFFFFF} You selected {FFBF00}AK47{FFFFFF} as your weapon!");
- }
- GetPlayerPos( playerid, OnArrow[ 0 ][ playerid ], OnArrow[ 1 ][ playerid ] ,OnArrow[ 2 ][ playerid ] );
- Shooting[ playerid ] = 1;
- PlayerObjects[playerid] = 20;
- Objects_Hit2[ playerid ] = 0;
- LoadAimObjects( playerid );
- for(new i=0; i<=20; i++)
- {
- new rand_val = random( sizeof( Random_Object_Speed ) );
- MovePlayerObject(playerid, A_Objects[i][playerid], 790.6284, AimObject[i][pObjectY][playerid], AimObject[i][pObjectZ][playerid], Random_Object_Speed[rand_val]);
- }
- GameTextForPlayer( playerid, "~r~~n~~n~~n~~n~~n~~n~~n~Start shooting!", 2000, 3 );
- }
- }
- return 1;
- }
- stock MoveObjectsForPlayerAgain( playerid )
- {
- new ObjectsMiss = Objects_Missed[ playerid ];
- PlayerObjects[ playerid ] = ObjectsMiss;
- for(new x = 0; x < ObjectsMiss; x++)
- {
- CreateAimObject( x ,playerid);
- }
- for(new x = 0; x <= ObjectsMiss; x++)
- {
- new rand_val = random( sizeof ( Random_Object_Speed ) );
- MovePlayerObject(playerid, A_Objects[ x ][ playerid ], 790.6284, AimObject[ x ][ pObjectY ][ playerid ], AimObject[ x ][ pObjectZ ][ playerid ], Random_Object_Speed[ rand_val ] );
- }
- }
- FinishShootingRange( p )
- {
- Objects_Count[ p ] = 0;
- Shooting[ p ] = 0;
- Objects_Missed[ p ] = 0;
- ResetPlayerWeapons( p );
- for ( new i = 0; i < 30; i++)
- {
- DestroyPlayerObject(p, A_Objects[ i ][ p ] );
- }
- PlayerObjects[ p ] = 0;
- Objects_Hit2[ p ] = 0;
- return 1;
- }
- LoadAimObjects( p )
- {
- //Did it this way due to some loop mallfunction
- //( Keept creating on and on when a player would join )
- CreateAimObject( 0, p );
- CreateAimObject( 1, p );
- CreateAimObject( 2, p );
- CreateAimObject( 3, p );
- CreateAimObject( 4, p );
- CreateAimObject( 5, p );
- CreateAimObject( 6, p );
- CreateAimObject( 7, p );
- CreateAimObject( 8, p );
- CreateAimObject( 9, p );
- CreateAimObject( 10, p );
- CreateAimObject( 11, p );
- CreateAimObject( 12, p );
- CreateAimObject( 13, p );
- CreateAimObject( 14, p );
- CreateAimObject( 15, p );
- CreateAimObject( 16, p );
- CreateAimObject( 17, p );
- CreateAimObject( 18, p );
- CreateAimObject( 19, p );
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- if(!strcmp(cmdtext,"/test"))
- {
- new str[256];
- format( str, 265, "PlayerObjects = %d | Objects_Hit = %d", PlayerObjects[ playerid ], Objects_Hit2[ playerid ] );
- SendClientMessage( playerid, -1, str);
- return 1;
- }
- if(!strcmp(cmdtext,"/re"))
- {
- if ( !Shooting[ playerid ] )
- return SendClientMessage( playerid, 0xFFBF00FF, "Shooting Range: {FFFFFF}You are not shooting!");
- else
- FinishShootingRange( playerid );
- return 1;
- }
- if(!strcmp(cmdtext,"/range"))
- {
- ShowPlayerDialog
- (
- playerid,
- 2593,
- DIALOG_STYLE_MSGBOX,
- "{FFFFFF}Shooting Range",
- Info(),
- "Close",
- ""
- );
- SetPlayerPos( playerid, 795.8624, 1685.6016, 5.2813 );
- return 1;
- }
- return 1;
- }
- Info()
- {
- new Str[ 1024 ];
- strcat2( Str, "\t\t\t\t {FF0000}Shooting Range\n\n");
- strcat2( Str, "{FFBF00}Information{FFFFFF}\n");
- strcat2( Str, "- The Shooting Range was made by {FFBF00}Zh3r0{FFFFFF} on date {FFBF00}20/02/2011{FFFFFF}.\n");
- strcat2( Str, "- It has {FFBF00}6{FFFFFF} pickups placed on the shooting place.\n");
- strcat2( Str, "- When you enter a pickup(arrow) some random objects will appear, shoot them!\n");
- strcat2( Str, "- After you finish the shooting, you will be rewarded with moneys and score!\n");
- strcat2( Str, "- Use command {FFBF00}/re{FFFFFF} to exit the Shooting Field( Or simply while shooting leave the field )\n");
- strcat2( Str, "- You can select with which weapon you want to shoot.( {FFBF00}Shotgun, Sniper, M4, Ak47{FFFFFF} )\n");
- return Str;
- }
- strcat2( string[], string2[] ) return strcat( string, string2, 1024 );
- PlayerToPoint(Float:radi, playerid, Float:x, Float:y, Float:z)
- {
- new Float:oldposx, Float:oldposy, Float:oldposz;
- new Float:tempposx, Float:tempposy, Float:tempposz;
- GetPlayerPos(playerid, oldposx, oldposy, oldposz);
- tempposx = (oldposx -x);
- tempposy = (oldposy -y);
- tempposz = (oldposz -z);
- if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
- {
- return 1;
- }
- return 0;
- }
- Float:getRand(Float:ll, Float:ul)
- {
- new ulv = floatround(ul, floatround_ceil);
- new llv = floatround(ll, floatround_floor);
- new range = ulv-llv;
- new Float:number = ll+(rand()%range);
- return number;
- }
- stock rand()
- {
- new rand_num = random(32767);
- return rand_num;
- }
- stock CreateAimObject(oid,playerid)
- {
- new Float:x = getRand(810.3989, 830.9512);
- new Float:y = getRand(1618.3936,1632.4587);
- new Float:z = getRand(5.4932, 10.4932);
- AimObject[oid][pObjectX][playerid] = x;
- AimObject[oid][pObjectY][playerid] = y;
- AimObject[oid][pObjectZ][playerid] = z;
- //DestroyPlayerObject( playerid, A_Objects[oid][playerid] );
- 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);
- return 1;
- }
- Float:DistanceCameraTargetToLocation(Float:CamX, Float:CamY, Float:CamZ, Float:ObjX, Float:ObjY, Float:ObjZ, Float:FrX, Float:FrY, Float:FrZ)
- {
- new Float:TGTDistance;
- TGTDistance = floatsqroot((CamX - ObjX) * (CamX - ObjX) + (CamY - ObjY) * (CamY - ObjY) + (CamZ - ObjZ) * (CamZ - ObjZ));
- new Float:tmpX, Float:tmpY, Float:tmpZ;
- tmpX = FrX * TGTDistance + CamX;
- tmpY = FrY * TGTDistance + CamY;
- tmpZ = FrZ * TGTDistance + CamZ;
- return floatsqroot((tmpX - ObjX) * (tmpX - ObjX) + (tmpY - ObjY) * (tmpY - ObjY) + (tmpZ - ObjZ) * (tmpZ - ObjZ));
- }
- //===================================//
- stock Float:GetPointAngleToPoint(Float:x2, Float:y2, Float:X, Float:Y)
- {
- new Float:DX, Float:DY;
- new Float:angle;
- DX = floatabs(floatsub(x2,X));
- DY = floatabs(floatsub(y2,Y));
- if (DY == 0.0 || DX == 0.0)
- {
- if(DY == 0 && DX > 0) angle = 0.0;
- else if(DY == 0 && DX < 0) angle = 180.0;
- else if(DY > 0 && DX == 0) angle = 90.0;
- else if(DY < 0 && DX == 0) angle = 270.0;
- else if(DY == 0 && DX == 0) angle = 0.0;
- }
- else
- {
- angle = atan(DX/DY);
- if(X > x2 && Y <= y2) angle += 90.0;
- else if(X <= x2 && Y < y2) angle = floatsub(90.0, angle);
- else if(X < x2 && Y >= y2) angle -= 90.0;
- else if(X >= x2 && Y > y2) angle = floatsub(270.0, angle);
- }
- return floatadd(angle, 90.0);
- }
- //===================================//
- stock GetXYInFrontOfPoint(&Float:x, &Float:y, Float:angle, Float:distance)
- {
- x += (distance * floatsin(-angle, degrees));
- y += (distance * floatcos(-angle, degrees));
- }
- //===================================//
- stock IsPlayerAiming(playerid, Float:x, Float:y, Float:z, Float:radius)
- {
- new Float:camera_x,Float:camera_y,Float:camera_z,Float:vector_x,Float:vector_y,Float:vector_z;
- GetPlayerCameraPos(playerid, camera_x, camera_y, camera_z);
- GetPlayerCameraFrontVector(playerid, vector_x, vector_y, vector_z);
- new Float:vertical, Float:horizontal;
- switch (GetPlayerWeapon(playerid))
- {
- case 34,35,36:
- {
- if (DistanceCameraTargetToLocation(camera_x, camera_y, camera_z, x, y, z, vector_x, vector_y, vector_z) < radius) return true;
- return false;
- }
- case 30,31:
- {
- vertical = 4.0;
- horizontal = -1.6;
- }
- case 33:
- {
- vertical = 2.7;
- horizontal = -1.0;
- }
- default:
- {
- vertical = 6.0;
- horizontal = -2.2;
- }
- }
- new Float:angle = GetPointAngleToPoint(0, 0, floatsqroot(vector_x*vector_x+vector_y*vector_y), vector_z) - 270.0;
- new Float:resize_x, Float:resize_y, Float:resize_z = floatsin(angle+vertical, degrees);
- GetXYInFrontOfPoint(resize_x, resize_y, GetPointAngleToPoint(0, 0, vector_x, vector_y)+horizontal, floatcos(angle+vertical, degrees));
- if (DistanceCameraTargetToLocation(camera_x, camera_y, camera_z, x, y, z, resize_x, resize_y, resize_z) < radius) return true;
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement