Arrest Key ...(Cops And Robbers)
#1

hello guys!
Look here, I tried to do when you press the key 2 arrest player around you! ... but... not work
Can you tell me what's wrong?

Код:
 if(newkeys == KEY_SUBMISSION)
	{
	new string[256];
	if(gTeam[playerid] == COP || gTeam[playerid] == SWAT || gTeam[playerid] == ARMY || gTeam[playerid] == FBI)
	{
	if(IsPlayerInAnyVehicle(playerid))
	{
    SendClientMessage(playerid,COLOR_ERROR,"You cannot arrest a suspect if you are in a car");
    return 1;
    }
	for(new i;i<MAX_PLAYERS;i++)
	{
	if(GetDistanceBetweenPlayers(i,playerid) <= 10 && GetPlayerWantedLevel(i) >= 4)
	{
	new spawn = random(sizeof(PrisonSpawn)), string2[250], Float:health, copname[MAX_PLAYER_NAME], arrested[MAX_PLAYER_NAME];
    GetPlayerName(playerid, copname, sizeof(copname));
    GetPlayerName(i, arrested, sizeof(arrested));
    GetPlayerHealth(i, health);
	SendClientMessage(i, GREY, "|_| San Andreas Police Dept. |_|");
	format(string, sizeof(string), "Officer %s has arrested you.", copname);
	SendClientMessage(i, WHITE, string);
	ResetPlayerWeapons(i);
	SetPlayerPos(i, PrisonSpawn[spawn][0], PrisonSpawn[spawn][1], PrisonSpawn[spawn][2]);
	SetPlayerFacingAngle(i, PrisonSpawn[spawn][3]);
	SetCameraBehindPlayer(i);
	if(GetPlayerWantedLevel(i) >= 4 && GetPlayerWantedLevel(i) <= 5)
	{
	PrisonTime[i] = 60;
	GivePlayerMoney(playerid,25000);
	GivePlayerScore(playerid,1);
	}
	else if(GetPlayerWantedLevel(i) >= 6 && GetPlayerWantedLevel(i) <= 8)
	{
	PrisonTime[i] = 120;
	GivePlayerMoney(playerid,35000);
	GivePlayerScore(playerid,1);
	}
	else if(GetPlayerWantedLevel(i) >= 9 && GetPlayerWantedLevel(i) <= 11)
	{
	PrisonTime[i] = 180;
	GivePlayerMoney(playerid,45000);
	GivePlayerScore(playerid,2);
	}
	else if(GetPlayerWantedLevel(i) >= 12 && GetPlayerWantedLevel(i) <= 14)
	{
	PrisonTime[i] = 240;
	GivePlayerMoney(playerid,55000);
	GivePlayerScore(playerid,2);
	}
	else if(GetPlayerWantedLevel(i) >= 15)
	{
	PrisonTime[i] = 300;
	GivePlayerMoney(playerid,65000);
	GivePlayerScore(playerid,3);
	}
	SetPlayerWantedLevel(i, 0);
	SetPlayerInterior(i,3);
	SetPlayerHealth(i,99999);
	TogglePlayerControllable(i, true);
	SetPlayerJailed(i, true);
	format(string2, sizeof(string2), "Officer %s[ID:%d] arrested %s[ID:%d].", copname, playerid, arrested, i);
	Announce(string2);
	if(health <= 90)
	{
    SendClientMessage(i, GREY, "|_| San Andreas Police Dept. |_|");
    SendClientMessage(i, WHITE, "SAPD has given you some food.");
    SetPlayerHealth(i, health+10);
    ApplyAnimation(i, "FOOD", "EAT_Burger", 4.0, 0, 0, 0, 0, 0);
	}
	}
	}
	}
}
Код:
public Float:GetDistanceBetweenPlayers(p1,p2)
{
	new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
	if(!IsPlayerConnected(p1) || !IsPlayerConnected(p2)) return -1.00;
	GetPlayerPos(p1,x1,y1,z1);
	GetPlayerPos(p2,x2,y2,z2);
	return floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
}
Reply
#2

For The Runix Cops And Robbers v1.2 Can You Make The Warning Gone?
Reply
#3

For about the million time,keys NEVER check with '==' .
Use '&' to check for keys.
pawn Код:
if(newkeys & KEY_SUBMISSION)
Quote:
Originally Posted by sa-mp wiki
How NOT to check for a key
pawn Код:
if (newkeys == KEY_FIRE)
This code may even work in your testing, but it is wrong and your testing is insufficient. Try crouching and pressing fire - your code will instantly stop working. Why? Because "newkeys" is no longer the same as "KEY_FIRE", it is the same as "KEY_FIRE" COMBINED WITH "KEY_CROUCH".
https://sampwiki.blast.hk/wiki/OnPlayerKeyStateChange
Reply
#4

Quote:
Originally Posted by [XST]O_x
Посмотреть сообщение
For about the million time,keys NEVER check with '==' .
Use '&' to check for keys.
pawn Код:
if(newkeys & KEY_SUBMISSION)


https://sampwiki.blast.hk/wiki/OnPlayerKeyStateChange
Does not work ...
When i press 2 in one vehicle say "You can not arrest the suspect if you are in a car" but when I am not in one vehicle... key not work...

I think is to blame
pawn Код:
if(GetDistanceBetweenPlayers(i,playerid) <= 10 && GetPlayerWantedLevel(i) >= 4)
but i don't know whi...
Reply
#5

The vehicle message works,because you've put 'return 1;' there,see?
Return a true value in the end of the key state change.
Reply
#6

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys & KEY_SUBMISSION)
    {
    new string[256];
    if(gTeam[playerid] == COP || gTeam[playerid] == SWAT || gTeam[playerid] == ARMY || gTeam[playerid] == FBI)
    {
    if(IsPlayerInAnyVehicle(playerid))
    {
    SendClientMessage(playerid,COLOR_ERROR,"You cannot arrest a suspect if you are in a car");
    return 1;
    }
    for(new i;i<MAX_PLAYERS;i++)
    {
    if(GetDistanceBetweenPlayers(i,playerid) <= 10 && GetPlayerWantedLevel(i) >= 4)
    {
    new spawn = random(sizeof(PrisonSpawn)), string2[250], Float:health, copname[MAX_PLAYER_NAME], arrested[MAX_PLAYER_NAME];
    GetPlayerName(playerid, copname, sizeof(copname));
    GetPlayerName(i, arrested, sizeof(arrested));
    GetPlayerHealth(i, health);
    SendClientMessage(i, GREY, "|_| San Andreas Police Dept. |_|");
    format(string, sizeof(string), "Officer %s has arrested you.", copname);
    SendClientMessage(i, WHITE, string);
    ResetPlayerWeapons(i);
    SetPlayerPos(i, PrisonSpawn[spawn][0], PrisonSpawn[spawn][1], PrisonSpawn[spawn][2]);
    SetPlayerFacingAngle(i, PrisonSpawn[spawn][3]);
    SetCameraBehindPlayer(i);
    if(GetPlayerWantedLevel(i) >= 4 && GetPlayerWantedLevel(i) <= 5)
    {
    PrisonTime[i] = 60;
    GivePlayerMoney(playerid,25000);
    GivePlayerScore(playerid,1);
    }
    else if(GetPlayerWantedLevel(i) >= 6 && GetPlayerWantedLevel(i) <= 8)
    {
    PrisonTime[i] = 120;
    GivePlayerMoney(playerid,35000);
    GivePlayerScore(playerid,1);
    }
    else if(GetPlayerWantedLevel(i) >= 9 && GetPlayerWantedLevel(i) <= 11)
    {
    PrisonTime[i] = 180;
    GivePlayerMoney(playerid,45000);
    GivePlayerScore(playerid,2);
    }
    else if(GetPlayerWantedLevel(i) >= 12 && GetPlayerWantedLevel(i) <= 14)
    {
    PrisonTime[i] = 240;
    GivePlayerMoney(playerid,55000);
    GivePlayerScore(playerid,2);
    }
    else if(GetPlayerWantedLevel(i) >= 15)
    {
    PrisonTime[i] = 300;
    GivePlayerMoney(playerid,65000);
    GivePlayerScore(playerid,3);
    }
    SetPlayerWantedLevel(i, 0);
    SetPlayerInterior(i,3);
    SetPlayerHealth(i,99999);
    TogglePlayerControllable(i, true);
    SetPlayerJailed(i, true);
    format(string2, sizeof(string2), "Officer %s[ID:%d] arrested %s[ID:%d].", copname, playerid, arrested, i);
    Announce(string2);
    if(health <= 90)
    {
    SendClientMessage(i, GREY, "|_| San Andreas Police Dept. |_|");
    SendClientMessage(i, WHITE, "SAPD has given you some food.");
    SetPlayerHealth(i, health+10);
    ApplyAnimation(i, "FOOD", "EAT_Burger", 4.0, 0, 0, 0, 0, 0);
    }
    return 1;
    }
    return 1;
    }
    return 1;
    }
    return 1;
    }
return 1;
}

But not work ;(
Reply
#7

I think you should not put so many return 1;
just put like
SendClientMessage(i, GREY, "|_| San Andreas Police Dept. |_|");
SendClientMessage(i, WHITE, "SAPD has given you some food.");
SetPlayerHealth(i, health+10);
ApplyAnimation(i, "FOOD", "EAT_Burger", 4.0, 0, 0, 0, 0, 0);
}
return 1;
}
return 0;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)