[Include] Southclaw INI file
#1

Tуpico original:
https://sampforum.blast.hk/showthread.php?tid=262795
Tenho permissхes do autor p/postar aqui!

Resumo do tуpico:
Quote:
Originally Posted by Sothclaw
Dou crйdito para [FEK] DraKins, por ter usado o FINI para aprender a ultilizar Cache.
Uma das caracterнsticas й a correзгo de bug em Windows e Linux de linha ( \r \n)
pawn Код:
//Caso vocк esteje usando Windows, defina no OnGameModeInit:
file_OS(WINDOWS);
//Caso vocк esteje usando LINUX, defina no OnGameModeInit
file_OS(LINUX);
Atualizaзхes:
- Adicionado file_SetFloat e file_GetFloat
- Adicionado file_IncVal (veja abaixo a descriзгo)
- Adicionado separadores para as funзхes do Pawn


Funзхes:

pawn Код:
// - Ediзгo

file_Create(filename[])
// Cria um arquivo com o nome <filename> sem esquecer da extensгo ( .txt .ini.cfg )
file_Delete(filename[])
// Deleta o arquivo com o nome <filename>

// - Abrindo e fechando

file_Open(filename[])
//Abre o arquivo <filename> e salva os arquivos na memуria [Ele nгo vai ler arquivos sem o sinal ' = ' ]

// <NOTA>  Nгo abra vбrios arquivos em um sу cуdigo, use file_Close e depois abra o outro arquivo!

file_Save(filename[])
// Salva o arquivo <filename>
// Vocк nгo precisa salvar o arquivo ao ler o mesmo.

file_Close()
//Sempre use file_Close para fechar o arquivo, nгo abra vбrios arquivos sem fechбr os mesmos.

//- Escrevendo

file_SetStr(key[], value[])
//Escreve uma STRING na KEY

file_SetVal(key[], value)
//Escreve um VALOR na KEY

file_SetFloat(key[], value)
//Escreve uma FLOAT na KEY

file_IncVal(key[], amount)
//Just a simple macro to save space when writing, Increments the value of <key> by <amount>

file_Remove(key[])
//Remove a KEY do arquivo.

//- LENDO

file_GetStr(key[])
//Retorna a string do arquivo

file_GetVal(key[])
// Retorna o valor da Key

Float:file_GetFloat(key[])
// Retorna a Float da Key

file_IsKey(key[])
//Checa se a chave й valida

// < - Outros >

file_PrintAll()
//Jб se diz por sн sу.

file_OS(type = LINUX or WINDOWS)
//USE ISSO PARA DEFINIR O SISTEMA OPERACIONAL EM 'OnGameModeInit' ( ex: file_OS(WINDOWS); )
Download:

Pastebin


Exemplos:

PHP код:
#include <a_samp>
#include <inifile>
stock SalvarDados(playerid)
{
    new 
arquivo[0x30], nome[0x20]; GetPlayerName(playeridnomesizeof(nome));
    
format(arquivosizeof(arquivo), "%s.ini"nome);
    if(!
fexist(arquivo)) file_Create(arquivo); //Caso nгo exista
    
file_Open(arquivo); // Abre o arquivo.
    
file_SetVal("Dinheiro"GetPlayerMoney(playerid)); // SETA um VALOR no arquivo
    
file_SetVal("Skin"GetPlayerSkin(playerid)); // SETA UM VALOR NO ARQUIVO
    
file_SetVal("Score"GetPlayerScore(playerid)); //SETA UM VALOR NO ARQUIVO
    
file_SetStr("Ricop522""Lindo"); //SETA UMA STRING NO ARQUIVO
    
file_Save(arquivo);  //SALVA !
    
file_Close();//Fecha
    
return 0x01;
}
stock CarregarDados(playerid)
{
    new 
arquivo[0x30], nome[0x20]; GetPlayerName(playeridnomesizeof(nome));
    
format(arquivo,sizeof(arquivo),"%s.txt",nome);
    if(!
fexist(arquivo)) file_Create(arquivo); //Caso nгo exista, ele cria o arquivo
    
file_Open(arquivo);
    
GivePlayerMoney(playeridfile_GetVal("Dinheiro"));
    
SetPlayerSkin(playeridfile_GetVal("Skin"));
    
SetPlayerScore(playeridfile_GetVal("Score"));
    
//Carregar arquivos: file_GetStr("Ricop522");
    
file_Close();
    return 
0x01;

Crйditos: Southclaw
Tutorial: Ricop522

___________________________
Reply


Messages In This Thread
Southclaw INI file - by Ricop522 - 19.06.2011, 20:45
Respuesta: Southclaw INI file - by ScripterTroll - 19.06.2011, 20:49
Re: Southclaw INI file - by Ricop522 - 19.06.2011, 20:51
Respuesta: Southclaw INI file - by ScripterTroll - 19.06.2011, 21:23
Respuesta: Southclaw INI file - by ScripterTroll - 19.06.2011, 21:37
Re: Southclaw INI file - by RockFire - 19.06.2011, 22:16
Re: Southclaw INI file - by Ricop522 - 19.06.2011, 23:16
Re: Southclaw INI file - by Falcon. - 20.06.2011, 00:38
Re: Southclaw INI file - by DreeH - 20.06.2011, 00:50

Forum Jump:


Users browsing this thread: 1 Guest(s)