OnPlayerKeyStateChange
#1

Hi!

I have a problem in my gamemode,when i type '2' or 'mmb' (key submission), i not give the message with "No suspects in range". how to solve it?

Code:
if((newkeys == KEY_SUBMISSION) && isLEO(playerid))
    {
        foreach(new i : Player)
        {
            new msg[100];
            if(GetDistanceBetweenPlayers(playerid, i) < 7.0 && Player[i][playerWanted] < 6 && Player[i][playerWanted] != 0)
            {
                format(msg, 100, "/ticket %d", i);
            	return OnPlayerCommandReceived(playerid, msg);
			}
			if(GetDistanceBetweenPlayers(playerid, i) < 7.0 && Player[i][playerWanted] > 5)
			{
			    format(msg, 100, "/arrest %d", i);
			    return OnPlayerCommandReceived(playerid, msg);
			}
			else
			{
				SendClientMessage(playerid, COLOR_RED, "No suspects in range.");
				break;
			}
        }
    }
    if((newkeys == KEY_SUBMISSION) && IsNowTicketed[playerid] == true)
    {
        new msg[78];
        format(msg, 100, "/payticket %d", TicketCop[playerid]);
    	return OnPlayerCommandReceived(playerid, msg);
    }
Reply
#2

First of all that's not the way to check for keys
https://sampwiki.blast.hk/wiki/OnPlayer...heck_for_a_key

After you've done with that try debugging, after every if() use a print to see where the code is getting executed.
If you don't read a print that snippet isn't executed and so you need to edit your if()s.
Reply
#3

PHP Code:
if(newkeys KEY_SUBMISSION)
  
    {
       if(!
isLEO(playerid)) return 0;
        foreach(new 
Player)
        {
            new 
msg[100];
            if(
GetDistanceBetweenPlayers(playeridi) < 7.0 && Player[i][playerWanted] < && Player[i][playerWanted] != 0)
            {
                
format(msg100"/ticket %d"i);
                return 
OnPlayerCommandReceived(playeridmsg);
            }
            if(
GetDistanceBetweenPlayers(playeridi) < 7.0 && Player[i][playerWanted] > 5)
            {
                
format(msg100"/arrest %d"i);
                return 
OnPlayerCommandReceived(playeridmsg);
            }
            else
            {
                
SendClientMessage(playeridCOLOR_RED"No suspects in range.");
                break;
            }
        }
    }
    if(
newkeys KEY_SUBMISSION)
    {
       if(
IsNowTicketed[playerid] == false) return 0;
        new 
msg[78];
        
format(msg100"/payticket %d"TicketCop[playerid]);
        return 
OnPlayerCommandReceived(playeridmsg);
    } 
and you can use onplayercommandtext instead donno why you use commandreceived
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)