SA-MP Forums Archive
What's wrong with this? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: What's wrong with this? (/showthread.php?tid=509168)



What's wrong with this? - AphexCCFC - 25.04.2014

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.


Re: What's wrong with this? - mamorunl - 25.04.2014

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


Re: What's wrong with this? - ]Rafaellos[ - 25.04.2014

This basicly will teleport you MAX_HOUSES times.


Re: What's wrong with this? - AphexCCFC - 25.04.2014

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
}



Re: What's wrong with this? - Konstantinos - 25.04.2014

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;
}



Re: What's wrong with this? - AphexCCFC - 25.04.2014

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.


Re: What's wrong with this? - Galletziz - 25.04.2014

edit.