SA-MP Forums Archive
I need help with this command! - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: I need help with this command! (/showthread.php?tid=257945)



I need help with this command! - Cjgogo - 28.05.2011

Look this are my first loops and I'm not so good at them yet so if you could tell me what;s wrong I would appreciate because the only thing I manage to do in-game is arresting myself.
pawn Код:
if(newkeys == KEY_LOOK_BEHIND)
    {
      for(new i = 0;i<MAX_PLAYERS;i++)
      {
          if(gTeam[playerid] == TEAM_COPS)
          {
             if(GetDistanceBetweenPlayers(i,playerid) > 5) return SendClientMessage(playerid,COLOR_WHITE,"Nobody is close enough");
             if(GetDistanceBetweenPlayers(i,playerid) < 5)
             {
                if(GetPlayerWantedLevel(i) > 0)
                {
                   TogglePlayerControllable(i,0);
                   GivePlayerMoney(playerid,500);
                   GivePlayerMoney(i,-500);
                   new copname[20];
                   new wantedname[20];
                   GetPlayerName(i,wantedname,sizeof(wantedname));
                   GetPlayerName(playerid,copname,sizeof(copname));
                   new string[128];
                   format(string,sizeof(string),"%s(%d) has been arrested by officer %s(%d)",wantedname,i,copname,playerid);
                   SendClientMessageToAll(COLOR_GREY,string);
                }
            }
        }
     }
   }



Re: I need help with this command! - Haydz - 28.05.2011

You need to put a check in to see if the player their trying to arrest is the same as the playerid. Something like
pawn Код:
if(i == playerid) return SendClientMessage(playerid,-1,"You cannot arrest yourself");
should work fine, If you don't want it to say 'you cannot arrest yourself' you could just put
pawn Код:
if(i != playerid)
pawn Код:
if(newkeys == KEY_LOOK_BEHIND)
{
    if(gTeam[playerid] == TEAM_COPS)
    {
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            if(GetDistanceBetweenPlayers(i,playerid) > 5) return SendClientMessage(playerid,COLOR_WHITE,"Nobody is close enough");
            if(GetDistanceBetweenPlayers(i,playerid) < 5)
            {
                if(i == playerid) return SendClientMessage(playerid, -1,"You cannot arrest yourself.");
                if(GetPlayerWantedLevel(i) > 0)
                {
                    TogglePlayerControllable(i,0);
                    GivePlayerMoney(playerid,500);
                    GivePlayerMoney(i,-500);
                    new copname[20];
                    new wantedname[20];
                    GetPlayerName(i,wantedname,sizeof(wantedname));
                    GetPlayerName(playerid,copname,sizeof(copname));
                    new string[128];
                    format(string,sizeof(string),"%s(%d) has been arrested by officer %s(%d)",wantedname,i,copname,playerid);
                    SendClientMessageToAll(COLOR_GREY,string);
                }
            }
        }
    }
}
Hopefully something like that should work.


Re: I need help with this command! - cs_master - 28.05.2011

hyden i think u need this command for ur poilt server but i am banned frm here on when i make 4 score i think its a bug


Re: I need help with this command! - Cjgogo - 28.05.2011

no it's buggy when I neter a car and turn the engine on it's sending me error u can not arrest urself and other things,basically I need someone good at loops


Re: I need help with this command! - Cjgogo - 28.05.2011

anyone please good at loops?


Re: I need help with this command! - x-cutter - 28.05.2011

Код:
if(newkeys == KEY_LOOK_BEHIND)
{
    if(gTeam[playerid] == TEAM_COPS)
    {
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
               if(!IsPlayerConnected(i))return 1;
               if(playerid == i)return 1;
that should be the start of your code. what this does, it ignores your own player id when it gets it in the loop. it also checks if the player id acquired by looping is online.


Re: I need help with this command! - Cjgogo - 28.05.2011

hmm now it doesn't arrest myself but it also doesn't say Nobody is close enouugh


Re: I need help with this command! - Cjgogo - 28.05.2011

this is how the new code looks
pawn Код:
if(newkeys == KEY_LOOK_BEHIND)
    {
       if(gTeam[playerid] == TEAM_COPS)
       {
          for(new i = 0;i<MAX_PLAYERS;i++)
          {
            if(!IsPlayerConnected(i)) return SendClientMessage(playerid,COLOR_WHITE,"Nobody is close enough");
            if(playerid == i) return SendClientMessage(playerid,COLOR_WHITE,"Nobody is close enough");
            if(GetDistanceBetweenPlayers(i,playerid) < 5)
             {
                if(GetPlayerWantedLevel(i) > 0)
                {
                   TogglePlayerControllable(i,0);
                   GivePlayerMoney(playerid,500);
                   GivePlayerMoney(i,-500);
                   new copname[20];
                   new wantedname[20];
                   GetPlayerName(i,wantedname,sizeof(wantedname));
                   GetPlayerName(playerid,copname,sizeof(copname));
                   new string[128];
                   format(string,sizeof(string),"%s(%d) has been arrested by officer %s(%d)",wantedname,i,copname,playerid);
                   SendClientMessageToAll(COLOR_GREY,string);
                }
            }
          }
       }
     }
1)Do you think that would work on game?
2)When I enter a car(made my own engine system) and I press 2 to toggle engine it says Nobody is close enough