SA-MP Forums Archive
Small problem with house system - 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: Small problem with house system (/showthread.php?tid=560926)



Small problem with pickup - FunnyBear - 31.01.2015

Hey,

I'm trying to make a house system. If you stand on the house pickup and press F, you will enter the house. I don't want it so you can enter the house as soon as you step on the pickup.

But there's a problem. I used OnPlayerKeyStateChange to check if they pressed F whilst on the House Pickup. However I can't check if they are on a pickup because I don't want to use OnPlayerPickupPickUp

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys & KEY_SECONDARY_ATTACK)
    {
        for(new i=1; i<=CreatedHouses; i++)
        {
            if(pickupid == HouseInfo[i][ExitPickup])
            {
                KickFromHouse(playerid, i);
            }
            else if(pickupid == HouseInfo[i][EnterPickup])
            {
                if(HouseInfo[i][Owned] == 0)
                {
                    ShowPlayerDialog(playerid, BUY_HOUSE, DIALOG_STYLE_LIST, "Buy House", "Buy this house", "Select", "Cancel");
                }
                else if(HouseInfo[i][Owned] == 1)
                {
                    if(HouseInfo[i][Locked] == 1)
                    {
                        new HouseOwner[MAX_PLAYER_NAME];
                        GetPlayerName(playerid, HouseOwner, sizeof(HouseOwner));
                        if(strcmp(HouseOwner, HouseInfo[i][Owner]) != 0)
                        {
                            SendClientMessage(playerid, RED, "This house is currently locked! You cannot enter it!");
                            return 1;
                        }
                    }
                }
            }
        }
    }
    return 1;
}
How am I able to check what pickup they are standing on because if I use pickupid on OnPlayerKeyStateChange, it will give me errors because pickupid is not recognised.

How can I solve this problem?

Thanks


Re: Small problem with house system - Gammix - 31.01.2015

Use IsPlayerInRangeOfPoint in the callback.
WIKI: https://sampwiki.blast.hk/wiki/IsPlayerInRangeOfPoint

Example:
pawn Код:
if(IsPlayerInRangeOfPoint(playerid, 1.0, HouseInfo[i][x], HouseInfo[i][y], HouseInfo[i][z]))
{
    //your code, this will run if the player is in range of the pickup
}
Set your range accordingly, 1.0 is appropriate though.
Also those x,y,z arrays are custom as you havent provided any code relative to those arrays.