OnPlayerKeyStateChange is not working for dynamic entrances
#1

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.
Reply
#2

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)
Reply
#3

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.
Reply
#4

If the commands work, just return them under OkPlayerKeyStateChange.
Reply
#5

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.
Reply
#6

Use only one callback, not two.
Reply
#7

I'm using one callback. OnPlayerKeyStateChange..
Reply
#8

Any suggestions?
Reply
#9

Not that callback, this callback:

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

}
Reply
#10

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)