[SOLVED][Advanced]Help with changing variables in ALL offline user accounts :S
#1

OK, well i have a big problem here =/
I m trying to reset the variable "vowner" and "vowned" to 0 in ALL of the user files, i am trying to make the server:
1. Add the username to a list in the acounts folder.
2. Read the list and change the variables for all the users in the list

Sounds easy, but i cant get it figured out, here is what i have so far:

In the register command
pawn Код:
new filestring[256];
        new File: pvfile = fopen("/ladmin/users/players.txt", io_write);
        format(filestring, sizeof(filestring), "%s\n", PlayerInfo[playerid][name] );
        fwrite(pvfile, filestring);
        fclose(pvfile);
This is called to change the variables:
pawn Код:
stock aresetallcar()
{
    for(new i = 1; i < MAX_PLAYERS; i++){
        if(IsPlayerConnected(i)) {
            PlayerInfo[i][vowned] = 0;
            PlayerInfo[i][vowner] = 0;
            SavePlayer(i);
        }
    }
    for(new v = 1; v < MAX_VEHICLES; v++){
        SetVehicleToRespawn(v);
        SetVehicleVirtualWorld(v,10);
        EraseVehicle(v);
    }
    if(fexist("/ladmin/users/players.txt")) {
    new rvpname[MAX_PLAYER_NAME];
    new SplitDiv[99][MAX_VEHICLES];
        new filestring[256];
        new File: file = fopen("/ladmin/users/players.txt", io_read);
        if (file) {
        fread(file, filestring);
            split(filestring, SplitDiv, ',');
            strmid(rvpname, SplitDiv[0], 0, strlen(SplitDiv[0]), 255);
        }
        fclose(file);
        ResetOfflinePlayerFile(rvpname);
    }
    return 1;
}
EDIT: Solved with:
pawn Код:
stock aresetallcar()
{
    for(new v = 0; v < MAX_VEHICLES; v++){
        DestroyVehicle(v);
    }
    for(new p = 0; p < MAX_PLAYERS; p++){
      if(IsPlayerConnected(p) == 1) {
            PlayerInfo[p][vowner] = 0;
            PlayerInfo[p][vowned] = 0;
        }
    }
    new buf[64], i;
    i = 0;
    while(ffind("ladmin/users/*.sav", buf, sizeof(buf), i))
    {
        new fname[MAX_STRING];
        format(fname,sizeof(fname),"ladmin/users/%s",buf);
        dini_IntSet(fname, "vowner", 0);
        dini_IntSet(fname, "vowned", 0);
    }
}
Reply
#2

YSF has a function called ffind, this could be used to get the player files.
For example:
pawn Код:
new buf[64];
new i = 0;
while(ffind("players/*.txt", buf, 64, i))
{
    dini_IntSet(buf, "Vowner", 0);
    dini_IntSet(buf, "Vowned", 0);
}
Though YSF works only on 0.2 and 0.3 R3
Reply
#3

hmm, interesting, i will try merge YSF into my gamemode and see how it works XD

EDIT: there is an unofficial version that works on R4

EDIT2: hmm well i tried it and i removed the stuff from the register command, now have:

pawn Код:
stock aresetallcar()
{
    for(new v = 1; v < MAX_VEHICLES; v++){
        SetVehicleToRespawn(v);
        SetVehicleVirtualWorld(v,10);
        EraseVehicle(v);
    }
    new buf[64];
    new i = 0;
    while(ffind("ladmin/users/*.sav", buf, sizeof(buf), i))
    {
        dini_IntSet(buf, "vowner", 0);
        dini_IntSet(buf, "vowned", 0);
    }
}
Reply
#4

hmmm, i am currently stuck with:
pawn Код:
stock aresetallcar()
{
    new buf[64], i;
    i = 0;
    while(ffind("ladmin/users/*.sav", buf, sizeof(buf), i))
    {
        dUserSetINT(buf).("vowner", 0);
        dUserSetINT(buf).("vowned", 0);
    }
    for(new p = 0; p < MAX_PLAYERS; p++){
      if(IsPlayerConnected(p) == 1) {
            PlayerInfo[p][vowner] = 0;
            PlayerInfo[p][vowned] = 0;
        }
    }
    for(new v = 0; v < MAX_VEHICLES; v++){
        DestroyVehicle(v);
    }
}
And it still fails to change the variables from the user files in the folder :S
please someone help me out :S

BTW i have got the latest version of YSF :S
Reply
#5

Why not make a new variable to save, then when a player joins with that old variable you reset it, and when the leave you give their file the new variable.
Reply
#6

hmm, i am thinking, but how would i make the server not give them this new variable everytime they logon

EDIT: Solved with:
pawn Код:
stock aresetallcar()
{
    for(new v = 0; v < MAX_VEHICLES; v++){
        DestroyVehicle(v);
    }
    for(new p = 0; p < MAX_PLAYERS; p++){
      if(IsPlayerConnected(p) == 1) {
            PlayerInfo[p][vowner] = 0;
            PlayerInfo[p][vowned] = 0;
        }
    }
    new buf[64], i;
    i = 0;
    while(ffind("ladmin/users/*.sav", buf, sizeof(buf), i))
    {
        new fname[MAX_STRING];
        format(fname,sizeof(fname),"ladmin/users/%s",buf);
        dini_IntSet(fname, "vowner", 0);
        dini_IntSet(fname, "vowned", 0);
    }
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)