OnPlayerKeyStateChange ID0 problem
#1

hi everyone i need hellp im trying to don that when a cop presse ALT <KEY_WALK> the player near of playerid get cuffed and when it pressed again he will be send to jail but it work only on ID:0
please help

PHP код:
//cuff
public :confused:(playeridnewkeysoldkeys)
{
    new 
string[128];
    if(
newkeys == KEY_WALK)
    {
        for(new 
i=0;i<MAX_PLAYERS;i++)
        {
            if(
CommandsBlocked[playerid] == 1)
            {
                
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] Your commands are blocked, You cannot use commands.");
                return 
1;
            }
            if(
InDuel[playerid] == 1)
            {
                
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You cannot use commands while on duel, Use /leave to exit the duel.");
                return 
1;
            }
            if(
pInfo[playerid][Spawned] != 1)
            {
                
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You must be alive and spawned in order to be able to use this command.");
                return 
1;
            }
            if(
IsKidnapped[playerid] == 1)
            {
                
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You are kidnapped. You cannot use this command.");
                return 
1;
            }
            if(
IsFrozen[playerid] == 1)
            {
                
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You have been frozen by a Server Administrator. You cannot use this command.");
                return 
1;
            }
            if(
AccInfo[i][OnDuty] == 1)
            {
                
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You cannot use this command on this player because they are in Administrator mode.");
                return 
1;
            }
            if(
gTeam[playerid] != COP && gTeam[playerid] != ARMY && gTeam[playerid] != CIA && gTeam[playerid] != FBI)
            {
                return 
1;
            }
            if(
== playerid)
            {
                return 
1;
            }
            if(
GetDistanceBetweenPlayers(playerid,i) > 4)
            {
                
format(string,sizeof(string),"[ERROR] %s[%d] is too far away. You cannot reach him to place cuffs on him.",GetName(i),i);
                
SendClientMessage(playerid,COLOR_ERROR,string);
                return 
1;
            }
            if(
GetPlayerWantedLevel(i) == 0)
            {
                
format(string,sizeof(string),"[ERROR] %s[%d] is innocent. use /cuff to place cuffs on him.",GetName(i),i);
                
SendClientMessage(playerid,COLOR_ERROR,string);
                return 
1;
            }
            if(
gTeam[i] == COP || gTeam[i] == ARMY || gTeam[i] == CIA || gTeam[i] == FBI)
            {
                
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You cannot cuff other Law Enforcement officers. You might lose your job for that ...");
                return 
1;
            }
            if(
GetPlayerState(playerid) == PLAYER_STATE_DRIVER || GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
            {
                
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You cannot place a suspect in cuffs while in a vehicle. Exit the vehicle first.");
                return 
1;
            }
            if(
GetPlayerState(i) == PLAYER_STATE_DRIVER || GetPlayerState(i) == PLAYER_STATE_PASSENGER)
            {
                
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You cannot place a suspect in cuffs while they are in a vehicle. Get them to exit the vehicle first.");
                return 
1;
            }
            if(
pInfo[i][Spawned] != 1)
            {
                
format(string,sizeof(string),"[ERROR] %s(%d) is not spawned. You cannot place cuffs on dead people ..",GetName(i),i);
                
SendClientMessage(playerid,COLOR_ERROR,string);
                return 
1;
            }
            if(
IsFrozen[i] == 1)
            {
                
format(string,sizeof(string),"[ERROR] %s(%d) is frozen by a Server Administrator. You cannot place cuffs them.",GetName(i),i);
                
SendClientMessage(playerid,COLOR_ERROR,string);
                return 
1;
            }
            if(
IsCuffed[i] == && cuff_arrest_time[i] != 0) return 1;
            
            if(
IsCuffed[i] == && cuff_arrest_time[i] == 0)
            {
                    
ARREST(playerid,i);
            }
            
CUFF(playerid,i);
            
        }
    }
    return 
1;

Reply
#2

Try this:

https://sampforum.blast.hk/showthread.php?tid=570868

Instead of the normal loop.

And for a more effecient way, you should run the loop the find out the nearest ID(the one you want to cuff/arrest), and after that do all the rest(close the loop before) because your loop is running shitloads of code and it's being returned 1; which is why it stops.
Reply
#3

Quote:
Originally Posted by jihadmeneer
Посмотреть сообщение
Try this:

https://sampforum.blast.hk/showthread.php?tid=570868

Instead of the normal loop.

And for a more effecient way, you should run the loop the find out the nearest ID(the one you want to cuff/arrest), and after that do all the rest(close the loop before) because your loop is running shitloads of code and it's being returned 1; which is why it stops.
tnx for your answer can you show me how
Reply
#4

PHP код:
public :confused:(newkeysoldkeys)
{
    new 
string[128];
    if(
newkeys == KEY_WALK)
    {
        for(new 
i=0;i<MAX_PLAYERS;i++)
        {
         for(new 
playerid;playerid<MAX_PLAYERS;playerid++)
           {
            if(
CommandsBlocked[playerid] == 1)
            {
                
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] Your commands are blocked, You cannot use commands.");
                return 
1;
            }
            if(
InDuel[playerid] == 1)
            {
                
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You cannot use commands while on duel, Use /leave to exit the duel.");
                return 
1;
            }
            if(
pInfo[playerid][Spawned] != 1)
            {
                
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You must be alive and spawned in order to be able to use this command.");
                return 
1;
            }
            if(
IsKidnapped[playerid] == 1)
            {
                
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You are kidnapped. You cannot use this command.");
                return 
1;
            }
            if(
IsFrozen[playerid] == 1)
            {
                
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You have been frozen by a Server Administrator. You cannot use this command.");
                return 
1;
            }
            if(
AccInfo[i][OnDuty] == 1)
            {
                
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You cannot use this command on this player because they are in Administrator mode.");
                return 
1;
            }
            if(
gTeam[playerid] != COP && gTeam[playerid] != ARMY && gTeam[playerid] != CIA && gTeam[playerid] != FBI)
            {
                return 
1;
            }
            if(
== playerid)
            {
                return 
1;
            }
            if(
GetDistanceBetweenPlayers(playerid,i) > 4)
            {
                
format(string,sizeof(string),"[ERROR] %s[%d] is too far away. You cannot reach him to place cuffs on him.",GetName(i),i);
                
SendClientMessage(playerid,COLOR_ERROR,string);
                return 
1;
            }
            if(
GetPlayerWantedLevel(i) == 0)
            {
                
format(string,sizeof(string),"[ERROR] %s[%d] is innocent. use /cuff to place cuffs on him.",GetName(i),i);
                
SendClientMessage(playerid,COLOR_ERROR,string);
                return 
1;
            }
            if(
gTeam[i] == COP || gTeam[i] == ARMY || gTeam[i] == CIA || gTeam[i] == FBI)
            {
                
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You cannot cuff other Law Enforcement officers. You might lose your job for that ...");
                return 
1;
            }
            if(
GetPlayerState(playerid) == PLAYER_STATE_DRIVER || GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
            {
                
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You cannot place a suspect in cuffs while in a vehicle. Exit the vehicle first.");
                return 
1;
            }
            if(
GetPlayerState(i) == PLAYER_STATE_DRIVER || GetPlayerState(i) == PLAYER_STATE_PASSENGER)
            {
                
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You cannot place a suspect in cuffs while they are in a vehicle. Get them to exit the vehicle first.");
                return 
1;
            }
            if(
pInfo[i][Spawned] != 1)
            {
                
format(string,sizeof(string),"[ERROR] %s(%d) is not spawned. You cannot place cuffs on dead people ..",GetName(i),i);
                
SendClientMessage(playerid,COLOR_ERROR,string);
                return 
1;
            }
            if(
IsFrozen[i] == 1)
            {
                
format(string,sizeof(string),"[ERROR] %s(%d) is frozen by a Server Administrator. You cannot place cuffs them.",GetName(i),i);
                
SendClientMessage(playerid,COLOR_ERROR,string);
                return 
1;
            }
            if(
IsCuffed[i] == && cuff_arrest_time[i] != 0) return 1;
            
            if(
IsCuffed[i] == && cuff_arrest_time[i] == 0)
            {
                    
ARREST(playerid,i);
            }
            
CUFF(playerid,i);
            
        }
    }
    return 
1;

instead of putting playerid in public try to add >>
PHP код:
for(new playerid;playerid<MAX_PLAYERS;playerid++)
    { 
wish it will work
Reply
#5

I had a good laugh reading the stupidity of the replies you got. You have a lot of code here that does not even belong in a loop and there other issues as well with the logic structure. I won't even begin to explain how out to lunch this code is as it is quite apparent you have not the slightest clue as to what you are doing simply you are using downloaded scripts.
Reply
#6

Quote:
Originally Posted by Pottus
Посмотреть сообщение
I had a good laugh reading the stupidity of the replies you got. You have a lot of code here that does not even belong in a loop and there other issues as well with the logic structure.
You say it

I am so friendly and solve this "problem" for you


Here you go:

PHP код:
new string[128];
    if(
newkeys KEY_WALK)
    {
        if(
CommandsBlocked[playerid] == 1) return SendClientMessage(playerid,COLOR_ERROR,"[ERROR] Your commands are blocked, You cannot use commands.");
        if(
InDuel[playerid] == 1) return SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You cannot use commands while on duel, Use /leave to exit the duel.");
        if(
pInfo[playerid][Spawned] != 1) return SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You must be alive and spawned in order to be able to use this command.");
        if(
IsKidnapped[playerid] == 1) return SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You are kidnapped. You cannot use this command.");
        if(
IsFrozen[playerid] == 1) return SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You have been frozen by a Server Administrator. You cannot use this command.");
        if(
AccInfo[i][OnDuty] == 1) return SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You cannot use this command on this player because they are in Administrator mode.");
        if(
gTeam[playerid] != COP && gTeam[playerid] != ARMY && gTeam[playerid] != CIA && gTeam[playerid] != FBI) return 1;
        new 
GetClosestPlayer(playerid);
        if(
== -1) return 1;
        if(
GetDistanceBetweenPlayers(playerid,i) > 4)
        {
            
format(string,sizeof(string),"[ERROR] %s[%d] is too far away. You cannot reach him to place cuffs on him.",GetName(i),i);
            
SendClientMessage(playerid,COLOR_ERROR,string);
            return 
1;
        }
        if(
GetPlayerWantedLevel(i) == 0)
        {
            
format(string,sizeof(string),"[ERROR] %s[%d] is innocent. use /cuff to place cuffs on him.",GetName(i),i);
            
SendClientMessage(playerid,COLOR_ERROR,string);
            return 
1;
        }
        if(
gTeam[i] == COP || gTeam[i] == ARMY || gTeam[i] == CIA || gTeam[i] == FBI)
        {
            
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You cannot cuff other Law Enforcement officers. You might lose your job for that ...");
            return 
1;
        }
        if(
GetPlayerState(playerid) == PLAYER_STATE_DRIVER || GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
        {
            
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You cannot place a suspect in cuffs while in a vehicle. Exit the vehicle first.");
            return 
1;
        }
        if(
GetPlayerState(i) == PLAYER_STATE_DRIVER || GetPlayerState(i) == PLAYER_STATE_PASSENGER)
        {
            
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You cannot place a suspect in cuffs while they are in a vehicle. Get them to exit the vehicle first.");
            return 
1;
        }
        if(
pInfo[i][Spawned] != 1)
        {
            
format(string,sizeof(string),"[ERROR] %s(%d) is not spawned. You cannot place cuffs on dead people ..",GetName(i),i);
            
SendClientMessage(playerid,COLOR_ERROR,string);
            return 
1;
        }
        if(
IsFrozen[i] == 1)
        {
            
format(string,sizeof(string),"[ERROR] %s(%d) is frozen by a Server Administrator. You cannot place cuffs them.",GetName(i),i);
            
SendClientMessage(playerid,COLOR_ERROR,string);
            return 
1;
        }
        if(
IsCuffed[i] == && cuff_arrest_time[i] != 0) return 1;
        if(
IsCuffed[i] == && cuff_arrest_time[i] == 0)
        {
                
ARREST(playerid,i);
        }
        
CUFF(playerid,i);
    }
    return 
1;
}
stock GetClosestPlayer(playerid) {
    new 
idx=-1,Float:x,Float:y,Float:z;
    
GetPlayerPos(playerid,x,y,z);
    for(new 
i=GetPlayerPoolSize()+1,Float:tmp,Float:max=3000.0; --i!=-1; ) {
        if(!
IsPlayerConnected(i) || IsPlayerNPC(i) || i==playerid) continue;
        
tmp GetPlayerDistanceFromPoint(i,x,y,z);
        if(
tmp maxmax=tmp,idx=i;
    }
    return 
idx;

Reply
#7

That isn't even close to solved.
Reply
#8

Quote:
Originally Posted by Kaliber
Посмотреть сообщение
You say it

I am so friendly and solve this "problem" for you


Here you go:

PHP код:
new string[128];
    if(
newkeys KEY_WALK)
    {
        if(
CommandsBlocked[playerid] == 1) return SendClientMessage(playerid,COLOR_ERROR,"[ERROR] Your commands are blocked, You cannot use commands.");
        if(
InDuel[playerid] == 1) return SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You cannot use commands while on duel, Use /leave to exit the duel.");
        if(
pInfo[playerid][Spawned] != 1) return SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You must be alive and spawned in order to be able to use this command.");
        if(
IsKidnapped[playerid] == 1) return SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You are kidnapped. You cannot use this command.");
        if(
IsFrozen[playerid] == 1) return SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You have been frozen by a Server Administrator. You cannot use this command.");
        if(
AccInfo[i][OnDuty] == 1) return SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You cannot use this command on this player because they are in Administrator mode.");
        if(
gTeam[playerid] != COP && gTeam[playerid] != ARMY && gTeam[playerid] != CIA && gTeam[playerid] != FBI) return 1;
        new 
GetClosestPlayer(playerid);
        if(
== -1) return 1;
        if(
GetDistanceBetweenPlayers(playerid,i) > 4)
        {
            
format(string,sizeof(string),"[ERROR] %s[%d] is too far away. You cannot reach him to place cuffs on him.",GetName(i),i);
            
SendClientMessage(playerid,COLOR_ERROR,string);
            return 
1;
        }
        if(
GetPlayerWantedLevel(i) == 0)
        {
            
format(string,sizeof(string),"[ERROR] %s[%d] is innocent. use /cuff to place cuffs on him.",GetName(i),i);
            
SendClientMessage(playerid,COLOR_ERROR,string);
            return 
1;
        }
        if(
gTeam[i] == COP || gTeam[i] == ARMY || gTeam[i] == CIA || gTeam[i] == FBI)
        {
            
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You cannot cuff other Law Enforcement officers. You might lose your job for that ...");
            return 
1;
        }
        if(
GetPlayerState(playerid) == PLAYER_STATE_DRIVER || GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
        {
            
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You cannot place a suspect in cuffs while in a vehicle. Exit the vehicle first.");
            return 
1;
        }
        if(
GetPlayerState(i) == PLAYER_STATE_DRIVER || GetPlayerState(i) == PLAYER_STATE_PASSENGER)
        {
            
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You cannot place a suspect in cuffs while they are in a vehicle. Get them to exit the vehicle first.");
            return 
1;
        }
        if(
pInfo[i][Spawned] != 1)
        {
            
format(string,sizeof(string),"[ERROR] %s(%d) is not spawned. You cannot place cuffs on dead people ..",GetName(i),i);
            
SendClientMessage(playerid,COLOR_ERROR,string);
            return 
1;
        }
        if(
IsFrozen[i] == 1)
        {
            
format(string,sizeof(string),"[ERROR] %s(%d) is frozen by a Server Administrator. You cannot place cuffs them.",GetName(i),i);
            
SendClientMessage(playerid,COLOR_ERROR,string);
            return 
1;
        }
        if(
IsCuffed[i] == && cuff_arrest_time[i] != 0) return 1;
        if(
IsCuffed[i] == && cuff_arrest_time[i] == 0)
        {
                
ARREST(playerid,i);
        }
        
CUFF(playerid,i);
    }
    return 
1;
}
stock GetClosestPlayer(playerid) {
    new 
idx=-1,Float:x,Float:y,Float:z;
    
GetPlayerPos(playerid,x,y,z);
    for(new 
i=GetPlayerPoolSize()+1,Float:tmp,Float:max=3000.0; --i!=-1; ) {
        if(!
IsPlayerConnected(i) || IsPlayerNPC(i) || i==playerid) continue;
        
tmp GetPlayerDistanceFromPoint(i,x,y,z);
        if(
tmp maxmax=tmp,idx=i;
    }
    return 
idx;

TNX MEN I fix it

ps: Pottus stop playing script hero help me or shut up
Reply
#9

Quote:
Originally Posted by Pottus
Посмотреть сообщение
That isn't even close to solved.
What is wrong withe calibers code?

That for loop looks strange to me.
Reply
#10

Quote:
Originally Posted by Pottus
Посмотреть сообщение
That isn't even close to solved.
As you can see..it's right


Quote:
Originally Posted by Mowgli;
That for loop looks strange to me.
Yeah it looks strange..but, it is very fast & right
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)