Arresting players with L.ALT bug?
#1

Hello guys, i have problem with following piece of code. I have a police job in my gamemode and cop can arrest players with a command, that's fine, but i decided to make it with a Left Alt key, but that doesn't work. Here is the code.. i hope you can help me :/ (when i press l.alt near wanted player as a cop, nothing happens. compiler also doesn't show any errors or warnings)

EDIT: i found out that it works only if player has ID 0


PHP код:
if (HOLDING(KEY_WALK))
    {
         if(
PlayerInfo[playerid][Team] == 6//If is player a cop
         
{
                for(new 
i=1MAX_PLAYERSi++)
                {
                    if(
GetDistanceBetweenPlayers(playeridi) <= 5)
                    {
                        if(!(
IsPlayerInAnyVehicle(playerid)))
                        {
                            if(
GetPlayerWantedLevel(playerid) == 1)
                            {
                            if(
GetPlayerWantedLevel(i) >= 1)
                            {
                                new 
vehicleid GetPlayerVehicleID(playerid);
                                
format(szStringsizeof(szString), ""c"Policista "w"%s"c" zatkl hrбče "w"%s"c" s wanted levelem "w"%d"c"."pName(playerid), pName(i), GetPlayerWantedLevel(i));
                                
SendClientMessageToAll(COLOR_BLUEszString);
                                
SetPlayerInterior(i6);
                                
SetPlayerPos(i264.3156,77.4590,1001.0391);
                                
GivePlayerMoney(playerid,2100);
                                
GameTextForPlayer(playerid,"~y~Odmena: ~w~$2100",4000,6);
                                
PlayerInfo[playerid][PolicistaZK] += 1;
                                
PlayerInfo[playerid][XP] += 20;
                                
SendClientMessage(playeridCOLOR_XP"Zнskali jste 20 XP!");
                                
PlayerPlaySound(playerid52010.0,0.0,0.0);
                                
PlayerPlaySound(i10830.0,0.0,0.0);
                                
GameTextForPlayer(i"Zatcen"25005);
                                
PlayerInfo[i][JailTime] = GetPlayerWantedLevel(i)*30;
                                
SetPlayerHealth(i100.0);
                                
SetPlayerArmour(i0.0);
                                
SetPlayerWantedLevel(i0);
                                
PlayerInfo[i][Zatcen] += 1;
                                
ResetPlayerWeapons(i);
                                
VTimer[i] = SetTimerEx("Vezeni"1000false"i"i);
                            }
                           }
                       }
                   }
               }
           } 
Reply
#2

Replace

PHP код:
if(GetPlayerWantedLevel(playerid) == 1)
                            {
                            if(
GetPlayerWantedLevel(i) >= 1
with

PHP код:
 if(GetPlayerWantedLevel(i) >= 1
Reply
#3

lol, yes i will replace "if(GetPlayerWantedLevel(playerid) == 1)" with "if(GetPlayerWantedLevel(playerid) == 0)" thanks .. iґm going to test it, let's see if it works
Reply
#4

nope, IT STILL WORKS ONLY FOR PLAYER WITH ID 0 -------BUMP
Reply
#5

PHP код:
for(new i=1MAX_PLAYERSi++) 
to
PHP код:
for(new i=< MAX_PLAYERSi++) 
Reply
#6

Quote:
Originally Posted by ._Xavier$$
Посмотреть сообщение
PHP код:
for(new i=1MAX_PLAYERSi++) 
to
PHP код:
for(new iMAX_PLAYERSi++) 
actually this is the correct way to loop

pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++)
{
    // code here
}
Reply
#7

This should work.

pawn Код:
if (HOLDING(KEY_WALK))
    {
         if(PlayerInfo[playerid][Team] == 6) //If is player a cop
         {
                for(new i=0; i < GetPlayerPoolSize(); i++)
                {
                    if(GetDistanceBetweenPlayers(playerid, i) <= 5)
                    {
                        if(!(IsPlayerInAnyVehicle(playerid)))
                        {
                            if(GetPlayerWantedLevel(i) >= 1)
                            {
                                new vehicleid = GetPlayerVehicleID(playerid);
                                format(szString, sizeof(szString), ""c"Policista "w"%s"c" zatkl hrбče "w"%s"c" s wanted levelem "w"%d"c".", pName(playerid), pName(i), GetPlayerWantedLevel(i));
                                SendClientMessageToAll(COLOR_BLUE, szString);
                                SetPlayerInterior(i, 6);
                                SetPlayerPos(i, 264.3156,77.4590,1001.0391);
                                GivePlayerMoney(playerid,2100);
                                GameTextForPlayer(playerid,"~y~Odmena: ~w~$2100",4000,6);
                                PlayerInfo[playerid][PolicistaZK] += 1;
                                PlayerInfo[playerid][XP] += 20;
                                SendClientMessage(playerid, COLOR_XP, "Zнskali jste 20 XP!");
                                PlayerPlaySound(playerid, 5201, 0.0,0.0,0.0);
                                PlayerPlaySound(i, 1083, 0.0,0.0,0.0);
                                GameTextForPlayer(i, "Zatcen", 2500, 5);
                                PlayerInfo[i][JailTime] = GetPlayerWantedLevel(i)*30;
                                SetPlayerHealth(i, 100.0);
                                SetPlayerArmour(i, 0.0);
                                SetPlayerWantedLevel(i, 0);
                                PlayerInfo[i][Zatcen] += 1;
                                ResetPlayerWeapons(i);
                                VTimer[i] = SetTimerEx("Vezeni", 1000, false, "i", i);
                            }
                           
                       }
                   }
               }
           }
Reply
#8

Removed.
Reply
#9

Thanks you guys, now it works <3 REP+ to all of you xD
Reply
#10

Glad you got it to work. Cheers.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)