SA-MP Forums Archive
LoadPlayer - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: LoadPlayer (/showthread.php?tid=65541)



LoadPlayer - Think - 13.02.2009

Is it possible to load a players account and set some variables and close teh account again?

pawn Код:
public LoadPlayer(loaderid,const string[])
{
    new string2[64];
    new loaded = loaderid;
    new valtmp[128];
    format(string2, sizeof(string2), "/users/%s.user", string);
    new File: file = fopen(string2, io_read);
    if (file)
    {
            fread(file, valtmp);strmid(PLlayerInfo[loaded][plPassword], valtmp, 0, strlen(valtmp)-1, 255);
            fread(file, valtmp);PLlayerInfo[loaded][plCash] = strval(valtmp);DelPrint(valtmp);
            fread(file, valtmp);PLlayerInfo[loaded][plAccount] = strval(valtmp);DelPrint(valtmp);
            fread(file, valtmp);PLlayerInfo[loaded][plAdmin] = strval(valtmp);DelPrint(valtmp);
      fread(file, valtmp);PLlayerInfo[loaded][plRank] = strval(valtmp);DelPrint(valtmp);
            fread(file, valtmp);PLlayerInfo[loaded][plJRank] = strval(valtmp);DelPrint(valtmp);
            fread(file, valtmp);PLlayerInfo[loaded][plLevel] = strval(valtmp);DelPrint(valtmp);
            fread(file, valtmp);PLlayerInfo[loaded][plExp] = strval(valtmp);DelPrint(valtmp);
            fread(file, valtmp);PLlayerInfo[loaded][glPupgrade] = strval(valtmp);DelPrint(valtmp);
            fread(file, valtmp);PLlayerInfo[loaded][plKills] = strval(valtmp);DelPrint(valtmp);
            fread(file, valtmp);PLlayerInfo[loaded][plCB] = strval(valtmp);DelPrint(valtmp);
            fread(file, valtmp);PLlayerInfo[loaded][plHW] = strval(valtmp);DelPrint(valtmp);
            fread(file, valtmp);PLlayerInfo[loaded][plSR] = strval(valtmp);DelPrint(valtmp);
            fread(file, valtmp);PLlayerInfo[loaded][plWA] = strval(valtmp);DelPrint(valtmp);
            fread(file, valtmp);PLlayerInfo[loaded][plPEN] = strval(valtmp);DelPrint(valtmp);
            fread(file, valtmp);PLlayerInfo[loaded][plGun1] = strval(valtmp);DelPrint(valtmp);
            fread(file, valtmp);PLlayerInfo[loaded][plGun2] = strval(valtmp);DelPrint(valtmp);
            fread(file, valtmp);PLlayerInfo[loaded][plGun3] = strval(valtmp);DelPrint(valtmp);
            fread(file, valtmp);PLlayerInfo[loaded][plGun4] = strval(valtmp);DelPrint(valtmp);
            fread(file, valtmp);PLlayerInfo[loaded][plGun5] = strval(valtmp);DelPrint(valtmp);
            fread(file, valtmp);PLlayerInfo[loaded][plGun6] = strval(valtmp);DelPrint(valtmp);
            fread(file, valtmp);PLlayerInfo[loaded][plAmmo1] = strval(valtmp);DelPrint(valtmp);
            fread(file, valtmp);PLlayerInfo[loaded][plAmmo2] = strval(valtmp);DelPrint(valtmp);
            fread(file, valtmp);PLlayerInfo[loaded][plAmmo3] = strval(valtmp);DelPrint(valtmp);
            fread(file, valtmp);PLlayerInfo[loaded][plAmmo4] = strval(valtmp);DelPrint(valtmp);
            fread(file, valtmp);PLlayerInfo[loaded][plAmmo5] = strval(valtmp);DelPrint(valtmp);
            fread(file, valtmp);PLlayerInfo[loaded][plAmmo6] = strval(valtmp);DelPrint(valtmp);
            fread(file, valtmp);PLlayerInfo[loaded][plSHealth] = floatstr(valtmp);DelPrint(valtmp);
            fread(file, valtmp);PLlayerInfo[loaded][plHealth] = floatstr(valtmp);DelPrint(valtmp);
            fread(file, valtmp);PLlayerInfo[loaded][plPos_x] = floatstr(valtmp);DelPrint(valtmp);
            fread(file, valtmp);PLlayerInfo[loaded][plPos_y] = floatstr(valtmp);DelPrint(valtmp);
            fread(file, valtmp);PLlayerInfo[loaded][plPos_z] = floatstr(valtmp);DelPrint(valtmp);
            fread(file, valtmp);PLlayerInfo[loaded][plLicenseA] = strval(valtmp);DelPrint(valtmp);
            fread(file, valtmp);PLlayerInfo[loaded][plLicenseB] = strval(valtmp);DelPrint(valtmp);
            fread(file, valtmp);PLlayerInfo[loaded][plLicenseC] = strval(valtmp);DelPrint(valtmp);
            fread(file, valtmp);PLlayerInfo[loaded][plInt] = strval(valtmp);DelPrint(valtmp);
            fread(file, valtmp);PLlayerInfo[loaded][plLocal] = strval(valtmp);DelPrint(valtmp);
            fread(file, valtmp);PLlayerInfo[loaded][plTeam] = strval(valtmp);DelPrint(valtmp);
            fread(file, valtmp);PLlayerInfo[loaded][plModel] = strval(valtmp);DelPrint(valtmp);
            fread(file, valtmp);PLlayerInfo[loaded][plPnumber] = strval(valtmp);DelPrint(valtmp);
            fread(file, valtmp);PLlayerInfo[loaded][plPhousekey] = strval(valtmp);DelPrint(valtmp);
            fread(file, valtmp);PLlayerInfo[loaded][plPbiskey] = strval(valtmp);DelPrint(valtmp);
            fread(file, valtmp);PLlayerInfo[loaded][plWarnL] = strval(valtmp);DelPrint(valtmp);
            fread(file, valtmp);PLlayerInfo[loaded][plArmour] = floatstr(valtmp);DelPrint(valtmp);
            fread(file, valtmp);PLlayerInfo[loaded][plJailed] = strval(valtmp);DelPrint(valtmp);
            SendClientMessage(loaderid, COLOR_WHITE, "SERVER: Account Loaded");
    }
    else
    {
        SendClientMessage(loaderid, COLOR_WHITE, "SERVER: No account found by that name");
        return 0;
    }
    return 1;
}
^^^^^ loadplayer function.

i want the housekey to be changed.


Re: LoadPlayer - Think - 13.02.2009

maybe saveplayer (how the stats are being saved) comes in handy too xD


pawn Код:
public SavePlayer(loaderid,const string[])
{
    new string3[32];
    new saved = loaderid;
    format(string3, sizeof(string3), "/users/%s.user", string);
    new File: pFile = fopen(string3, io_write);
    if (pFile)
    {
        new var[32];
        format(var, 32, "%s\n", PLlayerInfo[saved][plPassword]);fwrite(pFile, var);
        fclose(pFile);
        new File: hFile = fopen(string3, io_append);
        format(var, 32, "%d pCash\n",PLlayerInfo[saved][plCash]);fwrite(hFile, var);
        format(var, 32, "%d pAccount\n",PLlayerInfo[saved][plAccount]);fwrite(hFile, var);
        format(var, 32, "%d pAdmin\n",PLlayerInfo[saved][plAdmin]);fwrite(hFile, var);
        format(var, 32, "%d pJRank\n",PLlayerInfo[saved][plJRank]);fwrite(hFile, var);
        format(var, 32, "%d pLevel\n",PLlayerInfo[saved][plLevel]);fwrite(hFile, var);
        format(var, 32, "%d pExp\n",PLlayerInfo[saved][plExp]);fwrite(hFile, var);
        format(var, 32, "%d gPupgrade\n",PLlayerInfo[saved][glPupgrade]);fwrite(hFile, var);
        format(var, 32, "%d pKills\n",PLlayerInfo[saved][plKills]);fwrite(hFile, var);
        format(var, 32, "%d pCB\n",PLlayerInfo[saved][plCB]);fwrite(hFile, var);
        format(var, 32, "%d pHW\n",PLlayerInfo[saved][plHW]);fwrite(hFile, var);
        format(var, 32, "%d pSR\n",PLlayerInfo[saved][plSR]);fwrite(hFile, var);
        format(var, 32, "%d pWA\n",PLlayerInfo[saved][plWA]);fwrite(hFile, var);
        format(var, 32, "%d pPEN\n",PLlayerInfo[saved][plPEN]);fwrite(hFile, var);
        format(var, 32, "%d pGun1\n",PLlayerInfo[saved][plGun1]);fwrite(hFile, var);
        format(var, 32, "%d pGun2\n",PLlayerInfo[saved][plGun2]);fwrite(hFile, var);
        format(var, 32, "%d pGun3\n",PLlayerInfo[saved][plGun3]);fwrite(hFile, var);
        format(var, 32, "%d pGun4\n",PLlayerInfo[saved][plGun4]);fwrite(hFile, var);
        format(var, 32, "%d pGun5\n",PLlayerInfo[saved][plGun5]);fwrite(hFile, var);
        format(var, 32, "%d pGun6\n",PLlayerInfo[saved][plGun6]);fwrite(hFile, var);
        format(var, 32, "%d pGun7\n",PLlayerInfo[saved][plGun7]);fwrite(hFile, var);
        format(var, 32, "%d pAmmo1\n",PLlayerInfo[saved][plAmmo1]);fwrite(hFile, var);
        format(var, 32, "%d pAmmo2\n",PLlayerInfo[saved][plAmmo2]);fwrite(hFile, var);
        format(var, 32, "%d pAmmo3\n",PLlayerInfo[saved][plAmmo3]);fwrite(hFile, var);
        format(var, 32, "%d pAmmo4\n",PLlayerInfo[saved][plAmmo4]);fwrite(hFile, var);
        format(var, 32, "%d pAmmo5\n",PLlayerInfo[saved][plAmmo5]);fwrite(hFile, var);
        format(var, 32, "%d pAmmo6\n",PLlayerInfo[saved][plAmmo6]);fwrite(hFile, var);
        format(var, 32, "%d pAmmo7\n",PLlayerInfo[saved][plAmmo7]);fwrite(hFile, var);
        format(var, 32, "%.1f pSHealth\n", PLlayerInfo[saved][plSHealth]);fwrite(hFile, var);
        format(var, 32, "%.1f pHealth\n", PLlayerInfo[saved][plHealth]);fwrite(hFile, var);
        format(var, 32, "%.1f pPos_x\n", PLlayerInfo[saved][plPos_x]);fwrite(hFile, var);
        format(var, 32, "%.1f pPos_y\n", PLlayerInfo[saved][plPos_y]);fwrite(hFile, var);
        format(var, 32, "%.1f pPos_z\n", PLlayerInfo[saved][plPos_z]);fwrite(hFile, var);
        format(var, 32, "%d pLicenseA\n",PLlayerInfo[saved][plLicenseA]);fwrite(hFile, var);
        format(var, 32, "%d pLicenseB\n",PLlayerInfo[saved][plLicenseB]);fwrite(hFile, var);
        format(var, 32, "%d pLicenseC\n",PLlayerInfo[saved][plLicenseC]);fwrite(hFile, var);
        format(var, 32, "%d pInt\n",PLlayerInfo[saved][plInt]);fwrite(hFile, var);
        format(var, 32, "%d pLocal\n",PLlayerInfo[saved][plLocal]);fwrite(hFile, var);
        format(var, 32, "%d pTeam\n",PLlayerInfo[saved][plTeam]);fwrite(hFile, var);
        format(var, 32, "%d pModel\n",PLlayerInfo[saved][plModel]);fwrite(hFile, var);
        format(var, 32, "%d pPnumber\n",PLlayerInfo[saved][plPnumber]);fwrite(hFile, var);
        format(var, 32, "%d pPhousekey\n",PLlayerInfo[saved][plPhousekey]);fwrite(hFile, var);
        format(var, 32, "%d pPbiskey\n",PLlayerInfo[saved][plPbiskey]);fwrite(hFile, var);
        format(var, 32, "%d pDuty\n",PLlayerInfo[saved][plDuty]);fwrite(hFile, var);
        format(var, 32, "%d pDrugs\n",PLlayerInfo[saved][plDrugs]);fwrite(hFile, var);
        format(var, 32, "%d pWarnL\n",PLlayerInfo[saved][plWarnL]);fwrite(hFile, var);
        format(var, 32, "$.1f pSArmour\n",PLlayerInfo[saved][plArmour]);fwrite(hFile,var);
        format(var, 32, "%d pJailed\n",PLlayerInfo[saved][plJailed]);fwrite(hFile, var);
        fclose(hFile);
    }
    return 1;
}



Re: LoadPlayer - Grove - 13.02.2009

I don't understand. You can just use fclose after you have loaded the info and assigned variables to it to close the file.