Confused
#1

I'm kinda confused here, I have a house system, I wanted to make that when a player presses ENTER, he/she gets teleported to the house when he/she is in the checkpoint but the problem is that whenever I press ENTER, even when I'm not in the checkpoint, he/she gets teleported to the house.
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if (RELEASED( KEY_SECONDARY_ATTACK ))
    {
              enterHouse(playerid);
    }
        return 1;
}
pawn Код:
stock enterHouse(playerid)
{
    for(new i = 0; i < MAX_HOUSES; i++)
    {
        if(fexist(housePath(i)))
        {
            if(!IsPlayerInAnyVehicle(playerid))
            {
                if(pInfo[playerid][pJailTime] <= 0)
                {
                    if(IsPlayerInDynamicCP(playerid, hInfo[i][hCPOut]))
                    {
                        printf("house id: %d", i);
                        teleportToHouseInterior(playerid, i);
                    }
                    else break;
                }
            }
        }
    }
    return 1;
}
Is this something related to Streamer or?
Reply
#2

Check if the player is in range of any house in that function you made, my script looks familiar to this.

Edit: check if the player is in any checkpoint.
Reply
#3

Show us "IsPlayerInDynamicCP"?
Reply
#4

Quote:
Originally Posted by Darrenr
Посмотреть сообщение
Show us "IsPlayerInDynamicCP"?
Quote:

if(IsPlayerInDynamicCP(playerid, hInfo[i][hCPOut]))

I guess it already exists in that code.
Reply
#5

Where does "IsPlayerInDynamicCP" come from? An include/custom function? OR is it built into samp?
Reply
#6

I use this script to check it, it might be useful to you:
pawn Код:
public OnPlayerEnterDynamicCP(playerid, checkpointid)
{
    for(new i = 0; i < sizeof(HouseData); i++)
    {
        if(IsPlayerInRangeOfPoint(playerid, 1.5, HouseData[i][heX],HouseData[i][heY],HouseData[i][heZ]))
        {
            new housestring[128];
            watchingHouse[playerid] = i;

            //format(housestring, sizeof(housestring), "House Menu for house ID %d!", watchingHouse[playerid]);
            //ShowPlayerDialog(playerid, DIALOG_ENTERHOUSE, DIALOG_STYLE_LIST, housestring, "Enter House\nBuy House", "Continue", "Cancel");
            break;
        }
    }
}
My script sends a dialog if he's in a checkpoint, but hopefully you get the point.

EDIT: just use i as houseid and retrieve the info from that.
Reply
#7

Quote:
Originally Posted by Darrenr
Посмотреть сообщение
Where does "IsPlayerInDynamicCP" come from? An include/custom function? OR is it built into samp?
Streamer.
Quote:
Originally Posted by Jimmy0wns
Посмотреть сообщение
I use this script to check it, it might be useful to you:
pawn Код:
public OnPlayerEnterDynamicCP(playerid, checkpointid)
{
    for(new i = 0; i < sizeof(HouseData); i++)
    {
        if(IsPlayerInRangeOfPoint(playerid, 1.5, HouseData[i][heX],HouseData[i][heY],HouseData[i][heZ]))
        {
            new housestring[128];
            watchingHouse[playerid] = i;

            //format(housestring, sizeof(housestring), "House Menu for house ID %d!", watchingHouse[playerid]);
            //ShowPlayerDialog(playerid, DIALOG_ENTERHOUSE, DIALOG_STYLE_LIST, housestring, "Enter House\nBuy House", "Continue", "Cancel");
            break;
        }
    }
}
My script sends a dialog if he's in a checkpoint, but hopefully you get the point.

EDIT: just use i as houseid and retrieve the info from that.
Well, actually, I want to go like that: if someone presses LEFT ALT while being in a checkpoint, he/she gets in house the house.

I tried something like:
pawn Код:
if((newkeys & KEY_WALK) && !(oldkeys & KEY_WALK))
    {
        for(new houseid; houseid < MAX_HOUSES; houseid++)
        {
            if(IsPlayerInDynamicCP(playerid, houseCPOut[houseid]))
            {
                if(pInfo[playerid][pJailTime] <= 0)
                {
                    if(!IsPlayerInAnyVehicle(playerid))
                    {
                        if(!pInfo[playerid][pCuffed])
                        {
                            if(!pInfo[playerid][pTied])
                            {
                                if(!pInfo[playerid][pTazed])
                                {
                                    teleportToHouseInterior(playerid, houseid);
                                    break;
                                }
                            }
                        }
                    }
                }
                else
                {
                    break;
                }
            }
        }
    }
But still, it teleports me whenever I'm not in the checkpoint.
Reply
#8

Try this:
pawn Код:
#define PRESSED(%0)     (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(PRESSED(KEY_SECONDARY_ATTACK)) enterHouse(playerid);
    return 1;
}

stock enterHouse(playerid)
{
    if(IsPlayerInAnyVehicle(playerid) || pInfo[playerid][pJailTime] > 0) return 1;

    new bool:found = false, houseid = -1;
    for(new i = 0; i < MAX_HOUSES; i ++)
    {
        if(IsValidDynamicCP(hInfo[i][hCPOut]) && IsPlayerInDynamicCP(playerid, hInfo[i][hCPOut]))
        {
            found = true;
            houseid = i;
            break;
        }
    }

    if(found) teleportToHouseInterior(playerid, houseid);
    return 1;
}
Reply
#9

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
Try this:
pawn Код:
#define PRESSED(%0)     (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(PRESSED(KEY_SECONDARY_ATTACK)) enterHouse(playerid);
    return 1;
}

stock enterHouse(playerid)
{
    if(IsPlayerInAnyVehicle(playerid) || pInfo[playerid][pJailTime] > 0) return 1;

    new bool:found = false, houseid = -1;
    for(new i = 0; i < MAX_HOUSES; i ++)
    {
        if(IsValidDynamicCP(hInfo[i][hCPOut]) && IsPlayerInDynamicCP(playerid, hInfo[i][hCPOut]))
        {
            found = true;
            houseid = i;
            break;
        }
    }

    if(found) teleportToHouseInterior(playerid, houseid);
    return 1;
}
Works, thank you!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)