Binding problems
#1

Hello!

Today I want to make a bind for the commands /enter and /exit.

BUUUUT I want to make it so if you are in an interior, it will do /exit and not enter.

Here are the commands:

Код:
CMD:enter(playerid)
{
	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);
    }
	return 1;
}
CMD:exit(playerid)
{
	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;
}
I know how to bind things, but I want to make it so if you are not in an interior, /enter will bind to 'C' and if you are, /exit will bind to 'C'

Is this possible?
Reply
#2

Use GetPlayerInterior to see if a player is an interior or not. If it returns anything other than 0, the player is in an interior and that keys you to use the /exit command.
Reply
#3

Quote:
Originally Posted by Krx17
Посмотреть сообщение
Use GetPlayerInterior to see if a player is an interior or not. If it returns anything other than 0, the player is in an interior and that keys you to use the /exit command.
How would I use this to check if a player is in an interior?
Reply
#4

Give me 2 seconds, I will write a small snippet and try to explain... I will edit in a few minutes.

Edit: Was supposed to post that snippet here, but posted a new post by mistake. Sorry.
Reply
#5

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys & KEY_CROUCH) // checks to see if playerid pushed C
    {
        if(GetPlayerInterior(playerid) == 0) cmd_enter(playerid, ""); // is their interior equal to 0 (meaning they're outside)? If so, perform the /enter command
        else cmd_exit(playerid, ""); // otherwise, perform the /exit command
    }
    return 1;
}
Reply
#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
#7

Quote:
Originally Posted by RealCop228
Посмотреть сообщение
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys & KEY_CROUCH) // checks to see if playerid pushed C
    {
        if(GetPlayerInterior(playerid) == 0) cmd_enter(playerid, ""); // is their interior equal to 0 (meaning they're outside)? If so, perform the /enter command
        else cmd_exit(playerid, ""); // otherwise, perform the /exit command
    }
    return 1;
}
I am using this now, thank you!
Reply
#8

Quote:
Originally Posted by Knappen
Посмотреть сообщение
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.
I love your explanation, but I don't think I need something of those matters yet. In the future, if we find bugs where we are bugged with interiors, then I will add this script. But I don't think I need something like this now.

Thank you however, I really do appreciate this.
Reply
#9

No problem, happy to help!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)