Need small help with Buying house
#1

Fixed!
Reply
#2

Increase an array each time the player buys an house
pawn Код:
pInfo[playerid][Houses] ++;
And in the top of your command, check if it's higher than 3, and stop the cmd.
pawn Код:
if(pInfo[playerid][Houses] > 3) return SendClientMessage(playerid, -1, "You already have 3 houses.");
Reply
#3

pawn Код:
#define MAX_HOUSES 3
You can change this to whatever you want anytime.

Use your variable to check the houses owned by the player:
pawn Код:
if(pHouses[playerid] > MAX_HOUSES) return SendClientMessage(playerid, -1, "You have the maximum amount of houses.");
Change the variable name to whatever you want, that's just an example.

The post above is correct, I felt like doing this in a different way.
Reply
#4

Fixed!
Reply
#5

Fixed!
Reply
#6

Sc0pion, we aren't going to create all the code for you, we're just going to give you options/solutions. You'll have to make it work with the features you have in your script.

You could either create a new list item which saves in the player's user file (Ex: aUserInfo[playerid][user_houses]), and check if they own 3 houses and prevent them from buying another one, or you could loop through the houses and preform some checks:

pawn Код:
stock IsPlayerAllowedToBuyHouse(playerid)
{
    new count, name[MAX_PLAYER_NAME], bool:state = false;
    GetPlayerName(playerid, name, MAX_PLAYER_NAME);
    for(new i = 0; i < MAX_HOUSES; i ++)
    {
        if(strcmp(hInfo[i][Owner], name, true) == 0) count ++;
        if(count == 3)
        {
            state = true;
            break;
        }
    }

    if(state == true) return false;
    return true;
}
To prevent a player from buying another house if they already own 3 (implying you're using the code above):
pawn Код:
if(!IsPlayerAllowedToBuyHouse(playerid)) return SendClientMessage(playerid, -1, "You can't purchase another house, sell one first!");
However, I would recommend the first option, but it's up to you!
Reply
#7

Simply create the variable.

pawn Код:
new pHouses[MAX_PLAYERS];
Reply
#8

Well if you don't have a way to remove a players house, there's no need to do pInfo[playerid][Houses] --.
If you don't have such a variable, create it.
Reply
#9

Fixed!
Reply
#10

Change the variable's name (state) to something else then compile.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)