SA-MP Forums Archive
Nothing happens - OnPlayerKeyStateChange - 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)
+--- Thread: Nothing happens - OnPlayerKeyStateChange (/showthread.php?tid=523477)



Nothing happens - OnPlayerKeyStateChange - Kyance - 02.07.2014

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;
}



Re: Nothing happens - OnPlayerKeyStateChange - BroZeus - 02.07.2014

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


Re: Nothing happens - OnPlayerKeyStateChange - Kyance - 02.07.2014

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;'


Re: Nothing happens - OnPlayerKeyStateChange - Pillhead2007 - 02.07.2014

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


Re: Nothing happens - OnPlayerKeyStateChange - BroZeus - 02.07.2014

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


Re: Nothing happens - OnPlayerKeyStateChange - Kyance - 02.07.2014

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.


Re: Nothing happens - OnPlayerKeyStateChange - Pillhead2007 - 02.07.2014

edited my originalpost


Re: Nothing happens - OnPlayerKeyStateChange - Kyance - 02.07.2014

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


Re: Nothing happens - OnPlayerKeyStateChange - Pillhead2007 - 02.07.2014

no worries