How to create "Press F to enter the building"
#1

How do i code that when the user presses F near a door, he enters it without writing /enter, same with /exit.
Reply
#2

If you want to do this it would go under
OnPlayerKeyStateChange

http://forum.sa-mp.com/newreply.php?...te=1&p=2506411
Reply
#3

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if (newkeys & KEY_SECONDARY_ATTACK)
    {
        if (IsPlayerInRangeOfPoint(playerid, 3.0, 0.0, 0.0, 0.0)) // Replace 0.0, 0.0, 0.0 with your coords.
        {
            SetPlayerPos(playerid, 10.0, 20.0, 30.0);
        }
    }
    return 1;
}
Reply
#4

This way will work but is not very efficient if you have a lot of areas your better off using using the streamer plugin and adding areas in there then doing this.

pawn Код:
#define INVALID_AREA_ID (0xFFFF)

new CurrArea[MAX_PLAYERS] = { INVALID_AREA_ID, ... };

new myarea1, myarea2, myarea3;
public OnGameModeInit()
{
     myarea1 = CreateDynamicSphere(1.0, 1.0, 1.0, 2.0);
     myarea2 = CreateDynamicSphere(1.0, 1.0, 1.0, 2.0);
     myarea3 = CreateDynamicSphere(1.0, 1.0, 1.0, 2.0);
}

public OnPlayerEnterDynamicArea(playerid, areaid) { CurrArea[playerid] = areaid; }
public OnPlayerLeaveDynamicArea(playerid, areaid) { CurrArea[playerid] = INVALID_AREA_ID ; }

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if (newkeys & KEY_SECONDARY_ATTACK)
    {
         if(CurrArea[playerid] != INVALID_AREA_ID)
         {
               switch(CurrArea[playerid])
               {
                    case myarea1: { SetPlayerPosEx(playerid, 0.0, 0.0, 0.0, 0.0, 0, 0); }
                    case myarea2: { SetPlayerPosEx(playerid, 0.0, 0.0, 0.0, 0.0, 0, 0); }
                    case myarea3: { SetPlayerPosEx(playerid, 0.0, 0.0, 0.0, 0.0, 0, 0); }
               }
         }
    }
    return 1;
}

stock SetPlayerPosEx(playerid, Float:x, Float:y, Float:z, Float:fa, vw, int)
{
    SetPlayerPos(playerid, x, y, z);
    SetPlayerFacingAngle(playerid, fa);
    SetPlayerVirtualWorld(playerid, vw);
    SetPlayerInterior(playerid, int);
    SetCameraBehindPlayer(playerid);
}
That is far better than checking point ranges every time even if the player is not even near a point.
Reply
#5

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
This way will work but is not very efficient if you have a lot of areas your better off using using the streamer plugin and adding areas in there then doing this.

pawn Код:
#define INVALID_AREA_ID (0xFFFF)

new myarea1, myarea2, myarea3;
public OnGameModeInit()
{
     myarea1 = CreateDynamicSphere(1.0, 1.0, 1.0, 2.0);
     myarea2 = CreateDynamicSphere(1.0, 1.0, 1.0, 2.0);
     myarea3 = CreateDynamicSphere(1.0, 1.0, 1.0, 2.0);
}

public OnPlayerEnterDynamicArea(playerid, areaid) { CurrArea[playerid] = areaid; }
public OnPlayerLeaveDynamicArea(playerid, areaid) { CurrArea[playerid] = INVALID_AREA_ID ; }

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if (newkeys & KEY_SECONDARY_ATTACK)
    {
         if(CurrArea[playerid] != INVALID_AREA_ID)
         {
               switch(CurrArea[playerid])
               {
                    case myarea1: { SetPlayerPosEx(playerid, 0.0, 0.0, 0.0, 0.0, 0, 0); }
                    case myarea2: { SetPlayerPosEx(playerid, 0.0, 0.0, 0.0, 0.0, 0, 0); }
                    case myarea3: { SetPlayerPosEx(playerid, 0.0, 0.0, 0.0, 0.0, 0, 0); }
               }
         }
    }
    return 1;
}

stock SetPlayerPosEx(playerid, Float:x, Float:y, Float:z, Float:fa, vw, int)
{
    SetPlayerPos(playerid, x, y, z);
    SetPlayerFacingAngle(playerid, fa);
    SetPlayerVirtualWorld(playerid, vw);
    SetPlayerInterior(playerid, int);
    SetCameraBehindPlayer(playerid);
}
That is far better than checking point ranges every time even if the player is not even near a point.
I haven't actually ever thought of doing it that way, that's quite smart!

You could make this even more efficient by putting each area into a custom foreach iterator, which you could loop through to determine if a player is in one of the enter/exit areas; it would be better and faster than looping through the amount of entrances/exits. Foreach uses the whole list thing...

My two cents.
Reply
#6

No real need for that since if they're not in an area it will only do two if statements although if they're in an area that is not an area that you can enter a building say it's a drop point then you'd have to weigh the trade off between checking through your foreach iterator vs doing the switch I think overall you'd actually be better off leaving it out since if your in an area that you can enter a building you wouldn't need to check the foreach iterator and still have to do the switch() anyways unless I'm missing something about your idea.
Reply
#7

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
No real need for that since if they're not in an area it will only do two if statements although if they're in an area that is not an area that you can enter a building say it's a drop point then you'd have to weigh the trade off between checking through your foreach iterator vs doing the switch I think overall you'd actually be better off leaving it out since if your in an area that you can enter a building you wouldn't need to check the foreach iterator and still have to do the switch() anyways unless I'm missing something about your idea.
I think I see what you're saying. Never mind me then!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)