SA-MP Forums Archive
OnPlayerKeyStateChange is not working for dynamic entrances - 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: OnPlayerKeyStateChange is not working for dynamic entrances (/showthread.php?tid=530981)



OnPlayerKeyStateChange is not working for dynamic entrances - Magic_Time - 10.08.2014

I've been working in a dynamic entrance/exit system.

I have the following cmds:

PHP код:
CMD:enter(playeridparams[])
{
    new 
id GetClosestStoreEntrance(playerid);
    if(
IsPlayerInRangeOfPoint(playerid3.0ZoneRBInfo[id][RBentranceX], ZoneRBInfo[id][RBentranceY], ZoneRBInfo[id][RBentranceZ]))
    {
        
SetPlayerPos(playeridZoneRBInfo[id][RBexitX], ZoneRBInfo[id][RBexitY], ZoneRBInfo[id][RBexitZ]);//Rob store exit
        
SetPlayerInterior(playeridZoneRBInfo[id][RBinterior]);
        
SetPlayerVirtualWorld(playeridZoneRBInfo[id][RBworld]);
        
StoreID[playerid] = id;
    }
    return 
1;
}
CMD:exit(playeridparams[])
{
    new 
di StoreID[playerid];
    if(
IsPlayerInRangeOfPoint(playerid3.0ZoneRBInfo[di][RBexitX], ZoneRBInfo[di][RBexitY], ZoneRBInfo[di][RBexitZ]))
    {
        
SetPlayerPos(playeridZoneRBInfo[di][RBentranceX], ZoneRBInfo[di][RBentranceY], ZoneRBInfo[di][RBentranceZ]);//Rob store entrance
        
SetPlayerInterior(playerid0);
        
SetPlayerVirtualWorld(playerid0);
    }
    return 
1;

Those cmds given above work great, however I want to set a lonely key to enter/exit. However, it only works for entering a interior but it doesn't work once you want to exit it.

PHP код:
public OnPlayerKeyStateChange(playeridnewkeysoldkeys)
{
    if(
PRESSED(KEY_SECONDARY_ATTACK))
    {
        new 
id GetClosestStoreEntrance(playerid);
        if(
IsPlayerInRangeOfPoint(playerid3.0ZoneRBInfo[id][RBentranceX], ZoneRBInfo[id][RBentranceY], ZoneRBInfo[id][RBentranceZ]))
        {
            
SetPlayerPos(playeridZoneRBInfo[id][RBexitX], ZoneRBInfo[id][RBexitY], ZoneRBInfo[id][RBexitZ]);//Rob store exit
            
SetPlayerInterior(playeridZoneRBInfo[id][RBinterior]);
            
SetPlayerVirtualWorld(playeridZoneRBInfo[id][RBworld]);
            
StoreID[playerid] = id;
        }
    }
    if(
PRESSED(KEY_SECONDARY_ATTACK))
    {
        new 
di StoreID[playerid];
        if(
IsPlayerInRangeOfPoint(playerid3.0ZoneRBInfo[di][RBexitX], ZoneRBInfo[di][RBexitY], ZoneRBInfo[di][RBexitZ]))
        {
            
SetPlayerPos(playeridZoneRBInfo[di][RBentranceX], ZoneRBInfo[di][RBentranceY], ZoneRBInfo[di][RBentranceZ]);//Rob store entrance
            
SetPlayerInterior(playerid0);
            
SetPlayerVirtualWorld(playerid0);
        }
    }
    return 
1;

Thanks for replying.


Re: OnPlayerKeyStateChange is not working for dynamic entrances - Dignity - 10.08.2014

Why not simplify the code? There's no need for two seperate commands or two seperate if(PRESSED) statements.

Try something like this:

pawn Код:
CMD:enterexit(playerid)
{
    new id = GetClosestStoreEntrance(playerid), di = StoreID[playerid];

    if(IsPlayerInRangeOfPoint(playerid, 3.0, ZoneRBInfo[id][RBentranceX], ZoneRBInfo[id][RBentranceY], ZoneRBInfo[id][RBentranceZ]))
    {
        SetPlayerPos(playerid, ZoneRBInfo[id][RBexitX], ZoneRBInfo[id][RBexitY], ZoneRBInfo[id][RBexitZ]);//Rob store exit
        SetPlayerInterior(playerid, ZoneRBInfo[id][RBinterior]);
        SetPlayerVirtualWorld(playerid, ZoneRBInfo[id][RBworld]);
        StoreID[playerid] = id;
    }

    else if(IsPlayerInRangeOfPoint(playerid, 3.0, ZoneRBInfo[di][RBexitX], ZoneRBInfo[di][RBexitY], ZoneRBInfo[di][RBexitZ]))
    {
        SetPlayerPos(playerid, ZoneRBInfo[di][RBentranceX], ZoneRBInfo[di][RBentranceY], ZoneRBInfo[di][RBentranceZ]);//Rob store entrance
        SetPlayerInterior(playerid, 0);
        SetPlayerVirtualWorld(playerid, 0);
    }
   
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(PRESSED(KEY_SECONDARY_ATTACK))
    {
        return cmd_enterexit(playerid);
    }
   
    return 1;
}
(might not work as I'm exhausted atm but you get the point)


Re: OnPlayerKeyStateChange is not working for dynamic entrances - Magic_Time - 10.08.2014

Hi thanks for replying.
I tried your code, but I'm getting the same error.

It might sound weird but it allows me to enter in the interior, but it doesn't allow me to exit the interior.

NOTE:
The commands I posted above work great, so it has to be something related to OnPlayerKeyStateChange.


Re: OnPlayerKeyStateChange is not working for dynamic entrances - Dignity - 10.08.2014

If the commands work, just return them under OkPlayerKeyStateChange.


Re: OnPlayerKeyStateChange is not working for dynamic entrances - Magic_Time - 10.08.2014

You might think I'm doing something wrong but I tried to return the cmds, but it didn't work.
It allows me to enter in the interior but not to exit it.


Re: OnPlayerKeyStateChange is not working for dynamic entrances - Dignity - 10.08.2014

Use only one callback, not two.


Re: OnPlayerKeyStateChange is not working for dynamic entrances - Magic_Time - 10.08.2014

I'm using one callback. OnPlayerKeyStateChange..


Re: OnPlayerKeyStateChange is not working for dynamic entrances - Magic_Time - 10.08.2014

Any suggestions?


Re: OnPlayerKeyStateChange is not working for dynamic entrances - Dignity - 10.08.2014

Not that callback, this callback:

pawn Код:
if(PRESSED(KEY_SECONDARY_ATTACK))
{

}



Re: OnPlayerKeyStateChange is not working for dynamic entrances - Magic_Time - 11.08.2014

Quote:
Originally Posted by Mionee
Посмотреть сообщение
Not that callback, this callback:

pawn Код:
if(PRESSED(KEY_SECONDARY_ATTACK))
{

}
I'm using just one and it doesn't work.