SA-MP Forums Archive
Pickup Issues - 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: Pickup Issues (/showthread.php?tid=571060)



Pickup Issues - DTV - 15.04.2015

So I'm working with a house system that, for the most part, works fine. It's just updating the pickup to detect when the house is owned or not is an issue.


This is what I use to update the pickup ID at any house.
pawn Код:
stock LoadHouseVisual(playerid, houseid)
{
    DestroyDynamicPickup(HousePickup[playerid]);
    if(House[houseid][hOwned] == 0)
    {
        HousePickup[playerid] = CreateDynamicPickup(1273, 1, House[houseid][ExtPosX], House[houseid][ExtPosY], House[houseid][ExtPosZ], 0, 0);
    }
    else if(House[houseid][hOwned] == 1)
    {
        HousePickup[playerid] = CreatePickup(19522, 1, House[houseid][ExtPosX], House[houseid][ExtPosY], House[houseid][ExtPosZ], 0);
    }
    return 1;
}
With that, I use it for when the player logins and when they buy/sell a house. For some reason, when they buy a house that's for sale, it works just fine, but when they sell it, it doesn't change.


The /buyhouse and /sellhouse commands
pawn Код:
CMD:buyhouse(playerid, params[])
{
    if(GetPVarInt(playerid, "LoggedIn") == 0) return SendClientMessage(playerid, COLOR_RED, "[ERROR]: You need to be logged in to use this command.");
    new string[128], Float:x, Float:y, Float:z, owner[MAX_PLAYER_NAME];
    owner = GetName(playerid);
    if(Player[playerid][HouseID] == -1)
    {
        GetPlayerPos(playerid, x, y, z);
        for(new i = 0; i<MAX_HOUSES; i++)
        {
            if(fexist(HousePath(i)))
            {
                if(IsPlayerInRangeOfPoint(playerid, 1, House[i][ExtPosX], House[i][ExtPosY], House[i][ExtPosZ]))
                {
                    if(House[i][hOwned] == 0)
                    {
                        if(Player[playerid][Money] >= House[i][hPrice])
                        {
                            DestroyDynamicPickup(HousePickup[playerid]);
                            Player[playerid][HouseID] = House[i][hID];
                            House[i][hOwned] = 1;
                            House[i][hOwner] = owner;
                            //House[i][hPickup] = 19522;
                            Player[playerid][Money] -= House[i][hPrice];
                            SaveHouses(i);
                            LoadHouseVisual(playerid, i);
                            format(string, sizeof(string), "You have bought property named: %s [ID: %i] for $%i.", House[i][hName], House[i][hID], House[i][hPrice]);
                            SendClientMessage(playerid, COLOR_GREEN, string);
                            SendClientMessage(playerid, COLOR_GREEN, "Please take a screenshot now if a bug is to cause you to loose your house.");
                            SendClientMessage(playerid, COLOR_GREEN, "We cannot refund you the house or caps if the screenshot isn't provided, so keep that in mind.");
                        }
                        else return SendClientMessage(playerid, COLOR_GREY, "You don't have enough caps to buy the house.");
                    }
                    else return SendClientMessage(playerid, COLOR_GREY, "This house is already owned.");
                }
            }
        }
    }
    else return SendClientMessage(playerid, COLOR_GREY, "You already own a house.");
    return 1;
}


CMD:sellhouse(playerid, params[])
{
    if(GetPVarInt(playerid, "LoggedIn") == 0) return SendClientMessage(playerid, COLOR_RED, "[ERROR]: You need to be logged in to use this command.");
    new string[128], Float:x, Float:y, Float:z;
    for(new i = 0; i<MAX_HOUSES; i++)
    {
        if(fexist(HousePath(i)))
        {
            GetPlayerPos(playerid, x, y, z);
            if(IsPlayerInRangeOfPoint(playerid, 1, House[i][ExtPosX], House[i][ExtPosY], House[i][ExtPosZ]))
            {
                if(Player[playerid][HouseID] == House[i][hID])
                {
                    if(House[i][hOwned] == 1)
                    {
                        DestroyDynamicPickup(HousePickup[playerid]);
                        Player[playerid][HouseID] = -1;
                        House[i][hOwned] = 0;
                        House[i][hLocked] = 1;
                        House[i][hOwner] = 0;
                        //House[i][hPickup] = 1273;
                        Player[playerid][Money] += (House[i][hPrice]/2);
                        SaveHouses(i);
                        LoadHouseVisual(playerid, i);
                        format(string, sizeof(string), "You have sold property named: %s [ID: %i] for $%i.", House[i][hName], House[i][hID], (House[i][hPrice]/2));
                        SendClientMessage(playerid, COLOR_GREEN, string);
                    }
                    else return SendClientMessage(playerid, COLOR_GREY, "This house is already owned.");
                }
                else return SendClientMessage(playerid, COLOR_GREY, "You do not own this house.");
            }
        }
    }
    return 1;
}
Anyone know what's wrong with it?


Re: Pickup Issues - Emmet_ - 15.04.2015

You are using CreateDynamicPickup and CreatePickup interchangeably. Try using just one:

pawn Код:
stock LoadHouseVisual(playerid, houseid)
{
    DestroyDynamicPickup(HousePickup[playerid]);
    if(House[houseid][hOwned] == 0)
    {
        HousePickup[playerid] = CreateDynamicPickup(1273, 1, House[houseid][ExtPosX], House[houseid][ExtPosY], House[houseid][ExtPosZ], 0, 0);
    }
    else if(House[houseid][hOwned] == 1)
    {
        HousePickup[playerid] = CreateDynamicPickup(19522, 1, House[houseid][ExtPosX], House[houseid][ExtPosY], House[houseid][ExtPosZ], 0);
    }
    return 1;
}



Re: Pickup Issues - Pottus - 15.04.2015

I think there is a bug with the pickup system as well in some circumstances so using dynamic pickups is probably the best choice.


Re: Pickup Issues - DTV - 15.04.2015

Quote:
Originally Posted by Emmet_
Посмотреть сообщение
You are using CreateDynamicPickup and CreatePickup interchangeably. Try using just one:

pawn Код:
stock LoadHouseVisual(playerid, houseid)
{
    DestroyDynamicPickup(HousePickup[playerid]);
    if(House[houseid][hOwned] == 0)
    {
        HousePickup[playerid] = CreateDynamicPickup(1273, 1, House[houseid][ExtPosX], House[houseid][ExtPosY], House[houseid][ExtPosZ], 0, 0);
    }
    else if(House[houseid][hOwned] == 1)
    {
        HousePickup[playerid] = CreateDynamicPickup(19522, 1, House[houseid][ExtPosX], House[houseid][ExtPosY], House[houseid][ExtPosZ], 0);
    }
    return 1;
}
...I can't believe I missed that, thanks for pointing that out for me, works like a charm now