The correct way to save and load the player's interior.
#1

I'll give you all the code related to saving/loading of interiors, just point out what's wrong please:
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    new name[MAX_PLAYER_NAME], fileLoc[256];
    GetPlayerName(playerid, name, sizeof(name));
    format(fileLoc, sizeof(fileLoc), "/Users/%s.ini", name);
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
    if(Login[playerid] == 1) {
        if(pInfo[playerid][Registered] == 1) {
            dini_FloatSet(fileLoc, "spawnX", x);
            dini_FloatSet(fileLoc, "spawnY", y);
            dini_FloatSet(fileLoc, "spawnZ", z);
            dini_IntSet(fileLoc, "Interior", GetPlayerInterior(playerid));
            dini_IntSet(fileLoc, "AdminLevel", pInfo[playerid][AdminLevel]);
            dini_IntSet(fileLoc, "Cash", 0);
            dini_IntSet(fileLoc, "OOCMuted", 0);
            dini_IntSet(fileLoc, "Level", pInfo[playerid][Level]);
            dini_IntSet(fileLoc, "Experience", pInfo[playerid][Experience]);
            new weap1, ammo1, weap2, ammo2, weap3, ammo3, weap4, ammo4;
            GetPlayerWeaponData(playerid,2,weap1,ammo1);
            GetPlayerWeaponData(playerid,3,weap2,ammo2);
            GetPlayerWeaponData(playerid,4,weap3,ammo3);
            GetPlayerWeaponData(playerid,5,weap4,ammo4);
            dini_IntSet(fileLoc, "WeaponSlot1", weap1);
            dini_IntSet(fileLoc, "WeaponSlot1Ammo", ammo1);
            dini_IntSet(fileLoc, "WeaponSlot2", weap2);
            dini_IntSet(fileLoc, "WeaponSlot2Ammo", ammo2);
            dini_IntSet(fileLoc, "WeaponSlot3", weap3);
            dini_IntSet(fileLoc, "WeaponSlot3Ammo", ammo3);
            dini_IntSet(fileLoc, "WeaponSlot4", weap4);
            dini_IntSet(fileLoc, "WeaponSlot4Ammo", ammo4);
            dini_IntSet(fileLoc, "OOCMuted", pInfo[playerid][OOCMuted]);
            dini_IntSet(fileLoc, "Registered",pInfo[playerid][Registered]);
            dini_IntSet(fileLoc, "Age", pInfo[playerid][Age]);
            dini_IntSet(fileLoc, "Sex", pInfo[playerid][Sex]);
            dini_Set(fileLoc, "Accent", pInfo[playerid][Accent]);
        }
    }
    return 1;
}
pawn Код:
public OnPlayerSpawn(playerid)
{
    if(Login[playerid] == 1) {
        if(pInfo[playerid][Registered] == 1) {
            if(HasJustDied[playerid] == true) {
                SetPlayerPos(playerid, deathSpawnX, deathSpawnY, deathSpawnZ);
                HasJustDied[playerid] = false;
                pInfo[playerid][WS1] = -1;
                pInfo[playerid][WS2] = -1;
                pInfo[playerid][WS3] = -1;
                pInfo[playerid][WS4] = -1;
                pInfo[playerid][WS1Ammo] = 0;
                pInfo[playerid][WS2Ammo] = 0;
                pInfo[playerid][WS3Ammo] = 0;
                pInfo[playerid][WS4Ammo] = 0;
                ResetPlayerWeapons(playerid);
                SetPlayerInterior(playerid,0);
            }
            if(HasJustRegistered[playerid]) {
                HasJustRegistered[playerid] = false;
                SetPlayerInterior(playerid,0);
                ResetPlayerWeapons(playerid);
            }
            if(pInfo[playerid][Registered] == 0) {
                SetCameraBehindPlayer(playerid);
                ResetPlayerWeapons(playerid);
            }
            else {
                SetPlayerPos(playerid, pInfo[playerid][spawnX], pInfo[playerid][spawnY], pInfo[playerid][spawnZ]);
                SetPlayerInterior(playerid, pInfo[playerid][Interior]);
                GivePlayerWeapons(playerid);
            }
            TogglePlayerControllable(playerid, 1);
        }
    }
    return 1;
}
pawn Код:
if (dialogid == Register)
    {
        if (!strlen(inputtext)) return ShowPlayerDialog(playerid, Register, DIALOG_STYLE_INPUT, "Register", "Enter your password:", "Enter", "Cancel");
        if (!response) return ShowPlayerDialog(playerid, Register, DIALOG_STYLE_INPUT, "Register", "Enter your password:", "Enter", "Cancel");
        dini_Create(fileLoc);
        dini_Set(fileLoc, "User", playerName);
        dini_Set(fileLoc, "Password", inputtext);
        dini_IntSet(fileLoc, "AdminLevel", 0);
        dini_IntSet(fileLoc, "Cash", 0);
        dini_IntSet(fileLoc, "Level", 1);
        dini_IntSet(fileLoc, "Experience", 0);
        dini_IntSet(fileLoc, "WeaponSlot1", -1);
        dini_IntSet(fileLoc, "WeaponSlot1Ammo", 0);
        dini_IntSet(fileLoc, "WeaponSlot2", -1);
        dini_IntSet(fileLoc, "WeaponSlot2Ammo", 0);
        dini_IntSet(fileLoc, "WeaponSlot3", -1);
        dini_IntSet(fileLoc, "WeaponSlot3Ammo", 0);
        dini_IntSet(fileLoc, "WeaponSlot4", -1);
        dini_IntSet(fileLoc, "WeaponSlot4Ammo", 0);
        dini_IntSet(fileLoc, "spawnX", 0);
        dini_IntSet(fileLoc, "spawnY", 0);
        dini_IntSet(fileLoc, "spawnZ", 0);
        dini_IntSet(fileLoc, "OOCMuted", 0);
        dini_IntSet(fileLoc, "Registered", 0);
        dini_IntSet(fileLoc, "Age", 0);
        dini_IntSet(fileLoc, "Sex", 0);
        dini_IntSet(fileLoc, "Interior", -1);
        dini_Set(fileLoc, "Accent", "none");
        ShowPlayerDialog(playerid, Logged, DIALOG_STYLE_INPUT, "Login", "Enter your password:", "Enter", "Cancel");
    }
    if (dialogid == Logged)
    {
        if (!strlen(inputtext)) return ShowPlayerDialog(playerid, Logged, DIALOG_STYLE_INPUT, "Login", "Enter your password:", "Enter", "Cancel");
        if (!response) return ShowPlayerDialog(playerid, Logged, DIALOG_STYLE_INPUT, "Login", "Enter your password", "Enter", "Cancel");
        format(password, sizeof(password), "%s", dini_Get(fileLoc, "Password"));
        if (!strcmp (inputtext, password))
        {
            Login[playerid] = 1;
            pInfo[playerid][AdminLevel] = dini_Int(fileLoc, "AdminLevel");
            pInfo[playerid][Cash] = dini_Int(fileLoc, "Cash");
            pInfo[playerid][Level] = dini_Int(fileLoc, "Level");
            pInfo[playerid][Experience] = dini_Int(fileLoc, "Experience");
            pInfo[playerid][WS1] = dini_Int(fileLoc, "WeaponSlot1");
            pInfo[playerid][WS1Ammo] = dini_Int(fileLoc, "WeaponSlot1Ammo");
            pInfo[playerid][WS2] = dini_Int(fileLoc, "WeaponSlot2");
            pInfo[playerid][WS2Ammo] = dini_Int(fileLoc, "WeaponSlot2Ammo");
            pInfo[playerid][WS3] = dini_Int(fileLoc, "WeaponSlot3");
            pInfo[playerid][WS3Ammo] = dini_Int(fileLoc, "WeaponSlot3Ammo");
            pInfo[playerid][WS4] = dini_Int(fileLoc, "WeaponSlot4");
            pInfo[playerid][WS4Ammo] = dini_Int(fileLoc, "WeaponSlot4Ammo");
            pInfo[playerid][spawnX] = dini_Int(fileLoc, "spawnX");
            pInfo[playerid][spawnY] = dini_Int(fileLoc, "spawnY");
            pInfo[playerid][spawnZ] = dini_Int(fileLoc, "spawnZ");
            pInfo[playerid][OOCMuted] = dini_Int(fileLoc, "OOCMuted");
            pInfo[playerid][Registered] = dini_Int(fileLoc, "Registered");
            pInfo[playerid][Interior] = dini_Int(fileLoc, "Interior");
            pInfo[playerid][Age] = dini_Int(fileLoc, "Age");
            pInfo[playerid][Sex] = dini_Int(fileLoc, "Sex");
            strcat(pInfo[playerid][Accent], dini_Get(fileLoc, "Accent"));
            if(pInfo[playerid][Registered] == 0) {
                registerPlayer(playerid);
            }
            SpawnPlayer(playerid);
        }
        else
        {
            ShowPlayerDialog(playerid, Logged, DIALOG_STYLE_INPUT, "Login", "Enter your password:", "Enter", "Cancel");
        }
    }
However, the default interior, saves as 255.
Reply
#2

Bump, 8 views and no replies? At least try to help.
Reply
#3

Yeah, I sort of really need help with this.
Reply
#4

Sorry i wish i could help but i don't understand much of it. i don't see anything wrong anyway. So it compiles good when when they save all the ints save as 255?
Reply
#5

No, they don't all save as 255, but I enter interior 1 and it saves it as 109 or another random(?) number.
Reply
#6

Where do you put the players interior into the "pInfo[playerid][Interior]" variable?

EDIT: My bad i didn't see it. Try printing that variable after you put the players interior in it. See what it says. Also is all other data saving fine??
Reply
#7

Fixed, close please

(Thanks to Calgon)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)