OnPlayerKeyStateChange not processing the key pressed?
#1

Hey guys. I'm working on three different types of jobs. And I want to active them all by pressing Y. However when I press Y in the server, in the correct vehicle nothing happens...

All the code was working perfectly under commands. However now when I add the fact that the player has to press a key it doesn't work. Any ideas?

PHP код:
public OnPlayerKeyStateChange(playeridnewkeysoldkeys)
{
    if(
PRESSED(KEY_YES))
    {
        if(
GetVehicleModel(GetPlayerVehicleID(playerid)) == 482)
        {
            if(
GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
            {
                 new 
rand random(sizeof(DeliveryCP));
                if(
InJob[playerid] == true) return SendClientMessage(playerid0xFF0000FF"You're currently in a mission. Please finish it to start another delivery.");
                if(
GetVehicleModel(GetPlayerVehicleID(playerid)) == 482)
                {
                    
InJob[playerid] = true;
                    
DeliveryMan[playerid] = true;
                    
SetPlayerCheckpoint(playeridDeliveryCP[rand][0], DeliveryCP[rand][1], DeliveryCP[rand][2], 1.5);
                     
GameTextForPlayer(playerid"~w~COURIER JOB STARTED. DELIVER PACKAGE TO ~n~~r~RED ~w~CHECKPOINT"50003); 
                     
SendClientMessage(playerid0x76EEC6FF"* You can stop the delivery mission by typing /stopwork");
                }
             }
        }
        if(
GetVehicleModel(GetPlayerVehicleID(playerid)) == 407)
        {
            if(
GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
            {
                
FiremanJob[playerid] = 1;
                
GameTextForPlayer(playerid"~w~FIRE FIGHTER JOB STARTED. DRIVE TO THE ~n~~r~RED ~w~CHECKPOINT"50003); 
                
SendClientMessage(playerid0x76EEC6FF"* You can stop the delivery mission by typing /stopwork");
                
SetPlayerCheckpoint(playerid,1099.0345,-1194.4751,18.1079,4);
                
GivePlayerWeapon(playerid4299999);
            }
        }
        if(
GetVehicleModel(GetPlayerVehicleID(playerid)) == 420 || GetVehicleModel(GetPlayerVehicleID(playerid)) == 438)
        {
            if(
GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
            {
                new 
formatted[128];
                
OnDuty[playerid] = 1;
                
CreatePlayerDraws(playerid);
                
SendClientMessage(playerid,COLOR_WHITE,"You are now on duty!");
                
SendClientFormattedMessageToAll(COLOR_GREEN"ATTENTION: %s is now a Taxi Driver!"GetName(playerid), "");
                
format(formatted,128,"Start fare: %.2f$",STARTAMOUNT);
                
TextDrawSetString(startfare[playerid],formatted);
                
TextDrawSetString(taxistatus[playerid],"Taxi Status: Free");
                new 
format100[128];
                
format(format100,128,"100 Meter price: %.2f$",MONEYPER100);
                
TextDrawSetString(taxi100mfare[playerid],format100);
            }
        }
    }
    return 
1;

Reply
#2

Tell Me Have You Tried To Sit In All Vehicle.If No In Which Vehicle U Sit To Test It.
Reply
#3

Try Using This I Am Just Giving U An Example
Код:
new vid=GetVehicleModel(GetPlayerVehicleID(playerid));
if(vid == 482 ...
Reply
#4

I've tried in vehicles that match the ID's and also ones that don't. How will assigning a variable to the function change anything? It's just shortening it.
Reply
#5

It doesn't, but you should be saving the model ID of the vehicle you are inside in a variable in the first place. Since those functions do instructions, and the variable just stores the value which will always be the same.

You should also learn how to debug, that will help you see what runs, what doesn't, what turns out to be true, what doesn't, and so on.
Reply
#6

Code
Reply
#7

Quote:
Originally Posted by CarRamper
Посмотреть сообщение
Code
Are u Mad CarRamper

Try This
Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
  if ((newkeys & KEY_FIRE) && !(oldkeys & KEY_FIRE))
  {
    if(PRESSED(KEY_YES))
    {
        if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 482)
        {
            if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
            {
                 new rand = random(sizeof(DeliveryCP));
                if(InJob[playerid] == true) return SendClientMessage(playerid, 0xFF0000FF, "You're currently in a mission. Please finish it to start another delivery.");
                if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 482)
                {
                    InJob[playerid] = true;
                    DeliveryMan[playerid] = true;
                    SetPlayerCheckpoint(playerid, DeliveryCP[rand][0], DeliveryCP[rand][1], DeliveryCP[rand][2], 1.5);
                     GameTextForPlayer(playerid, "~w~COURIER JOB STARTED. DELIVER PACKAGE TO ~n~~r~RED ~w~CHECKPOINT", 5000, 3);
                     SendClientMessage(playerid, 0x76EEC6FF, "* You can stop the delivery mission by typing /stopwork");
                }
             }
        }
        if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 407)
        {
            if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
            {
                FiremanJob[playerid] = 1;
                GameTextForPlayer(playerid, "~w~FIRE FIGHTER JOB STARTED. DRIVE TO THE ~n~~r~RED ~w~CHECKPOINT", 5000, 3);
                SendClientMessage(playerid, 0x76EEC6FF, "* You can stop the delivery mission by typing /stopwork");
                SetPlayerCheckpoint(playerid,1099.0345,-1194.4751,18.1079,4);
                GivePlayerWeapon(playerid, 42, 99999);
            }
        }
        if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 420 || GetVehicleModel(GetPlayerVehicleID(playerid)) == 438)
        {
            if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
            {
                new formatted[128];
                OnDuty[playerid] = 1;
                CreatePlayerDraws(playerid);
                SendClientMessage(playerid,COLOR_WHITE,"You are now on duty!");
                SendClientFormattedMessageToAll(COLOR_GREEN, "ATTENTION: %s is now a Taxi Driver!", GetName(playerid), "");
                format(formatted,128,"Start fare: %.2f$",STARTAMOUNT);
                TextDrawSetString(startfare[playerid],formatted);
                TextDrawSetString(taxistatus[playerid],"Taxi Status: Free");
                new format100[128];
                format(format100,128,"100 Meter price: %.2f$",MONEYPER100);
                TextDrawSetString(taxi100mfare[playerid],format100);
            }
        }
    }
    return 1;
}
Reply
#8

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
It doesn't, but you should be saving the model ID of the vehicle you are inside in a variable in the first place. Since those functions do instructions, and the variable just stores the value which will always be the same.

You should also learn how to debug, that will help you see what runs, what doesn't, what turns out to be true, what doesn't, and so on.
I debugged it and it came out like this.

PHP код:
[07:43:16] [debugRun time error 4"Array index out of bounds"
[07:43:16] [debug]  Attempted to read/write array element at index 65535 in array of size 50
[07:43:16] [debugAMX backtrace:
[
07:43:16] [debug#0 00099e30 in public CB_OnPlayerStateChange (0, 1, 2) from vR.amx
[07:43:16] [debug#1 0001d160 in ?? (0, 1, 2) from vR.amx
[07:43:16] [debug#2 00006d48 in public OnPlayerStateChange (0, 1, 2) from vR.amx 
Reply
#9

Hi You Said That When U Make It Cmd It Works So Convert It into Cmd And Then Do Like This In OnPlayerKeyStateChange
i Am Just Giving U An example.
Код:
if(newkeys & KEY_YES)
	        {
	        if(gTeam[playerid] == TEAM_COP)
            {
            CallLocalFunction( "cmd_ar", "d", playerid);
            return 1;
         	}
         	}

         	if(newkeys & KEY_NO)
	        {
	        if(gTeam[playerid] == TEAM_COP)
            {
            CallLocalFunction( "cmd_tk", "d", playerid);
            return 1;
         	}
         	}
Reply
#10

Quote:
Originally Posted by Tass007
Посмотреть сообщение
I debugged it and it came out like this.

PHP код:
[07:43:16] [debugRun time error 4"Array index out of bounds"
[07:43:16] [debug]  Attempted to read/write array element at index 65535 in array of size 50
[07:43:16] [debugAMX backtrace:
[
07:43:16] [debug#0 00099e30 in public CB_OnPlayerStateChange (0, 1, 2) from vR.amx
[07:43:16] [debug#1 0001d160 in ?? (0, 1, 2) from vR.amx
[07:43:16] [debug#2 00006d48 in public OnPlayerStateChange (0, 1, 2) from vR.amx 
Then there's your problem! Fix the error.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)