2 problems to deal with
#1

Hello again..

Guys , i have two problems:
  1. If i press enter anywhere - gametext appears (Durys uzrakintos))
  2. When i log out and login and if i were in house my postion i setted to the sky
Here is my code:

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(PRESSED(KEY_SECONDARY_ATTACK))
    {
        for(new h;h < MAX_HOUSES; h++)
        {
            new pName[MAX_PLAYER_NAME];
            GetPlayerName(playerid, pName, sizeof(pName));
            if(IsPlayerInRangeOfPoint(playerid, 5, HouseInfo[h][hEnterX], HouseInfo[h][hEnterY], HouseInfo[h][hEnterZ]))
            {
                if(HouseInfo[h][hLocked] == 0 && (strcmp(HouseInfo[h][hOwnerName], pName, false) == 0 || strcmp(HouseInfo[h][hRenter], pName, false) == 0))
                {
                    SetPlayerInterior(playerid,HouseInfo[h][hInterior]);
                    SetPlayerVirtualWorld(playerid, HouseInfo[h][hVirtualWorld]);
                    SetPlayerPos(playerid, HouseInfo[h][hExitX], HouseInfo[h][hExitY], HouseInfo[h][hExitZ]);
                    PlayerInfo[playerid][pInHouse] = 1;
                    return 1;
                }
                else
                {
                    GameTextForPlayer(playerid, "~r~Uzrakinta", 2000, 1);
                    return 1;
                }
            }

            if(PlayerInfo[playerid][pInHouse] == 1 && IsPlayerInRangeOfPoint(playerid, 5, HouseInfo[h][hExitX], HouseInfo[h][hExitY], HouseInfo[h][hExitZ]) && HouseInfo[h][hLocked] == 0)
            {
                SetPlayerInterior(playerid,0);
                SetPlayerVirtualWorld(playerid, 0);
                SetPlayerPos(playerid, HouseInfo[h][hEnterX], HouseInfo[h][hEnterY], HouseInfo[h][hEnterZ]);
                PlayerInfo[playerid][pInHouse] = 0;
                return 1;
            }
            else
            {
                GameTextForPlayer(playerid, "~r~Duris Uzrakintos", 2000, 1);
                return 1;
            }
        }
    }
    return 1;
}
And here i save my players position and variable whether he is in the house.

pawn Код:
enum pInfo
{
    Float:pPosX,Float:pPosY,Float:pPosZ,Float:pAngle,
    pInterrior,
    pInHouse,
    pVirtualWorld,
}
new PlayerInfo[MAX_PLAYERS][pInfo];

forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
    INI_Float("PositionX",PlayerInfo[playerid][pPosX]);
    INI_Float("PositionY",PlayerInfo[playerid][pPosY]);
    INI_Float("PositionZ",PlayerInfo[playerid][pPosZ]);
    INI_Float("Angle",PlayerInfo[playerid][pAngle]);
INI_Int("Interrior",PlayerInfo[playerid][pInterrior]);
INI_Int("IsInHouse",PlayerInfo[playerid][pInHouse]);
    INI_Int("VirtualWorld",PlayerInfo[playerid][pVirtualWorld]);
    return 1;
}

if(IsPlayerConnected(playerid))
    {
        GetPlayerPos(playerid,PlayerInfo[playerid][pPosX],PlayerInfo[playerid][pPosY],PlayerInfo[playerid][pPosZ]);
        GetPlayerFacingAngle(playerid,PlayerInfo[playerid][pAngle]);
        new INI:File = INI_Open(UserPath(playerid));
        INI_SetTag(File,"PlayerData");
        INI_WriteFloat(File,"PositionX",PlayerInfo[playerid][pPosX]);
        INI_WriteFloat(File,"PositionY",PlayerInfo[playerid][pPosY]);
        INI_WriteFloat(File,"PositionZ",PlayerInfo[playerid][pPosZ]);
        INI_WriteFloat(File,"Angle",PlayerInfo[playerid][pAngle]);
        INI_WriteInt(File,"Interrior",PlayerInfo[playerid][pInterrior]);
        INI_WriteInt(File,"IsInHouse",PlayerInfo[playerid][pInHouse]);
        INI_WriteInt(File,"VirtualWorld",GetPlayerVirtualWorld(playerid));
        INI_Close(File);
    }

Or maybe there is another way to save that player logged out while he was in the house and then spawn him there when he log in?
Reply
#2

1. You should check player's position first, then check if house is not locked and they're in a house.
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(PRESSED(KEY_SECONDARY_ATTACK))
    {
        for(new h;h < MAX_HOUSES; h++)
        {
            new pName[MAX_PLAYER_NAME];
            GetPlayerName(playerid, pName, sizeof(pName));
            if(IsPlayerInRangeOfPoint(playerid, 5, HouseInfo[h][hEnterX], HouseInfo[h][hEnterY], HouseInfo[h][hEnterZ]))
            {
                if(HouseInfo[h][hLocked] == 0 && (strcmp(HouseInfo[h][hOwnerName], pName, false) == 0 || strcmp(HouseInfo[h][hRenter], pName, false) == 0))
                {
                    SetPlayerInterior(playerid,HouseInfo[h][hInterior]);
                    SetPlayerVirtualWorld(playerid, HouseInfo[h][hVirtualWorld]);
                    SetPlayerPos(playerid, HouseInfo[h][hExitX], HouseInfo[h][hExitY], HouseInfo[h][hExitZ]);
                    PlayerInfo[playerid][pInHouse] = 1;
                    return 1;
                }
                else
                {
                    GameTextForPlayer(playerid, "~r~Uzrakinta", 2000, 1);
                    return 1;
                }
            }
            if(IsPlayerInRangeOfPoint(playerid, 5, HouseInfo[h][hExitX], HouseInfo[h][hExitY], HouseInfo[h][hExitZ]))
            {
                if(PlayerInfo[playerid][pInHouse] == 1 && HouseInfo[h][hLocked] == 0)
                {
                    SetPlayerInterior(playerid,0);
                    SetPlayerVirtualWorld(playerid, 0);
                    SetPlayerPos(playerid, HouseInfo[h][hEnterX], HouseInfo[h][hEnterY], HouseInfo[h][hEnterZ]);
                    PlayerInfo[playerid][pInHouse] = 0;
                    return 1;
                }
                else
                {
                    GameTextForPlayer(playerid, "~r~Duris Uzrakintos", 2000, 1);
                    return 1;
                }
            }
        }
    }
    return 1;
}
2. Have you set player's interior to house interior ?
Reply
#3

yeah first problem fixed.But second as i said i save and load data so player should spawn in interior and virtual world but now i just go to the sky somewhere.
Reply
#4

May I see your code which spawn the player ?
Reply
#5

Will this work?
pawn Код:
if(PlayerInfo[playerid][NewPlayer] == true)
    {
        GivePlayerMoney(playerid,4000);
        PlayerInfo[playerid][NewPlayer] = false;
        new PlayerSkin = GetPlayerSkin(playerid);
        PlayerInfo[playerid][Logged] = true;
        switch(PlayerSkin)
        {
            case 12,55,91,93:
            {
                PlayerInfo[playerid][pGender] = 2;
                SavePlayerData(playerid);
            }
            case 26,47,60,170:
            {
                PlayerInfo[playerid][pGender] = 1;
                SavePlayerData(playerid);
            }
        }
    }
    else
    {
        PlayerInfo[playerid][Logged] = true;
        LoadSpawnInfo(playerid);
        if(PlayerInfo[playerid][pInHouse] != 0)
        {
            new houseid = PlayerInfo[playerid][pInHouse];
            SetPlayerPos(playerid, HouseInfo[houseid][hExitX], HouseInfo[houseid][hExitY], HouseInfo[houseid][hExitZ]);
        }
    }
Reply
#6

Just do this for interior's fix:

Logout:
- Save player interior trough GetPlayerInterior(playerid) in player's data file,

Login:
- Read saved Interior value and call it so: SetPlayerInterior(playerid,interiorid)

This will work.
Reply
#7

i did it before ,but now i just checking if player was in house and setting the position.And its working.still thank you for your time.
Reply


Forum Jump:


Users browsing this thread: