![]() |
#1 |
Godfather
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Apr 2010
Location: Brazil, Caxias RS
Posts: 6,094
Reputation: 536
|
![]() Arquivos Temporários ATUALIZADO - ARMAZENA TEMPO MESMO AO FECHAR SERVIDOR 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 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 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: 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! Last edited by ipsBruno; 14/06/2012 at 03:43 AM. |
![]() |
![]() |
![]() |
#2 |
High-roller
![]() ![]() ![]() ![]() ![]() Join Date: Mar 2012
Posts: 1,126
Reputation: 98
|
![]()
Muito bom, parabéns Drakins!
Você coda Squirrel ou lua? Porque seu comandos não começam com maiúsculos o.O (Exemplo: alterarTempo) |
![]() |
![]() |
![]() |
#3 |
Gangsta
![]() ![]() ![]() ![]() Join Date: Apr 2012
Location: Rio de Janeiro
Posts: 799
Reputation: 23
|
![]()
Gostei
![]() |
![]() |
![]() |
![]() |
#4 | |
Gangsta
![]() ![]() ![]() ![]() Join Date: May 2012
Location: Ji-Parana - RO ,Brazil
Posts: 782
Reputation: 63
|
![]()
Muito Bom , Explicando cada aprte do codigo , exelente .
Somente não entendi essa parte : Quote:
|
|
![]() |
![]() |
![]() |
#5 |
Gangsta
![]() ![]() ![]() ![]() Join Date: Apr 2012
Location: Rio de Janeiro
Posts: 799
Reputation: 23
|
![]()
Quer dizer o título diz tudo Ades Arquivos Temporários mais se você der GMX com o settimer correndo ele não ira deletar e quando o server voltar ele vai continuar novamente do começo
Espero ter explicado ![]() |
![]() |
![]() |
![]() |
#6 |
Gangsta
![]() ![]() ![]() ![]() Join Date: Mar 2012
Location: Na 9 Lua De Saturno,8 Galaxia do Universo
Posts: 558
Reputation: 55
|
![]()
Enfim Gostei Muito Do Código, Muitas Pessoas irá utilizar tenho quase certeza.
Pois com ela da pra colocar Admin Por Tempo,Horas,Dias Sem se preocupar. Muito Utilizavel. Obrigado por compartilhar. |
![]() |
![]() |
![]() |
#7 | ||
Godfather
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Apr 2010
Location: Brazil, Caxias RS
Posts: 6,094
Reputation: 536
|
![]() Quote:
![]() Quote:
- OFF Na verdade, tempo eu tenho, mas agora eu sinto a necessidade profunda de ir secar o Grêmio contra o Palmeiras. Fuuiiz |
||
![]() |
![]() |
![]() |
#8 |
High-roller
![]() ![]() ![]() ![]() ![]() Join Date: Mar 2012
Posts: 1,126
Reputation: 98
|
![]() |
![]() |
![]() |
![]() |
#9 | |
Godfather
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Apr 2010
Location: Brazil, Caxias RS
Posts: 6,094
Reputation: 536
|
![]() Quote:
terão ** - Até amanha terei atualizado isto como include e tudo. Até lá, estudem a função. É simples. Como o amigo acima disse, é bom para sistemas temporizadores, temp-ban, temp-vip, temp-weapon .. etc |
|
![]() |
![]() |
![]() |
#10 |
Gangsta
![]() ![]() ![]() ![]() Join Date: May 2012
Location: Ji-Parana - RO ,Brazil
Posts: 782
Reputation: 63
|
![]()
Brigado por esclarecer minha duvida
![]() |
![]() |
![]() |
![]() |
Thread Tools | |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
[Ajuda] Comandos Temporarios | leonardo1434 | Português/Portuguese | 11 | 15/05/2012 03:59 PM |
[AJUDA] Include de criar cmd de login/registro em dialog | Spock | Português/Portuguese | 1 | 25/03/2011 05:02 PM |
[Ajuda] Oque Tem de errado neste codigo Codigo | Twisted_. | Português/Portuguese | 6 | 24/03/2011 12:39 AM |
[Pedido] Veículos temporários | Magnus' | Português/Portuguese | 3 | 01/01/2011 05:40 PM |
[DUV] Associar arquivos | DartakousLien | Português/Portuguese | 0 | 27/01/2010 11:15 PM |