pawn Code:
#include <a_samp> // Redefina aqui em caso de for necessário #define fp%0(%1) forward %0(%1); public %0(%1) #if !defined MAX_FILE_NAME #define MAX_FILE_NAME 32 #endif #if !defined MAX_TEMP_FILES #define MAX_TEMP_FILES 100 #endif // Declarar variáveis novas enum bsInfo { szFilename[MAX_FILE_NAME], fileTime } new bstempFile[MAX_TEMP_FILES][bsInfo], bsTotalfiles = -1; // Ao iniciar script, chamar a pública para checar os arquivos // Carregar o arquivo nas arrays public OnFilterScriptInit() { if(fexist("filesrename.bs")) { new File:file = fopen("filesrename.bs", io_read), File:time = fopen("filestimers.bs", io_read), stringRename[MAX_TEMP_FILES * MAX_FILE_NAME char], stringTimers[MAX_TEMP_FILES * 13 char]; fread(file, stringRename, (MAX_TEMP_FILES * MAX_FILE_NAME) >> 2, true); // >> 2 para adaptar a char fread(time, stringTimers, (MAX_TEMP_FILES * 13) >> 2, true); // 13 pois pawn só aceita números com +- 13 algarismos fclose(file); fclose(time); bsTotalfiles++; // Carregar nomes arquivos for(new x, j = -1; stringRename{x}; x++) { if(stringRename{x} == '>') { j = -1; bsTotalfiles++; } else { bstempFile[bsTotalfiles][szFilename][++j] = stringRename{x}; } } bsTotalfiles = 0; // Carregar tempos for(new x, j = -1, stringTemp[13]; stringTimers{x}; x++) { if(stringTimers{x} == '|') { j = -1; bsTotalfiles++; bstempFile[bsTotalfiles][fileTime] = strval(stringTemp); stringTemp[0] = EOS; } else { stringTemp[++j] = stringTimers{x}; } } fremove("filesrename.bs"); fremove("filestimers.bs"); printf("Arquivos temporários carregados: %d", bsTotalfiles); } return SetTimer("checarArquivos", 998, true); // 998 ms. Para demorar em torno de 1 segundo (2 ms execução callback) } // Exportar array para arquivo // Assim pode carregar os dados posteriormente public OnFilterScriptExit() { new File:file = fopen("filesrename.bs", io_write), File:time = fopen("filestimers.bs", io_write); for(new i; i <= bsTotalfiles; i++) { if(gettime() <= bstempFile[i][fileTime]) { if(fexist(bstempFile[i][szFilename])) { if(file) { fwrite(file, bstempFile[i][szFilename]); fwrite(time, intToStr(bstempFile[i][fileTime])); fwrite(file, ">"); fwrite(time, "|"); } } } } if(file) { fclose(file); fclose(time); } return true; } // Checar se o tempo do arquivo já passou do inválido // Aqui é deletado o arquivo após x tempo fp checarArquivos() { for(new i; i <= bsTotalfiles; i++) { if(gettime() >= bstempFile[i][fileTime]) { if(fexist(bstempFile[i][szFilename])) { fremove(bstempFile[i][szFilename]); CallRemoteFunction("OnTemporaryDeleteFile", "s", bstempFile[i][szFilename]); } } } return true; } // Função para criar o arquivoTemporario // Bastando especificar os segundos e o arquivo fp arquivoTemporario(arquivo[], segundos) { // caso arquivo já existir editar tempo atual if(fexist(arquivo)) { alterarTempo(arquivo, segundos); } static File:file; if((file = fopen(arquivo, io_write))) { strcat(bstempFile[++bsTotalfiles][szFilename], arquivo, MAX_FILE_NAME); return fclose(file), bstempFile[bsTotalfiles][fileTime] = (gettime() + segundos); } return false; } // Função para alterar o tempo de deletação do arquivo. // Partindo o tempo atual fp alterarTempo(arquivo[], segundos) { new cmd = prev_strcmp(arquivo); for(new i; i <= bsTotalfiles; i++) { if(cmd == prev_strcmp(bstempFile[i][szFilename])) { if(!strcmp(arquivo, bstempFile[i][szFilename], true)) { return bstempFile[i][fileTime] = gettime() + segundos; } } } return false; } // Ajudar na velocidade de comparação de strings // Sistema simples de conta caracteres, compara dados números é mais veloz fp prev_strcmp(string[]) { new j; for(new i; string[i]; i++) { j += string[i]; } return j; } // Transformar valor em string // Sem declarar strings chatas intToStr(valor) { new szString[13]; format(szString, 13, "%i", valor); return szString; }
Cria um arquivo especificando os segundos para ele ser deletado.
Simples uso
pawn Code:
arquivoTemporario("bruno.txt", 10);
Modo de uso.
1 Primeiramente salve o código ali encima como filterscript e carregue-o no server.cfg ATENCAO. O código acima deve ser salvo como um filterscript e carregado.
2 Coloque isto no seu game mode . No GAME MODE o código abaixo
pawn Code:
#define alterarTempo(%0,%1) CallRemoteFunction("alterarTempo", "si", %0,%1) #define arquivoTemporario(%0,%1) CallRemoteFunction("arquivoTemporario", "si", %0,%1) forward OnDeleteTempFile(file[]);
3 Agora só usar as funções definidas acima em seu gamemode

Exemplo - Funções para VIP
Umas funções vips:
pawn Code:
stock darVip(playerid, dias) { static namePlayer[MAX_PLAYER_NAME + 25] ; GetPlayerName(playerid, namePlayer, MAX_PLAYER_NAME); format(namePlayer, MAX_PLAYER_NAME + 25], "/pastaVips/%s.ini", namePlayer); arquivoTemporario(namePlayer, dias * 60 * 60 * 24); // x * 60 = 1 minuto // x * 60 * 60 = 1 hora // x * 60 * 60 * 24 = 1 dia } stock remVip(playerid) { static namePlayer[MAX_PLAYER_NAME + 25] ; GetPlayerName(playerid, namePlayer, MAX_PLAYER_NAME); format(namePlayer, MAX_PLAYER_NAME + 25], "/pastaVips/%s.ini", namePlayer); alterarTempo(namePlayer, 0); // 0 = deleta arquivo na hora } stock chkVip(playerid) { static namePlayer[MAX_PLAYER_NAME + 25] ; GetPlayerName(playerid, namePlayer, MAX_PLAYER_NAME); format(namePlayer, MAX_PLAYER_NAME + 25], "/pastaVips/%s.ini", namePlayer); return fexist(namePlayer); }
Observações
OnDeleteTempFile será chamada com nome do arquivo cada vez que o arquivo é deletado após determinado tempo
Não ocorre lag no servidor. Já coloquei um sistema de comparação de strings similar ao do Bini e DOF2 usando dados númericos para diminuir caso tiver latência. Mesmo não tendo usando "string compare" direto

* Nenhum erro encontrado *
Abraços!

---------------------------------------------------