Nothing happens - OnPlayerKeyStateChange
#1

I created this "Interior" script for the vehicle "Journey".
Basically, whenever you press 'Y' while next to the "Journey", it should place you in its interior ( custom map ).

But the problem is, that nothing is happening.
I've tried changing the "newkeys & KEY_***" to "newkeys == KEY_***", but that doesn't work either.
I'm guessing the problem is in the loop, but I don't see any problem there d:
code;
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys & KEY_YES)
    {
        new Float:X, Float:Y, Float:Z;
        GetPlayerPos(playerid, X,Y,Z);
        for(new i=1;i<MAX_VEHICLES;i++)
        {
            if(GetVehicleModel(i) == 508)
            {
                new Float:fDistance = GetVehicleDistanceFromPoint(i, X, Y, Z);
                if(fDistance < 5)
                {
                    ExitX[playerid] = X, ExitY[playerid] = Y, ExitZ[playerid] = Z;
                    SetPlayerPos(playerid, -360.6434,-1499.0181,516.6295), SetPlayerVirtualWorld(playerid, 1);
                    SetCameraBehindPlayer(playerid);
                    SendClientMessage(playerid, COLOR_NOTES, "[INFO] You've entered the 'Journey', to leave it, press 'N'.");
                    return 1;
                }
            }
        }
    }
    if(newkeys & KEY_NO)
    {
        new Float:X, Float:Y, Float:Z;
        GetPlayerPos(playerid, X,Y,Z);
        if(IsPlayerInRangeOfPoint(playerid, 8, -360.6434,-1499.0181,516.6295))
        {
            SetPlayerPos(playerid, ExitX[playerid], ExitY[playerid], ExitZ[playerid]), SetPlayerVirtualWorld(playerid, 0);
            SendClientMessage(playerid, COLOR_NOTES, "[INFO] You've left the 'Journey's' interior.");
            return 1;
        }
    }
    return 1;
}
Reply
#2

make sure its in GM script
if not then make sure that in GM script OnKeyStateChange there is no return 0; in it
Reply
#3

Quote:
Originally Posted by BroZeus
Посмотреть сообщение
make sure its in GM script
if not then make sure that in GM script OnKeyStateChange there is no return 0; in it
It is, and there are only 'return 1;'
Reply
#4

try
PHP код:
//---[Keys]
#define PRESSED(%0) (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
public OnPlayerKeyStateChange(playeridnewkeysoldkeys)
{
  if(
PRESSED(KEY_YES))
  {
    new 
Float:XFloat:YFloat:Z;        
    
GetPlayerPos(playeridX,Y,Z);        
    for(new 
i=0;i<MAX_VEHICLES;i++)        
    {
                  
      if(
GetVehicleModel(i) == 508)            
      {                
        new 
Float:fDistance GetVehicleDistanceFromPoint(iXYZ);                
        if(
fDistance <= 5)                
        {                    
           
ExitX[playerid] = XExitY[playerid] = YExitZ[playerid] = Z;                    
           
SetPlayerPos(playerid, -360.6434,-1499.0181,516.6295);
           
SetPlayerVirtualWorld(playerid1);
           
SetCameraBehindPlayer(playerid);                    
           
SendClientMessage(playeridCOLOR_NOTES"[INFO] You've entered the 'Journey' to leave it,
press 'N'."
);                                    
       }            
    }        
 }
return 
1
edited try it now
Reply
#5

debug the code
put print("[DEBUG]:Y key pressed");
after "if" check of Y key and like this print distance using printf() function and see what it prints
Reply
#6

Quote:
Originally Posted by Pillhead2007
Посмотреть сообщение
try
PHP код:
//---[Keys]
#define PRESSED(%0) (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
public OnPlayerKeyStateChange(playeridnewkeysoldkeys)
{
  if(
PRESSED(KEY_YES))
  {
    new 
Float:XFloat:YFloat:Z;        
    
GetPlayerPos(playeridX,Y,Z);        
    for(new 
i=0;i<MAX_VEHICLES;i++)        
    {            
      if(
GetVehicleModel(i) == 508)            
      {                
        new 
Float:fDistance GetVehicleDistanceFromPoint(iXYZ);                
        if(
fDistance 5)                
        {                    
           
ExitX[playerid] = XExitY[playerid] = YExitZ[playerid] = Z;                    
           
SetPlayerPos(playerid, -360.6434,-1499.0181,516.6295), SetPlayerVirtualWorld(playerid1);
           
SetCameraBehindPlayer(playerid);                    
           
SendClientMessage(playeridCOLOR_NOTES"[INFO] You've entered the 'Journey' to leave it,
press 'N'."
);                    
          return 
1;                
       }            
    }        
 } 
Still the same.
@ZeuS, alright, will try that.
Reply
#7

edited my originalpost
Reply
#8

Pillhead, that wasn't it, thanks though.
Repped you both

The debugging helped a lot, turns out that the Group scripts supplydrop was blocking it to get to the Interior stuff
Reply
#9

no worries
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)