/enter command not checking positions.
#1

Hello. I made a /enter command for my house system.. Will make it for all soon, but now..
The problem is that it tells i am not near any house, even if i do.

pawn Code:
CMD:enter(playerid, params[])
{
    for(new i = 0; i < sizeof(HouseInfo); i++)
    {
        if(IsPlayerInRangeOfPoint(playerid, 10.0, HouseInfo[i][X], HouseInfo[i][Y], HouseInfo[i][Z]))
        {
            if(HouseInfo[i][Lock] == 0)
            {
                SetPlayerPos(playerid, HouseInfo[i][IntX], HouseInfo[i][IntY], HouseInfo[i][IntZ]);
                SetPlayerInterior(playerid, HouseInfo[i][Int]);
                SetPlayerVirtualWorld(playerid, HouseInfo[i][Vw]);
                return 1;
            }
            else return SendClientMessage(playerid, 0xFFFFFFFF, "This house is locked.");
        }
        else return SendClientMessage(playerid, 0xFFFFFFFF, "You are not near a house.");
    }
    return 1;
}
Tried all... Also tried make a command to laod HouseInfo.. the LoadHouses is like that:
pawn Code:
//LoadHouses
forward LoadHouses();
public LoadHouses()
{
    for(new i = 1; i < sizeof(HouseInfo); i++)
    {
        format(file, sizeof(file), "RRP/houses/%d.ini", i);
        if(fexist(file))
        {
            HouseInfo[i][X] = dini_Int(file, "X");
            HouseInfo[i][Y] = dini_Int(file, "Y");
            HouseInfo[i][Z] = dini_Int(file, "Z");
            HouseInfo[i][Int] = dini_Int(file, "Int");
            HouseInfo[i][Vw] = dini_Int(file, "Vw");
            HouseInfo[i][Owner] = dini_Int(file, "Owner");
            HouseInfo[i][Lock] = dini_Int(file, "Lock");
            HouseInfo[i][Price] = dini_Int(file, "Price");
            HouseInfo[i][IntX] = dini_Int(file, "IntX");
            HouseInfo[i][IntY] = dini_Int(file, "IntY");
            HouseInfo[i][IntZ] = dini_Int(file, "IntZ");
        }
    }
    print("[RRP]: Houses Loadeds");
    return 1;
}
Reply
#2

how many times do we need to tell you..

dont use return 1; inside a loop!

pawn Code:
CMD:enter(playerid, params[])
{
    for(new i = 0; i < sizeof(HouseInfo); i++)
    {
        if(IsPlayerInRangeOfPoint(playerid, 10.0, HouseInfo[i][X], HouseInfo[i][Y], HouseInfo[i][Z]))
        {
            if(HouseInfo[i][Lock] == 0)
            {
                SetPlayerPos(playerid, HouseInfo[i][IntX], HouseInfo[i][IntY], HouseInfo[i][IntZ]);
                SetPlayerInterior(playerid, HouseInfo[i][Int]);
                SetPlayerVirtualWorld(playerid, HouseInfo[i][Vw]);
                return 1;  //REMOVE THIS LINE
            }
            else return SendClientMessage(playerid, 0xFFFFFFFF, "This house is locked.");
        }
        else return SendClientMessage(playerid, 0xFFFFFFFF, "You are not near a house.");
    }
    return 1;
}
Reply
#3

Ohhh. xD Thank you.
Reply
#4

That's still wrong though. In fact, that return 1 can stay as the correct house has been found and no further checking is required. The culprit is this line:
pawn Code:
else return SendClientMessage(playerid, 0xFFFFFFFF, "You are not near a house.");
If you're not near the very first house, the script will jump to this line, send the message and then exit the loop without checking any further houses.
Reply
#5

REMOVED
Reply
#6

Quote:
Originally Posted by Vince
View Post
That's still wrong though. In fact, that return 1 can stay as the correct house has been found and no further checking is required. The culprit is this line:
pawn Code:
else return SendClientMessage(playerid, 0xFFFFFFFF, "You are not near a house.");
If you're not near the very first house, the script will jump to this line, send the message and then exit the loop without checking any further houses.
Explain that please.
Reply
#7

Quote:
Originally Posted by milanosie
View Post
Explain that please.
Look:
pawn Code:
CMD:enter(playerid, params[])
{
    for(new i = 0; i < sizeof(HouseInfo); i++)
    {
        if(IsPlayerInRangeOfPoint(playerid, 10.0, HouseInfo[i][X], HouseInfo[i][Y], HouseInfo[i][Z]))
        {
            if(HouseInfo[i][Lock] == 0)
            {
                SetPlayerPos(playerid, HouseInfo[i][IntX], HouseInfo[i][IntY], HouseInfo[i][IntZ]);
                SetPlayerInterior(playerid, HouseInfo[i][Int]);
                SetPlayerVirtualWorld(playerid, HouseInfo[i][Vw]);
                return 1;
            }
            else return SendClientMessage(playerid, 0xFFFFFFFF, "This house is locked.");
        }
        else return SendClientMessage(playerid, 0xFFFFFFFF, "You are not near a house.");
    }
    return 1;
}
That's the original code. Now I will make it different so that you might understand it.
pawn Code:
CMD:enter(playerid, params[]) //The command is performed
{
    for(new i = 0; i < sizeof(HouseInfo); i++) //Loop through the variable HouseInfo (=300)
    {
        if(IsPlayerInRangeOfPoint(playerid, 10.0, HouseInfo[i][X], HouseInfo[i][Y], HouseInfo[i][Z])) //Is the player in the X+Y+Z? (Range 10 - Way too big)
        {
            if(HouseInfo[i][Lock] == 0) //When the variable 'Lock' is 0 (unlocked)
            {
                SetPlayerPos(playerid, HouseInfo[i][IntX], HouseInfo[i][IntY], HouseInfo[i][IntZ]);
                SetPlayerInterior(playerid, HouseInfo[i][Int]);
                SetPlayerVirtualWorld(playerid, HouseInfo[i][Vw]); //Set pos etc
                return 1;
            }
            else //When the house is locked
            {
                SendClientMessage(playerid, 0xFFFFFFFF, "This house is locked.");
                return 1; //The return! Does the same as 'return SendClientMessage...' in the previous command. Loop stopped
            }
        }
        else //When the player ain't near a house
        {
            SendClientMessage(playerid, 0xFFFFFFFF, "You are not near a house.");
            return 1; //Again...
        }
    }
    return 1;
}
This code is exactly doing the same. In fact, this is what the code Ricardo provided actually does.
Reply
#8

Oh, just now I made this image.

Reply
#9

Quote:
Originally Posted by Vince
View Post
Oh, just now I made this image.

isnt that what I said there?
Reply
#10

Like, this is my /enter cmd with House AND business.

pawn Code:
CMD:enter(playerid, params[])
{
    for(new h=0; h<sizeof(House); h++)
    {
    if(IsPlayerInRangeOfPoint(playerid, 3, House[h][henx], House[h][heny], House[h][henz]))
    {
        if(IsInHouse[playerid] == 0)
        {
            if(House[h][hlocked] == 0)
            {
                GetPlayerPos(playerid, PP[playerid], PP2[playerid], PP3[playerid]);
                SetPlayerPos(playerid, House[h][hexx], House[h][hexy], House[h][hexz]);
                SetPlayerInterior(playerid, House[h][hint]);
                SetPlayerVirtualWorld(playerid, House[h][hvw]);
                IsInHouse[playerid] = 1;
                IsInHouseID[playerid] = h;
            }
            else return SendClientMessage(playerid, COLOR_GREY, "This house is locked!");
        }
    }
    for(new b = 0; b < sizeof(BizzInfo); b++)
    {
    if(IsPlayerInRangeOfPoint(playerid, 2, BizzInfo[b][benx], BizzInfo[b][beny], BizzInfo[b][benz]))
    {
        if(IsInBizz[playerid] == 0)
        {
            if(BizzInfo[b][bopen] == 1)
            {
                if(BizzInfo[b][bprods] >= 1)
                {
                    if(BizzInfo[b][btype] != 6 && BizzInfo[b][btype] != 7)
                    {
                    GetPlayerPos(playerid, PP[playerid], PP2[playerid], PP3[playerid]);
                    SetPlayerPos(playerid, BizzInfo[b][bexx], BizzInfo[b][bexy], BizzInfo[b][bexz]);
                    SetPlayerInterior(playerid, BizzInfo[b][bint]);
                    SetPlayerVirtualWorld(playerid, BizzInfo[b][bvw]);
                    IsInBizz[playerid] = 1;
                    GivePlayerMinusCash(playerid, BizzInfo[b][bfee]);
                    BizzInfo[b][bbank] = BizzInfo[b][bbank] + BizzInfo[b][bfee];
                    IsInBizzID[playerid] = b;
                    BizzInfo[b][customers] = BizzInfo[b][customers] + 1;
                    IsInBizzType[playerid] = BizzInfo[b][btype];
                    BizzInfo[b][bprods] = BizzInfo[b][bprods] -1;
                    }
                    else return SendClientMessage(playerid, COLOR_GREY, "Can't enter this business!");
                }
                else return SendClientMessage(playerid, COLOR_GREY, "This business is out of stock!");
            }
            else return SendClientMessage(playerid, COLOR_GREY, "Business is Closed!!");
        }
    }
    }
    }
    return 1;
}
Aint this just what I said? It works perfect.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)