How to make arrest key?
#1

Guys can help me i dont know how to make a arrest key in cops and robbers its like you press submission key in a vehicle you arrest the play near you
so can you guys tell me how to make or tutorial?
Reply
#2

Код:
// This function gets called when a police player presses the FIRE key (to fine nearby wanted players) when he's on foot
Police_FineNearbyPlayers(playerid)
{
	// Setup local variables
	new PlayerToCheck, Float:x, Float:y, Float:z;

	// Scan through all players
	while (PlayerToCheck < MAX_PLAYERS)
	{
		// check if this player is connected
		if (IsPlayerConnected(PlayerToCheck))
		{
			// Check if the current player is wanted and the wanted player is driving slowly (below 20 kph)
			if ((GetPlayerWantedLevel(PlayerToCheck) > 0) && (APlayerData[PlayerToCheck][PlayerSpeed] < 20))
			{
			    // Get the position of this player
			    GetPlayerPos(PlayerToCheck, x, y, z);

			    // Check if the police-player is in range of the player (police player and wanted player must be within 5 units of eachother)
				if (IsPlayerInRangeOfPoint(playerid, 5.0, x, y, z))
				{
					// Pay the police based on the player's wanted status
					switch (GetPlayerWantedLevel(PlayerToCheck))
					{
						case 1: Police_PayFine(playerid, PlayerToCheck, 500);
						case 2: Police_PayFine(playerid, PlayerToCheck, 1500);
						case 3: Police_PayFine(playerid, PlayerToCheck, 3000);
						case 4: Police_PayFine(playerid, PlayerToCheck, 5000);
						case 5: Police_PayFine(playerid, PlayerToCheck, 7500);
						default: Police_PayFine(playerid, PlayerToCheck, 10000);
					}

					// Clear the player's wanted status
					SetPlayerWantedLevel(PlayerToCheck, 0);
					// Exit the function
					return 1;
				}

				// Check if the police-player is in range of the player (he can be inside his vehicle or on foot)
				if (IsPlayerInRangeOfPoint(playerid, 50.0, x, y, z))
					GameTextForPlayer(PlayerToCheck, "~r~This is the police! Stop at once!~w~", 3000, 4); // Warn the player
			}
		}

		// Next player
		PlayerToCheck++;
	}

	return 1;
}
Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
	// Check the class of the player
	switch (APlayerData[playerid][PlayerClass])
	{
		case ClassPolice:
		{
		    // If the police-player pressed the RMB key (AIM key) when OUTSIDE his vehicle
			if (((newkeys & KEY_HANDBRAKE) && !(oldkeys & KEY_HANDBRAKE)) && (GetPlayerVehicleID(playerid) == 0))
				Police_FineNearbyPlayers(playerid);

		    // If the police-player pressed the LCTRL (SECUNDAIRY key) key when INSIDE his vehicle
			if (((newkeys & KEY_ACTION) && !(oldkeys & KEY_ACTION)) && (GetPlayerVehicleID(playerid) != 0))
				Police_WarnNearbyPlayers(playerid);
		}
	}

	return 1;
}
This is the code I'm using for my police class (just a quick copy/paste). You can check it out and convert it to your needs.
When a player is wanted and the police is within 5.0 units (meters) of the wanted player and hits the button, he gets fined based on his wanted level.
Don't mind the mixed-up comments about the keys, I had to figure out which key to press to get what I wanted because of the keys-bug in samp.
Reply
#3

Thanks Mate
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)