[Pedido] Jeito para que nгo de lag nisso...
#1

Ola galerinha...
Eu tenho um sistema de armas salvбveis em meu gamemode, e puis em OnPlayerUpdate o seguinte script;
pawn Code:
SaveWeapons(playerid);
Porйm desta forma, meu servidor fica com um lag enorme, pois fica salvando rapidamente as armas de todos os players onlines.
Como eu poderia fazer com que essas armas salvassem sem causar lag no servidor?
Reply
#2

Vocк quer salvar por que? Pra quando entra no jogo voltar com o mesmo armamento?
Se sim, coloque em OnPlayerDisconnect isso e nгo em OnPlayerUpdate.
Reply
#3

Jб tentei por em OnPlayerDisconnect, mais quando o servidor reinicia ou o player reloga, ele perde o armamento...
Tem que por de um jeito que salve enquanto o player ainda esteja online...
Reply
#4

Exato, coloque no OnPlayerDisconnect para salvar, e para carregar OnPlayerConnect.
Reply
#5

Tenta usar:
pawn Code:
OnGamemodeInit()
{
    SetTimer("UpdateWeapons", 5000, true);
    return 1;
}

forward UpdateWeapons();
public UpdateWeapons()
                    return for(new x = 0; x < MAX_PLAYERS; x ++) SaveWeapons(x);
Reply
#6

Quote:
Originally Posted by Kuddy
View Post
Tenta usar:
pawn Code:
OnGamemodeInit()
{
    SetTimer("UpdateWeapons", 5000, true);
    return 1;
}

forward UpdateWeapons();
public UpdateWeapons()
                    return for(new x = 0; x < MAX_PLAYERS; x ++) SaveWeapons(x);
Deu um erro...
pawn Code:
error 029: invalid expression, assumed zero
Linha:
pawn Code:
return for(new x = 0; x < MAX_PLAYERS; x ++) SaveWeapons(x);
Reply
#7

UP...
Reply
#8

Peguei a Base do cmd do Kuddy e Modifiquei

pawn Code:
OnGamemodeInit()
{
    SetTimer("UpdateArmas", 30000, true);
    return 1;
}

forward UpdateArmas();
public UpdateArmas()
{
    for(new i = 0; i < MAX_PLAYERS; i ++)
    {
        SaveWeapons(i);
    }
}
Reply
#9

Quote:
Originally Posted by Murilo_sousa
View Post
Peguei a Base do cmd do Kuddy e Modifiquei

pawn Code:
OnGamemodeInit()
{
    SetTimer("UpdateArmas", 30000, true);
    return 1;
}

forward UpdateArmas();
public UpdateArmas()
{
    for(new i = 0; i < MAX_PLAYERS; i ++)
    {
        SaveWeapons(i);
    }
}
Agora foi, obrigado...
Tambйm pensei em por o SaveWeapons quando comprar a arma...
Mas acho que vou utilizar os dois modos
Reply
#10

pawn Code:
OnGamemodeInit()
{
    SetTimer("UpdateArmas", 30000, true);
    return 1;
}

forward UpdateArmas();
public UpdateArmas()
{
    for(new i = 0; i < MAX_PLAYERS; i ++)
    {
        SaveWeapons(i);
    }
    return 1;
}
Correзгo*
Reply
#11

Quote:
Originally Posted by Kuddy
View Post
pawn Code:
OnGamemodeInit()
{
    SetTimer("UpdateArmas", 30000, true);
    return 1;
}

forward UpdateArmas();
public UpdateArmas()
{
    for(new i = 0; i < MAX_PLAYERS; i ++)
    {
        SaveWeapons(i);
    }
    return 1;
}
Correзгo*
Pelo visto tambйm nгo funcionou em meu servidor :l
Reply
#12

Quote:
Originally Posted by Ley
View Post
Pelo visto tambйm nгo funcionou em meu servidor :l
Entгo o erro e no SaveWeapons

Poste ele ou me mande MP com ela (:
Reply
#13

pawn Code:
stock SaveWeapons(playerid)
{
    new File:arquivo, File:ftmp, tmp[256], fname[30], pname[30], arma[13], municao[13];
    arquivo = fopen(WEAPON_FILE, io_readwrite);
    ftmp = fopen(WEAPON_FILE#.tmp, io_write);
    GetPlayerName(playerid, pname, sizeof pname);
    while(fread(arquivo, tmp, sizeof tmp, false))
    {
        new off[256], index;
        off = strtok(tmp, index);
        strmid(fname, off, 0, strlen(off));
        if(!strcmp(pname, fname, false))continue;
        format(tmp, sizeof tmp, "%s", tmp);
        fwrite(ftmp, tmp);
    }
    fclose(arquivo);
    fclose(ftmp);
    fremove(WEAPON_FILE);
    arquivo = fopen(WEAPON_FILE, io_write);
    ftmp = fopen(WEAPON_FILE#.tmp, io_read);
    while(fread(ftmp, tmp))
    {
        format(tmp, sizeof tmp, "%s", tmp);
        fwrite(arquivo, tmp);
    }
    fclose(ftmp);
    fremove(WEAPON_FILE#.tmp);
    for(new i; i < 12; i++)GetPlayerWeaponData(playerid, i+1, arma[i+1], municao[i+1]);
    format(tmp, sizeof tmp, "%s ", pname);
    for(new a; a < 24; a++)
    {
        new s[10];
        if(a < 12)
        {
            format(s, sizeof s, "%d ", arma[a]);
            strcat(tmp, s);
        } else {
            format(s, sizeof s, "%d ", municao[a-12]);
            strcat(tmp, s);
        }
    }
    strcat(tmp, "\r\n");
    fwrite(arquivo, tmp);
    fclose(arquivo);
    return 1;
}
Reply
#14

UP...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)