Binding problems
#6

Put it in a enum or just make a function, could be like this:

pawn Код:
// This is better to be used with a dynamic system, like from a file or MySQL

#define MAX_EAE 10 // Max enters and exits, increase as you put in more enters and exits

enum eae // Enum for Enters and Exits
{
    eInterior,
    Float:eEnterX,
    Float:eEnterY,
    Float:eEnterZ,
    eExterior,
    Float:eExitX,
    Float:eExitZ,
    Float:eExitY
}

/*
Use this if you are going to load dynamically from a file:
new EAE[MAX_EAE][eae]; // Create a global for the enum we just made.
*/


new EAE[MAX_EAE][eae] = {
{10, -1911.7417,828.6296,35.1732, 0, 363.0568,-74.9951,1001.5078}, // Burger Shot
{15, -2374.9663,909.7300,45.4453, 0, 207.8533,-110.9560,1005.1328}, // Binco
{10, -1605.5649, 711.5371, 13.8672, 0, 246.1845,110.3962, 1003.2257}, // SFPD
{17, -1989.0898,379.1354,36.2675, 0, -25.884498,-185.868988,1003.546875} // SFPD
};

stock EntersAndExits(playerid) // Function for checking if player is near entrance or exit
{
    for(new i = 0; i < MAX_EAE; i++) // Standard loop, which will loop till it finishes, or till it finds one
    {
        if(IsPlayerInRangeOfPoint(playerid, 3.0, EAE[i][eEnterX], EAE[i][eEnterY], EAE[i][eEnterZ])) // Checking if player is near an entrance
        {
            SetPlayerPos(playerid, EAE[i][eExitX], EAE[i][eExitY], EAE[i][eExitZ]); // Setting position and the interior
            SetPlayerInterior(playerid, EAE[i][eInterior]);
            break;
        }
        else if(IsPlayerInRangeOfPoint(playerid, 3.0, EAE[i][eExitX], EAE[i][eExitY], EAE[i][eExitZ])) // Checking if player is near an exit
        {
            SetPlayerPos(playerid, EAE[i][eEnterX], EAE[i][eEnterY], EAE[i][eEnterZ]); // Setting position and the exterior
            SetPlayerInterior(playerid, EAE[i][eInterior]);
            break;
        }
    }
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if((newkeys & KEY_CROUCH) && !(oldkeys & KEY_CROUCH)) // Check if key is being pressed and released
    {
        EntersAndExits(playerid); // Check if player is near an entrance or an exit
    }
    return 1;
}

// Commands
CMD:enter(playerid)
{
    EntersAndExits(playerid);
    return 1;
}

CMD:exit(playerid)
{
    EntersAndExits(playerid);
    return 1;
}
Now, that is one way to do, the most structual way I think,
but a simpler one might be to just add this under OnPlayerKeyStateChange:

pawn Код:
stock EntersAndExits(playerid);
{
    // Enters
    if(IsPlayerInRangeOfPoint(playerid, 5.0, -1911.7417,828.6296,35.1732)) // Burger Shot
    {
        SetPlayerInterior(playerid, 10);
        SetPlayerPos(playerid, 363.0568,-74.9951,1001.5078);
    }  // Burger Shot
    if(IsPlayerInRangeOfPoint(playerid, 5.0, -2374.9663,909.7300,45.4453)) // Binco
    {
        SetPlayerInterior(playerid, 15);
        SetPlayerPos(playerid, 207.8533,-110.9560,1005.1328);
    }
    if(IsPlayerInRangeOfPoint(playerid, 5.0, -1605.5649, 711.5371, 13.8672)) // SFPD
    {
        SetPlayerInterior(playerid, 10);
        SetPlayerPos(playerid, 246.1845,110.3962, 1003.2257);
    }
    if(IsPlayerInRangeOfPoint(playerid, 5.0, -1989.0898,379.1354,36.2675)) // SFPD
    {
        SetPlayerInterior(playerid, 17);
        SetPlayerPos(playerid, -25.884498,-185.868988,1003.546875);
    }
   
    // Exits
    if(IsPlayerInRangeOfPoint(playerid, 5.0, 363.0568,-74.9951,1001.5078))
    {
        SetPlayerVirtualWorld(playerid, 0);
        SetPlayerPos(playerid, -1911.7417,828.6296,35.1732);
        SetPlayerInterior(playerid, 0);
    }
    if(IsPlayerInRangeOfPoint(playerid, 5.0, 207.8533,-110.9560,1005.1328))
    {
        SetPlayerVirtualWorld(playerid, 0);
        SetPlayerPos(playerid, -2374.9663,909.7300,45.4453);
        SetPlayerInterior(playerid, 0);
    }
    if(IsPlayerInRangeOfPoint(playerid, 5.0, 246.1845,110.3962, 1003.2257))
    {
        SetPlayerVirtualWorld(playerid, 0);
        SetPlayerPos(playerid, -1605.5649, 711.5371, 13.8672);
        SetPlayerInterior(playerid, 0);
    }
    if(IsPlayerInRangeOfPoint(playerid, 5.0, -25.884498,-185.868988,1003.546875)) // SFPD
    {
        SetPlayerInterior(playerid, 17);
        SetPlayerPos(playerid, -1989.0898,379.1354,36.2675);
    }
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if((newkeys & KEY_CROUCH) && !(oldkeys & KEY_CROUCH)) // Check if key is being pressed and released
    {
        EntersAndExits(playerid); // Check if player is near entrance or exit
    }
    return 1;
}

// Then you can also keep your commands
CMD:enter(playerid)
{
    EntersAndExits(playerid);
    return 1;
}

CMD:exit(playerid)
{
    EntersAndExits(playerid);
    return 1;
}
If you use GetPlayerInterior, I can almost assure you it's going to be bugged. Let's take an example in the bank interior, which is 0, what will it do then?

It will try to enter a building, but it won't find anything, so you're stuck. If you want it to work that way, it becomes really hard to keep track of. Not saying that it's not an option though.
Reply


Messages In This Thread
Binding problems - by xXRealLegitXx - 16.04.2013, 22:20
Re: Binding problems - by Krx17 - 16.04.2013, 22:27
Re: Binding problems - by xXRealLegitXx - 16.04.2013, 22:51
Re: Binding problems - by Knappen - 17.04.2013, 00:12
Re: Binding problems - by Scenario - 17.04.2013, 00:16
Re: Binding problems - by Knappen - 17.04.2013, 00:28
Re: Binding problems - by xXRealLegitXx - 17.04.2013, 00:55
Re: Binding problems - by xXRealLegitXx - 17.04.2013, 00:59
Re: Binding problems - by Knappen - 17.04.2013, 01:36

Forum Jump:


Users browsing this thread: 1 Guest(s)