SA-MP Forums Archive
Need help with these stuffs. - 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: Need help with these stuffs. (/showthread.php?tid=537101)



Need help with these stuffs. - iOxide - 13.09.2014

Alright, i have been working whole day for this and i have finally converted this house system to Y_ini.

The house system loads/saves fine after gamemode restarts. Problem i got is that each player have 2 house slots available max, and whenever they buy 2 houses then relog, only 1 house is loading. Other house is still showing owned by the player but they aren't able to use it. In the player file where the houses are stored, its showing Houses = 2 but when player reconnects, its only loading 1. I have been trying to fix this since 7 hours but couldn't figure out whats wrong.

pawn Код:
//OnGamemodeInit()
Housing_LoadAll()
{
    for (new HouseID = 1; HouseID < MAX_HOUSES; HouseID++)
    {
        if(fexist(House_File(HouseID)))
        {
            INI_ParseFile(House_File(HouseID), "LoadHouse_%s", .bExtra = true, .extra = HouseID);
            gHouseData[HouseID][HouseOpened] = false;
            House_CreateEntrance(HouseID);
            TotalHouses++;
        }
    }
    return 1;
}

//OnPlayerConnect(playerid)
if(fexist(UserPath(playerid)))
        INI_ParseFile(UserPath(playerid), "Load_%s", .bExtra = true, .extra = playerid);

public Load_playerdata(playerid, name[], value[])
{
    new
        BusIndex,
        HouseIndex
    ;

    INI_Int("MoneyBoost",       pInfo[playerid][MoneyBoost]);
    INI_Int("BoostTime",        pInfo[playerid][BoostTime]);
    INI_Int("Jailed",           pInfo[playerid][Jailed]);
    INI_Bool("Muted",           pInfo[playerid][Muted]);
    INI_Bool("RulesRead",       pInfo[playerid][RulesRead]);
    INI_Int("Houses",           pInfo[playerid][Houses][HouseIndex]); HouseIndex++;
    INI_Int("Business",         pInfo[playerid][Business][BusIndex]); BusIndex++;
    return 1;
}

//OnPlayerDisconnect(playerid, reason)
pData_Save(playerid)
{
    if(!pInfo[playerid][LoggedIn]) return 1;

    new
        INI:File = INI_Open(UserPath(playerid));

    INI_SetTag(File, "playerdata");
    INI_WriteInt(File, "MoneyBoost",    pInfo[playerid][MoneyBoost]);
    INI_WriteInt(File, "BoostTime",     pInfo[playerid][BoostTime]);
    INI_WriteInt(File, "Jailed",        pInfo[playerid][Jailed]);
    INI_WriteBool(File, "Muted",        pInfo[playerid][Muted]);
    INI_WriteBool(File, "RulesRead",    pInfo[playerid][RulesRead]);
    for (new i; i < MAX_HOUSESPERPLAYER; i++)
        if (pInfo[playerid][Houses][i] != 0)
            INI_WriteInt(File, "Houses", pInfo[playerid][Houses][i]);
    for (new i; i < MAX_BUSINESSPERPLAYER; i++)
        if (pInfo[playerid][Business][i] != 0)
            INI_WriteInt(File, "Businesses", pInfo[playerid][Business][i]);
    INI_Close(File);
    for (new i; i < MAX_HOUSESPERPLAYER; i++)
    {
        if (pInfo[playerid][Houses][i] != 0)
        {
            Save_HouseData(pInfo[playerid][Houses][i]);
        }
    }
    for (new i; i < MAX_BUSINESSPERPLAYER; i++)
        if (pInfo[playerid][Business][i] != 0)
            BusinessFile_Save(pInfo[playerid][Business][i]);
    return 1;
}

//These are working fine tho
forward LoadHouse_data(HouseID, name[], value[]);
public LoadHouse_data(HouseID, name[], value[])
{
    INI_String("HouseName", gHouseData[HouseID][HouseName], 24);
    INI_Float("HouseX", gHouseData[HouseID][HouseX]);
    INI_Float("HouseY", gHouseData[HouseID][HouseY]);
    INI_Float("HouseZ", gHouseData[HouseID][HouseZ]);
    INI_Int("HouseLevel", gHouseData[HouseID][HouseLevel]);
    INI_Int("HouseMaxLevel", gHouseData[HouseID][HouseMaxLevel]);
    INI_Int("HousePrice", gHouseData[HouseID][HousePrice]);
    INI_Bool("Owned", gHouseData[HouseID][Owned]);
    INI_String("Owner", gHouseData[HouseID][Owner], 24);
    INI_Int("Insurance", gHouseData[HouseID][Insurance]);
    return 1;
}

Save_HouseData(HouseID)
{
    new INI:hFile = INI_Open(House_File(HouseID));

    INI_SetTag(hFile, "data");
    INI_WriteString(hFile, "HouseName", gHouseData[HouseID][HouseName]);
    INI_WriteFloat(hFile, "HouseX", gHouseData[HouseID][HouseX]);
    INI_WriteFloat(hFile, "HouseY", gHouseData[HouseID][HouseY]);
    INI_WriteFloat(hFile, "HouseZ", gHouseData[HouseID][HouseZ]);
    INI_WriteInt(hFile, "HouseLevel", gHouseData[HouseID][HouseLevel]);
    INI_WriteInt(hFile, "HouseMaxLevel", gHouseData[HouseID][HouseMaxLevel]);
    INI_WriteInt(hFile, "HousePrice", gHouseData[HouseID][HousePrice]);
    INI_WriteBool(hFile, "Owned", gHouseData[HouseID][Owned]);
    INI_WriteString(hFile, "Owner", gHouseData[HouseID][Owner]);
    INI_WriteInt(hFile, "Insurance", gHouseData[HouseID][Insurance]);
    INI_Close(hFile);
    return 1;
}
Sorry for posting this huge code. Any help?


Re: Need help with these stuffs. - MikeB - 13.09.2014

try this , if you get any error or problem tell here

PHP код:
//OnGamemodeInit()
Housing_LoadAll()
{
    for (new 
HouseID 1HouseID MAX_HOUSESHouseID++)
    {
        if(
fexist(House_File(HouseID)))
        {
            
INI_ParseFile(House_File(HouseID), "LoadHouse_%s", .bExtra true, .extra HouseID);
            
gHouseData[HouseID][HouseOpened] = false;
            
House_CreateEntrance(HouseID);
            
TotalHouses++;
        }
    }
    for (new 
HouseID 2HouseID MAX_HOUSESHouseID++)
    {
        if(
fexist(House_File(HouseID)))
        {
            
INI_ParseFile(House_File(HouseID), "LoadHouse_%s", .bExtra true, .extra HouseID);
            
gHouseData[HouseID][HouseOpened] = false;
            
House_CreateEntrance(HouseID);
            
TotalHouses++;
        }
    }
    return 
1;
}
//OnPlayerConnect(playerid)
if(fexist(UserPath(playerid)))
        
INI_ParseFile(UserPath(playerid), "Load_%s", .bExtra true, .extra playerid);
public 
Load_playerdata(playeridname[], value[])
{
    new
        
BusIndex,
        
HouseIndex
    
;
    
INI_Int("MoneyBoost",       pInfo[playerid][MoneyBoost]);
    
INI_Int("BoostTime",        pInfo[playerid][BoostTime]);
    
INI_Int("Jailed",           pInfo[playerid][Jailed]);
    
INI_Bool("Muted",           pInfo[playerid][Muted]);
    
INI_Bool("RulesRead",       pInfo[playerid][RulesRead]);
    
INI_Int("Houses",           pInfo[playerid][Houses][HouseIndex]); HouseIndex++;
    
INI_Int("Business",         pInfo[playerid][Business][BusIndex]); BusIndex++;
    return 
1;
}
//OnPlayerDisconnect(playerid, reason)
pData_Save(playerid)
{
    if(!
pInfo[playerid][LoggedIn]) return 1;
    new
        
INI:File INI_Open(UserPath(playerid));
    
INI_SetTag(File"playerdata");
    
INI_WriteInt(File"MoneyBoost",    pInfo[playerid][MoneyBoost]);
    
INI_WriteInt(File"BoostTime",     pInfo[playerid][BoostTime]);
    
INI_WriteInt(File"Jailed",        pInfo[playerid][Jailed]);
    
INI_WriteBool(File"Muted",        pInfo[playerid][Muted]);
    
INI_WriteBool(File"RulesRead",    pInfo[playerid][RulesRead]);
    for (new 
iMAX_HOUSESPERPLAYERi++)
        if (
pInfo[playerid][Houses][i] != 0)
            
INI_WriteInt(File"Houses"pInfo[playerid][Houses][i]);
    for (new 
iMAX_BUSINESSPERPLAYERi++)
        if (
pInfo[playerid][Business][i] != 0)
            
INI_WriteInt(File"Businesses"pInfo[playerid][Business][i]);
    
INI_Close(File);
    for (new 
iMAX_HOUSESPERPLAYERi++)
    {
        if (
pInfo[playerid][Houses][i] != 0)
        {
            
Save_HouseData(pInfo[playerid][Houses][i]);
        }
    }
    for (new 
iMAX_BUSINESSPERPLAYERi++)
        if (
pInfo[playerid][Business][i] != 0)
            
BusinessFile_Save(pInfo[playerid][Business][i]);
    return 
1;
}
//These are working fine tho
forward LoadHouse_data(HouseIDname[], value[]);
public 
LoadHouse_data(HouseIDname[], value[])
{
    
INI_String("HouseName"gHouseData[HouseID][HouseName], 24);
    
INI_Float("HouseX"gHouseData[HouseID][HouseX]);
    
INI_Float("HouseY"gHouseData[HouseID][HouseY]);
    
INI_Float("HouseZ"gHouseData[HouseID][HouseZ]);
    
INI_Int("HouseLevel"gHouseData[HouseID][HouseLevel]);
    
INI_Int("HouseMaxLevel"gHouseData[HouseID][HouseMaxLevel]);
    
INI_Int("HousePrice"gHouseData[HouseID][HousePrice]);
    
INI_Bool("Owned"gHouseData[HouseID][Owned]);
    
INI_String("Owner"gHouseData[HouseID][Owner], 24);
    
INI_Int("Insurance"gHouseData[HouseID][Insurance]);
    return 
1;
}
Save_HouseData(HouseID)
{
    new 
INI:hFile INI_Open(House_File(HouseID));
    
INI_SetTag(hFile"data");
    
INI_WriteString(hFile"HouseName"gHouseData[HouseID][HouseName]);
    
INI_WriteFloat(hFile"HouseX"gHouseData[HouseID][HouseX]);
    
INI_WriteFloat(hFile"HouseY"gHouseData[HouseID][HouseY]);
    
INI_WriteFloat(hFile"HouseZ"gHouseData[HouseID][HouseZ]);
    
INI_WriteInt(hFile"HouseLevel"gHouseData[HouseID][HouseLevel]);
    
INI_WriteInt(hFile"HouseMaxLevel"gHouseData[HouseID][HouseMaxLevel]);
    
INI_WriteInt(hFile"HousePrice"gHouseData[HouseID][HousePrice]);
    
INI_WriteBool(hFile"Owned"gHouseData[HouseID][Owned]);
    
INI_WriteString(hFile"Owner"gHouseData[HouseID][Owner]);
    
INI_WriteInt(hFile"Insurance"gHouseData[HouseID][Insurance]);
    
INI_Close(hFile);
    return 
1;




Re: Need help with these stuffs. - iOxide - 13.09.2014

Dude, the one you modified is to load all the houses that has been created in-game (Which currently works fine). I am talking about the house slots that are stored inside the player data which doesn't load after player reconnects. Its only loading one house not both.

I am guessing the problem is in Load_playerdata function, the HouseIndex isn't counting the second house as far as i guess. But i don't know how to fix it.


Respuesta: Need help with these stuffs. - MikeB - 13.09.2014

well i will think about any solution


Re: Need help with these stuffs. - iOxide - 14.09.2014

/Bump


Re: Need help with these stuffs. - iOxide - 16.09.2014

/Bump, still couldn't fix this bug. Please help!


Re: Need help with these stuffs. - biker122 - 16.09.2014

Can you tell me the 'MAX_HOUSESPERPLAYER' value?


Re: Need help with these stuffs. - iOxide - 16.09.2014

Nevermind, fixed.