House system not working proply.
#1

Hey guys. I decided to continue my GM to get better in scripting but i still cant realize why /enter and /buyhouse only work on the house id 1... The cmd is:

pawn Код:
CMD:buyhouse(playerid, params[])
{
    if(PlayerInfo[playerid][HouseKey] == 9999)
    {
        for(new h = 1; h < sizeof(HouseInfo); h++)
        {
            if(IsPlayerInRangeOfPoint(playerid, 1.0, HouseInfo[h][X], HouseInfo[h][Y], HouseInfo[h][Z]))
            {
                new string[128], Name[MAX_PLAYER_NAME];
                GetPlayerName(playerid, Name, sizeof(Name));
                PlayerInfo[playerid][HouseKey] = h;
                HouseInfo[h][Owner] = GetPlayerName(playerid, Name, sizeof(Name));
                HouseInfo[h][Ownable] = 0;
                DestroyPickup(housepickup[h]);
                Delete3DTextLabel(housetext[h]);
                housepickup[h] = CreatePickup(1272, 1, HouseInfo[h][X], HouseInfo[h][Y], HouseInfo[h][Z], 0);
                format(string, sizeof(string), "This house is owned. Owner: %s", Name);
                housetext[h] = Create3DTextLabel(string, COLOR_RED, HouseInfo[h][X], HouseInfo[h][Y], HouseInfo[h][Z], 10.0, 0);
                format(file, sizeof(file), "RRP/houses/%d.ini", h);
                if(fexist(file))
                {
                    dini_Set(file, "Owner", Name);
                    dini_IntSet(file, "Ownable", 0);
                }
                format(file, sizeof(file), "RRP/users/%s.ini", Name);
                if(fexist(file))
                {
                    dini_IntSet(file, "HouseKey", h);
                }
            }
            else return SendClientMessage(playerid, 0xFFFFFFFF, "You are not near any house.");
        }
        return 1;
    }
    else return SendClientMessage(playerid, 0xFFFFFFFF, "You already own a house.");
}
Thanks
Reply
#2

else return SendClientMessage(playerid, 0xFFFFFFFF, "You are not near any house.");

DONT EVER return inside a loop if needs be continue such as

pawn Код:
else
{
     SendClientMessage(playerid, 0xFFFFFFFF, "You are not near any house.");
     continue;
}
Continue stops the code in the lop[ there and goes to the next number
return stops the loop and anything else under the loop.

EDIT: hat will spawn your client let me edit it properly I will update this post after.

EDIT: Here

pawn Код:
CMD:buyhouse(playerid, params[])
{
    if(PlayerInfo[playerid][HouseKey] == 9999)
    {
        for(new h = 1; h < sizeof(HouseInfo); h++)
        {
            if(IsPlayerInRangeOfPoint(playerid, 1.0, HouseInfo[h][X], HouseInfo[h][Y], HouseInfo[h][Z]))
            {
                new string[128], Name[MAX_PLAYER_NAME];
                GetPlayerName(playerid, Name, sizeof(Name));
                PlayerInfo[playerid][HouseKey] = h;
                HouseInfo[h][Owner] = GetPlayerName(playerid, Name, sizeof(Name));
                HouseInfo[h][Ownable] = 0;
                DestroyPickup(housepickup[h]);
                Delete3DTextLabel(housetext[h]);
                housepickup[h] = CreatePickup(1272, 1, HouseInfo[h][X], HouseInfo[h][Y], HouseInfo[h][Z], 0);
                format(string, sizeof(string), "This house is owned. Owner: %s", Name);
                housetext[h] = Create3DTextLabel(string, COLOR_RED, HouseInfo[h][X], HouseInfo[h][Y], HouseInfo[h][Z], 10.0, 0);
                format(file, sizeof(file), "RRP/houses/%d.ini", h);
                if(fexist(file))
                {
                    dini_Set(file, "Owner", Name);
                    dini_IntSet(file, "Ownable", 0);
                }
                format(file, sizeof(file), "RRP/users/%s.ini", Name);
                if(fexist(file))
                {
                    dini_IntSet(file, "HouseKey", h);
                }
                                                              else
                                                              {
                                                                         if(sizeof(HouseInfo) == i) SendClientMessage(playerid, 0xFFFFFFFF, "You are not near any house.");         }
        }
    }
    else return SendClientMessage(playerid, 0xFFFFFFFF, "You already own a house.");
}
Reply
#3

pawn Код:
CMD:buyhouse(playerid, params[])
{
    if(PlayerInfo[playerid][HouseKey] == 9999)
    {
        for(new h = 1; h < sizeof(HouseInfo); h++)
        {
            if(IsPlayerInRangeOfPoint(playerid, 1.0, HouseInfo[h][X], HouseInfo[h][Y], HouseInfo[h][Z]))
            {
                new string[128], Name[MAX_PLAYER_NAME];
                GetPlayerName(playerid, Name, sizeof(Name));
                PlayerInfo[playerid][HouseKey] = h;
                HouseInfo[h][Owner] = GetPlayerName(playerid, Name, sizeof(Name));
                HouseInfo[h][Ownable] = 0;
                DestroyPickup(housepickup[h]);
                Delete3DTextLabel(housetext[h]);
                housepickup[h] = CreatePickup(1272, 1, HouseInfo[h][X], HouseInfo[h][Y], HouseInfo[h][Z], 0);
                format(string, sizeof(string), "This house is owned. Owner: %s", Name);
                housetext[h] = Create3DTextLabel(string, COLOR_RED, HouseInfo[h][X], HouseInfo[h][Y], HouseInfo[h][Z], 10.0, 0);
                format(file, sizeof(file), "RRP/houses/%d.ini", h);
                if(fexist(file))
                {
                    dini_Set(file, "Owner", Name);
                    dini_IntSet(file, "Ownable", 0);
                }
                format(file, sizeof(file), "RRP/users/%s.ini", Name);
                if(fexist(file))
                {
                    dini_IntSet(file, "HouseKey", h);
                }
                return 1;
            }
        }
        return SendClientMessage(playerid, 0xFFFFFFFF, "You are not near any house.");
    }
    else return SendClientMessage(playerid, 0xFFFFFFFF, "You already own a house.");
}
Reply
#4

@Vinni your code wont send the client "You are not near any house." therefore he must use my code above.
Reply
#5

See again, i edited my post

PS: { missing in your code IceCube
Reply
#6

, I wasn't sure if you cold do that . Incase I didn't want to look like an idiot I put an if .
Reply
#7

You don't need to use one 'if' in this case.
Just work with 'return' at the right time, the way I did in my code
Reply
#8

Used Vinni code and it says i am nto near any house.. :/
I am gettign fool with this.. Some other parts of the system:

pawn Код:
CMD:createhouse(playerid, params[])
{
    new Float:px, Float:py, Float:pz, hprice, hint, string[128];
    GetPlayerPos(playerid, px, py, pz);
    if(!sscanf(params, "ii", hint, hprice))
    {
        new hid;
        hid = Houses[topnumber]+1;
        new vwid;
        vwid = Houses[vwtopnumber]+1;
        if(hint == 1)
        {
            format(file, sizeof(file), "RRP/houses/%d.ini", hid);
            dini_Create(file);
            dini_FloatSet(file, "X", Float:px);
            dini_FloatSet(file, "Y", Float:py);
            dini_FloatSet(file, "Z", Float:pz);
            dini_IntSet(file, "Price", hprice);
            dini_IntSet(file, "Int", hint);
            dini_Set(file, "Owner", "State");
            dini_IntSet(file, "Ownable", 1);
            dini_IntSet(file, "Lock", 0);
            dini_FloatSet(file, "IntX", 223.043991);
            dini_FloatSet(file, "IntY", 1289.259888);
            dini_FloatSet(file, "IntZ", 1082.199951);
            dini_IntSet(file, "Vw", vwid);
            dini_IntSet(file, "Weapon1", 0);
            dini_IntSet(file, "Weapon2", 0);
            dini_IntSet(file, "Weapon3", 0);
            dini_IntSet(file, "Weapon4", 0);
            dini_IntSet(file, "Weapon5", 0);
            dini_IntSet(file, "Weapon6", 0);
            dini_IntSet(file, "Weapon7", 0);
            dini_IntSet(file, "Weapon8", 0);
            dini_IntSet(file, "Materials", 0);
            LoadHouses();
            housepickup[hid] = CreatePickup(1273, 1, Float:px, Float:py, Float:pz, 0);
            format(string, sizeof(string), "This house is for sale. Use /buyhouse to buy it. Price: %d", hprice);
            housetext[hid] = Create3DTextLabel(string, COLOR_RED, Float:px, Float:py, Float:pz, 10.0, 0);
            Houses[topnumber] = Houses[topnumber]+1;
            Houses[vwtopnumber] = Houses[vwtopnumber]+1;
        }
        if(hint == 2)
        {
            format(file, sizeof(file), "RRP/houses/%d.ini", hid);
            dini_Create(file);
            dini_FloatSet(file, "X", Float:px);
            dini_FloatSet(file, "Y", Float:py);
            dini_FloatSet(file, "Z", Float:pz);
            dini_IntSet(file, "Price", hprice);
            dini_IntSet(file, "Int", hint);
            dini_Set(file, "Owner", "State");
            dini_IntSet(file, "Ownable", 1);
            dini_IntSet(file, "Lock", 0);
            dini_FloatSet(file, "IntX", 225.756989);
            dini_FloatSet(file, "IntY", 1240.000000);
            dini_FloatSet(file, "IntZ", 1082.149902);
            dini_IntSet(file, "Vw", vwid);
            LoadHouses();
            housepickup[hid] = CreatePickup(1273, 1, Float:px, Float:py, Float:pz, 0);
            format(string, sizeof(string), "This house is for sale. Use /buyhouse to buy it. Price: %d", hprice);
            housetext[hid] = Create3DTextLabel(string, COLOR_RED, Float:px, Float:py, Float:pz, 10.0, 0);
            Houses[topnumber] = Houses[topnumber]+1;
            Houses[vwtopnumber] = Houses[vwtopnumber]+1;
        }
        if(hint == 3)
        {
            format(file, sizeof(file), "RRP/houses/%d.ini", hid);
            dini_Create(file);
            dini_FloatSet(file, "X", Float:px);
            dini_FloatSet(file, "Y", Float:py);
            dini_FloatSet(file, "Z", Float:pz);
            dini_IntSet(file, "Price", hprice);
            dini_IntSet(file, "Int", hint);
            dini_Set(file, "Owner", "State");
            dini_IntSet(file, "Ownable", 1);
            dini_IntSet(file, "Lock", 0);
            dini_FloatSet(file, "IntX", 235.508994);
            dini_FloatSet(file, "IntY", 1189.169897);
            dini_FloatSet(file, "IntZ", 1080.339966);
            dini_IntSet(file, "Vw", vwid);
            LoadHouses();
            housepickup[hid] = CreatePickup(1273, 1, Float:px, Float:py, Float:pz, 0);
            format(string, sizeof(string), "This house is for sale. Use /buyhouse to buy it. Price: %d", hprice);
            housetext[hid] = Create3DTextLabel(string, COLOR_RED, Float:px, Float:py, Float:pz, 10.0, 0);
            Houses[topnumber] = Houses[topnumber]+1;
            Houses[vwtopnumber] = Houses[vwtopnumber]+1;
        }
        if(hint == 5)
        {
            format(file, sizeof(file), "RRP/houses/%d.ini", hid);
            dini_Create(file);
            dini_FloatSet(file, "X", Float:px);
            dini_FloatSet(file, "Y", Float:py);
            dini_FloatSet(file, "Z", Float:pz);
            dini_IntSet(file, "Price", hprice);
            dini_IntSet(file, "Int", hint);
            dini_Set(file, "Owner", "State");
            dini_IntSet(file, "Ownable", 1);
            dini_IntSet(file, "Lock", 0);
            dini_FloatSet(file, "IntX", 1299.14);
            dini_FloatSet(file, "IntY", -794.77);
            dini_FloatSet(file, "IntZ", 1084.00);
            dini_IntSet(file, "Vw", vwid);
            LoadHouses();
            housepickup[hid] = CreatePickup(1273, 1, Float:px, Float:py, Float:pz, 0);
            format(string, sizeof(string), "This house is for sale. Use /buyhouse to buy it. Price: %d", hprice);
            housetext[hid] = Create3DTextLabel(string, COLOR_RED, Float:px, Float:py, Float:pz, 10.0, 0);
            Houses[topnumber] = Houses[topnumber]+1;
            Houses[vwtopnumber] = Houses[vwtopnumber]+1;
        }
        if(hint == 7)
        {
            format(file, sizeof(file), "RRP/houses/%d.ini", hid);
            dini_Create(file);
            dini_FloatSet(file, "X", Float:px);
            dini_FloatSet(file, "Y", Float:py);
            dini_FloatSet(file, "Z", Float:pz);
            dini_IntSet(file, "Price", hprice);
            dini_IntSet(file, "Int", hint);
            dini_Set(file, "Owner", "State");
            dini_IntSet(file, "Ownable", 1);
            dini_IntSet(file, "Lock", 0);
            dini_FloatSet(file, "IntX", 225.630997);
            dini_FloatSet(file, "IntY", 1022.479980);
            dini_FloatSet(file, "IntZ", 1084.069946);
            dini_IntSet(file, "Vw", vwid);
            LoadHouses();
            housepickup[hid] = CreatePickup(1273, 1, Float:px, Float:py, Float:pz, 0);
            format(string, sizeof(string), "This house is for sale. Use /buyhouse to buy it. Price: %d", hprice);
            housetext[hid] = Create3DTextLabel(string, COLOR_RED, Float:px, Float:py, Float:pz, 10.0, 0);
            Houses[topnumber] = Houses[topnumber]+1;
            Houses[vwtopnumber] = Houses[vwtopnumber]+1;
        }
        if(hint == 8)
        {
            format(file, sizeof(file), "RRP/houses/%d.ini", hid);
            dini_Create(file);
            dini_FloatSet(file, "X", Float:px);
            dini_FloatSet(file, "Y", Float:py);
            dini_FloatSet(file, "Z", Float:pz);
            dini_IntSet(file, "Price", hprice);
            dini_IntSet(file, "Int", hint);
            dini_Set(file, "Owner", "State");
            dini_IntSet(file, "Ownable", 1);
            dini_IntSet(file, "Lock", 0);
            dini_FloatSet(file, "IntX", 2365.42);
            dini_FloatSet(file, "IntY", -1131.85);
            dini_FloatSet(file, "IntZ", 1050.88);
            dini_IntSet(file, "Vw", vwid);
            LoadHouses();
            housepickup[hid] = CreatePickup(1273, 1, Float:px, Float:py, Float:pz, 0);
            format(string, sizeof(string), "This house is for sale. Use /buyhouse to buy it. Price: %d", hprice);
            housetext[hid] = Create3DTextLabel(string, COLOR_RED, Float:px, Float:py, Float:pz, 10.0, 0);
            Houses[topnumber] = Houses[topnumber]+1;
            Houses[vwtopnumber] = Houses[vwtopnumber]+1;
        }
        if(hint == 10)
        {
            format(file, sizeof(file), "RRP/houses/%d.ini", hid);
            dini_Create(file);
            dini_FloatSet(file, "X", Float:px);
            dini_FloatSet(file, "Y", Float:py);
            dini_FloatSet(file, "Z", Float:pz);
            dini_IntSet(file, "Price", hprice);
            dini_IntSet(file, "Int", hint);
            dini_Set(file, "Owner", "State");
            dini_IntSet(file, "Ownable", 1);
            dini_IntSet(file, "Lock", 0);
            dini_FloatSet(file, "IntX", 2260.76);
            dini_FloatSet(file, "IntY", -1210.45);
            dini_FloatSet(file, "IntZ", 1049.02);
            dini_IntSet(file, "Vw", vwid);
            LoadHouses();
            housepickup[hid] = CreatePickup(1273, 1, Float:px, Float:py, Float:pz, 0);
            format(string, sizeof(string), "This house is for sale. Use /buyhouse to buy it. Price: %d", hprice);
            housetext[hid] = Create3DTextLabel(string, COLOR_RED, Float:px, Float:py, Float:pz, 10.0, 0);
            Houses[topnumber] = Houses[topnumber]+1;
            Houses[vwtopnumber] = Houses[vwtopnumber]+1;
        }
        format(file, sizeof(file), "RRP/houses/Hindex.ini");
        if(fexist(file))
        {
            dini_IntSet(file, "topnumber", Houses[topnumber]);
            dini_IntSet(file, "vwtopnumber", Houses[vwtopnumber]);
        }
        return 1;
    }
    else
    {
        SendClientMessage(playerid, COLOR_DARKGOLD, "USAGE: /createhouse [Interior] [Price]");
        SendClientMessage(playerid, COLOR_DARKGOLD, "||Interiors|| Madd Doggs: 5 || Very Largue: 7 || Largue: 3 || Medium: 2 || Small: 1 || Very Small: 7 || CJ House: 3 || Verdant Bluffs: 8 || Hashbury: 10");
        return 1;
    }
}
Reply
#9

Increase the range of IsPlayerInRangeOfPoint.

I use the same style of code in my gamemod, and the logic is correct.
Reply
#10

Quote:
Originally Posted by Viniborn
Посмотреть сообщение
Increase the range of IsPlayerInRangeOfPoint.

I use the same style of code in my gamemod, and the logic is correct.
Will try it. I found it weird that with first house it works and second no. xD
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)