What's wrong with this?
#1

Hello. Here is my stock:

pawn Код:
stock IsPlayerNearHouse(playerid)
{
    if(IsPlayerConnected(playerid))
    {
        for(new i = 0; i < MAX_HOUSES; i++)
        {
            if(IsPlayerInRangeOfPoint(playerid, 1, HouseInfo[i][hEnterPos][0], HouseInfo[i][hEnterPos][1], HouseInfo[i][hEnterPos][2]))
            {
                return 1;
            }
        }
    }
    return 0;
}
Then the enter command:

pawn Код:
CMD:enter(playerid, params[])
{
    if(IsPlayerNearHouse(playerid))
    {
        for(new i = 0; i < MAX_HOUSES; i++)
        {
            SetPlayerPos(playerid, HouseInfo[i][hExitPos][0], HouseInfo[i][hExitPos][1], HouseInfo[i][hExitPos][2]);
            SetPlayerInterior(playerid, HouseInfo[i][hInterior]);
        }
    }
    else
    {
        SendClientMessage(playerid, COLOR_RED, "Error"White": You are not near an entrance point.");
        return 1;
    }
    return 1;
}
It knows when I'm near the house or not, but when I am near the house and /enter it teleports me in the air.
Reply
#2

It is teleporting you to every house in the array. Make your IsPlayerNearHouse return the loop index (i) and use that to setPlayerPos.
Reply
#3

This basicly will teleport you MAX_HOUSES times.
Reply
#4

Quote:
Originally Posted by mamorunl
Посмотреть сообщение
It is teleporting you to every house in the array. Make your IsPlayerNearHouse return the loop index (i) and use that to setPlayerPos.
You mean put SetPlayerPos inside the stock?
I did this now:

pawn Код:
stock IsPlayerNearHouse(playerid)
{
    if(IsPlayerConnected(playerid))
    {
        for(new i = 0; i < MAX_HOUSES; i++)
        {
            if(IsPlayerInRangeOfPoint(playerid, 1, HouseInfo[i][hEnterPos][0], HouseInfo[i][hEnterPos][1], HouseInfo[i][hEnterPos][2]))
            {
                return 1;
            }
        }
    }
    return i; // Changed this to i
}
Reply
#5

pawn Код:
stock IsPlayerNearHouse(playerid) // If a player is near a house, it will return the slot else -1
{
    for(new i = 0; i < MAX_HOUSES; i++)
    {
        if(IsPlayerInRangeOfPoint(playerid, 1, HouseInfo[i][hEnterPos][0], HouseInfo[i][hEnterPos][1], HouseInfo[i][hEnterPos][2]))
        {
            return i;
        }
    }
    return -1;
}

CMD:enter(playerid, params[])
{
    new i = IsPlayerNearHouse(playerid);
    if (i != -1)
    {
        SetPlayerPos(playerid, HouseInfo[i][hExitPos][0], HouseInfo[i][hExitPos][1], HouseInfo[i][hExitPos][2]);
        SetPlayerInterior(playerid, HouseInfo[i][hInterior]);
    }
    else SendClientMessage(playerid, COLOR_RED, "Error"White": You are not near an entrance point.");
    return 1;
}
Reply
#6

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
pawn Код:
stock IsPlayerNearHouse(playerid) // If a player is near a house, it will return the slot else -1
{
    for(new i = 0; i < MAX_HOUSES; i++)
    {
        if(IsPlayerInRangeOfPoint(playerid, 1, HouseInfo[i][hEnterPos][0], HouseInfo[i][hEnterPos][1], HouseInfo[i][hEnterPos][2]))
        {
            return i;
        }
    }
    return -1;
}

CMD:enter(playerid, params[])
{
    new i = IsPlayerNearHouse(playerid);
    if (i != -1)
    {
        SetPlayerPos(playerid, HouseInfo[i][hExitPos][0], HouseInfo[i][hExitPos][1], HouseInfo[i][hExitPos][2]);
        SetPlayerInterior(playerid, HouseInfo[i][hInterior]);
    }
    else SendClientMessage(playerid, COLOR_RED, "Error"White": You are not near an entrance point.");
    return 1;
}
Thanks man! I get it now.
Reply
#7

edit.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)