[Tutorial] [TUT] Salvamento de Dados
#1

Bom Vou Aqui Postar um Tutorial de Como Salvar/Carregar Algumas Coisas com a Dini
Primeiramente Baixem a Include:
http://dracoblue.net/download-release/35/dini_1_6.zip
Adicionem Dini.INC na Pasta PAWNO/INCLUDES


Agora Vamos "Codar"
Primeiramente Ao Topo do GM:

pawn Код:
#include <Dini>
[b]_________________________
Agora Vamos Algums Cуdigos
*Salvar Money
*Salvar Skin
*Salvar Score
*Salvar Armas
*Salvar Vida
*Salvar Colete
*Salvar Nнvel Procurado
*Salvar Cor do Player
*Salvar IP (para Admin Ver IP)

__________________________________________________ _____________________________
[size=15pt]Salvar Skins
Em OnPlayerSpawn:
pawn Код:
if(dini_Isset("skins.ini",PlayerName(playerid))) SetPlayerSkin(playerid,dini_Int("skins.ini",PlayerName(playerid)));
em OnPlayerDisconnect:
pawn Код:
dini_IntSet("skins.ini",PlayerName(playerid),GetPlayerSkin(playerid));
Em OnGameModeInit:
pawn Код:
if(!fexist("skins.ini")) dini_Create("skins.ini");
[size=15pt]Salvar Money
Em OnPlayerConnect:
pawn Код:
if(dini_Isset("dinheiro.ini",PlayerName(playerid))) GivePlayerMoney(playerid,dini_Int("dinheiro.ini",PlayerName(playerid)));
em OnPlayerDisconnect:
pawn Код:
dini_IntSet("dinheiro.ini",PlayerName(playerid),GetPlayerMoney(playerid));
Em OnGameModeInit:[b]
pawn Код:
if(!fexist("dinheiro.ini")) dini_Create("dinheiro.ini");
[size=15pt]Salvar Score
Em OnPlayerConnect:
pawn Код:
if(dini_Isset("score.ini",PlayerName(playerid))) SetPlayerScore(playerid,dini_Int("score.ini",PlayerName(playerid)));
em OnPlayerDisconnect:
pawn Код:
dini_IntSet("score.ini",PlayerName(playerid),GetPlayerScore(playerid));
Em OnGameModeInit:[b]
pawn Код:
if(!fexist("score.ini")) dini_Create("score.ini");
[size=15pt]Salvar Armas
Em OnPlayerSpawn:
pawn Код:
if(dini_Isset("Weapon.ini",PlayerName(playerid))) GivePlayerWeapon(playerid,dini_Int("Weapon.ini",PlayerName(playerid)));


em OnPlayerDisconnect:
pawn Код:
dini_IntSet("Weapon.ini",PlayerName(playerid),GetPlayerWeapon(playerid));
Em OnGameModeInit:[b]
pawn Код:
if(!fexist("Weapon.ini")) dini_Create("Weapon.ini");
[size=15pt]Salvar Vida
Em OnPlayerSpawn:
pawn Код:
if(dini_Isset("Health.ini",PlayerName(playerid))) SetPlayerHealth(playerid,dini_Int("Health.ini",PlayerName(playerid)));
em OnPlayerDisconnect:
pawn Код:
dini_IntSet("Health.ini",PlayerName(playerid),GetPlayerHealth(playerid));
Em OnGameModeInit:[b]
pawn Код:
if(!fexist("Health.ini")) dini_Create("Health.ini");
[size=15pt]Salvar Colete
Em OnPlayerSpawn:
pawn Код:
if(dini_Isset("Armour.ini",PlayerName(playerid))) SetPlayerArmour(playerid,dini_Int("Armour.ini",PlayerName(playerid)));
em OnPlayerDisconnect:
pawn Код:
dini_IntSet("Armour.ini",PlayerName(playerid),GetPlayerArmour(playerid));
Em OnGameModeInit:[b]
pawn Код:
if(!fexist("Armour.ini")) dini_Create("Armour.ini");

[size=15pt]Salvar Nнvel de Procurado
Em OnPlayerSpawn:
pawn Код:
if(dini_Isset("WantedLevel .ini",PlayerName(playerid))) SetPlayerWantedLevel (playerid,dini_Int("WantedLevel.ini",PlayerName(playerid)));
em OnPlayerDisconnect:
pawn Код:
dini_IntSet("WantedLevel.ini",PlayerName(playerid),GetPlayerWantedLevel (playerid));
Em OnGameModeInit:[b]
pawn Код:
if(!fexist("WantedLevel.ini")) dini_Create("WantedLevel .ini");
[size=15pt]Salvar Cor do Player
Em OnPlayerConnect:
pawn Код:
if(dini_Isset("Color.ini",PlayerName(playerid))) SetPlayerColor(playerid,dini_Int("Color.ini",PlayerName(playerid)));
em OnPlayerDisconnect:
pawn Код:
dini_IntSet("Color.ini",PlayerName(playerid),GetPlayerColor (playerid));
Em OnGameModeInit:[b]
pawn Код:
if(!fexist("Color.ini")) dini_Create("Color .ini");
[size=15pt]Salvar IP do Player
em OnPlayerDisconnect:
pawn Код:
dini_IntSet("IPPlayers.ini",PlayerName(playerid),GetPlayerIp(playerid));
Em OnGameModeInit:[b]
pawn Код:
if(!fexist("IPPlayers.ini")) dini_Create("IPPlayers");
Resumindo:
Repararam Que Todas Funзгo Sгo as Mesmas? Funciona Assim

Funзгo:
pawn Код:
dini_IntSet("NOMEDOARQUIVO");
Ira "Salvar" o tal Arquivo

Funзгo:
pawn Код:
dini_Create("NOMEDOARQUIVO");
Ira "Criar" o tal Arquivo

Funзгo:
pawn Код:
dini_Isset("NOMEDORARQUIVO");
ou
pawn Код:
dini_Int("NOMEDOARQUIVO");
Irб "Carregar" o Arquivo"

Entгo й Assim
GET-CRIAR-SALVAR-CARREGAR-SET


Nгo Testei Tudo xD

Antes que Me Esquece Adicionar :
Final do GM ou Abaixo das New (inicio GM)
pawn Код:
stock PlayerName(playerid)
{
new Name[MAX_PLAYERS];
GetPlayerName(playerid, Name, sizeof(Name));
return Name;
}
Para Nгo Dar "Undefined PlayerName"
Reply
#2

Bom tutorial drakon. Mas tambйm podias utilizar um ъnico .ini para cada jogador e com tudo lб dentro.
Reply
#3

isso й codigo, e nгo Tuto, mas ta bom... so mudar a TAG
Reply
#4

Muito bom, parabens.
Reply
#5

Antes que Me Esquece Adicionar :
Final do GM ou Abaixo das New (inicio GM)
pawn Код:
PlayerName(playerid) {
new PlayerName[MAX_PLAYERS];
GetPlayerName(playerid, PlayerName, MAX_PLAYERS);
return PlayerName;
}
Para Nгo Dar "Undefined PlayerName"
Reply
#6

Quote:
Originally Posted by DraKoN
Antes que Me Esquece Adicionar :
Final do GM ou Abaixo das New (inicio GM)
PlayerName(playerid) {
new PlayerName[MAX_PLAYERS];
GetPlayerName(playerid, NPlayerName, MAX_PLAYERS);
return PlayerName;
}[/pawn]

Para Nгo Dar "Undefined PlayerName"
poem isso la no 1є post mesmo..
Reply
#7

ta fixe
Reply
#8

Quote:
Originally Posted by tshadow
eu fiz um Filterscripte assim
pawn Код:
// This is a comment
// uncomment the line below if you want to write a filterscript
//#define FILTERSCRIPT

#include <a_samp>
#include <Dini>

#if defined FILTERSCRIPT

#pragma unused PlayerName

public OnFilterScriptInit()
{
    if(!fexist("score.ini")) dini_Create("score.ini");
    if(!fexist("Weapon.ini")) dini_Create("Weapon.ini");
    return 1;
}

public OnFilterScriptExit()
{
    return 1;
}

#else

main()
{

}

#endif

public OnPlayerConnect(playerid)
{
  if(dini_Isset("Weapon.ini",PlayerName(playerid))) GivePlayerWeapon(playerid,dini_Int("Weapon.ini",PlayerName(playerid)));
    if(dini_Isset("score.ini",PlayerName(playerid))) SetPlayerScore(playerid,dini_Int("score.ini",PlayerName(playerid)));
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
  dini_IntSet("score.ini",PlayerName(playerid),GetPlayerScore(playerid));
    dini_IntSet("Weapon.ini",PlayerName(playerid),GetPlayerWeapon(playerid));
    return 1;
}
Код:
C:\Program Files\Rockstar Games\GTA San Andreas\server\Server\filterscripts\Set.pwn(35) : error 017: undefined symbol "PlayerName"
C:\Program Files\Rockstar Games\GTA San Andreas\server\Server\filterscripts\Set.pwn(35) : error 017: undefined symbol "PlayerName"
C:\Program Files\Rockstar Games\GTA San Andreas\server\Server\filterscripts\Set.pwn(36) : error 017: undefined symbol "PlayerName"
C:\Program Files\Rockstar Games\GTA San Andreas\server\Server\filterscripts\Set.pwn(36) : error 017: undefined symbol "PlayerName"
C:\Program Files\Rockstar Games\GTA San Andreas\server\Server\filterscripts\Set.pwn(42) : error 017: undefined symbol "PlayerName"
C:\Program Files\Rockstar Games\GTA San Andreas\server\Server\filterscripts\Set.pwn(43) : error 017: undefined symbol "PlayerName"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


6 Errors.

ACORDA PA VIDA:


Quote:
Originally Posted by DraKoN
Antes que Me Esquece Adicionar :
Final do GM ou Abaixo das New (inicio GM)
pawn Код:
PlayerName(playerid) {
new PlayerName[MAX_PLAYERS];
GetPlayerName(playerid, NPlayerName, MAX_PLAYERS);
return PlayerName;
}
Para Nгo Dar "Undefined PlayerName"
Reply
#9

Код:
C:\Program Files\Rockstar Games\GTA San Andreas\server\Server\filterscripts\Set.pwn(35) : warning 202: number of arguments does not match definition
C:\Program Files\Rockstar Games\GTA San Andreas\server\Server\filterscripts\Set.pwn(48) : warning 219: local variable "PlayerName" shadows a variable at a preceding level
C:\Program Files\Rockstar Games\GTA San Andreas\server\Server\filterscripts\Set.pwn(49) : error 017: undefined symbol "NPlayerName"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Error.
continua a dar estes erros
Reply
#10

Quote:
Originally Posted by tshadow
Code:
C:\Program Files\Rockstar Games\GTA San Andreas\server\Server\filterscripts\Set.pwn(35) : warning 202: number of arguments does not match definition
C:\Program Files\Rockstar Games\GTA San Andreas\server\Server\filterscripts\Set.pwn(48) : warning 219: local variable "PlayerName" shadows a variable at a preceding level
C:\Program Files\Rockstar Games\GTA San Andreas\server\Server\filterscripts\Set.pwn(49) : error 017: undefined symbol "NPlayerName"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Error.
continua a dar estes erros
posta as linhas, nгo??s
Reply
#11

pawn Code:
// This is a comment
// uncomment the line below if you want to write a filterscript
//#define FILTERSCRIPT

#include <a_samp>
#include <Dini>

#if defined FILTERSCRIPT

#pragma unused PlayerName

public OnFilterScriptInit()
{
if(!fexist("score.ini")) dini_Create("score.ini");
if(!fexist("Weapon.ini")) dini_Create("Weapon.ini");
return 1;
}

public OnFilterScriptExit()
{
return 1;
}

#else

main()
{

}

#endif

public OnPlayerConnect(playerid)
{
  if(dini_Isset("Weapon.ini",PlayerName(playerid))) GivePlayerWeapon(playerid,dini_Int("Weapon.ini",PlayerName(playerid)));//linha 33
if(dini_Isset("score.ini",PlayerName(playerid))) SetPlayerScore(playerid,dini_Int("score.ini",PlayerName(playerid)));
return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
  dini_IntSet("score.ini",PlayerName(playerid),GetPlayerScore(playerid));
dini_IntSet("Weapon.ini",PlayerName(playerid),GetPlayerWeapon(playerid));
return 1;
}
PlayerName(playerid) {
new PlayerName[MAX_PLAYERS];//linha 46
GetPlayerName(playerid, NPlayerName, MAX_PLAYERS);//linha 47
return PlayerName;
}
Reply
#12

Substitui NplayerName por PlayerName
Aff^^ Parece que se fazem de burro xD
Reply
#13

Nгo dб, continua a dar estes erros:
Code:
C:\Program Files\Rockstar Games\GTA San Andreas\server\Server\filterscripts\Set.pwn(33) : warning 202: number of arguments does not match definition
C:\Program Files\Rockstar Games\GTA San Andreas\server\Server\filterscripts\Set.pwn(46) : warning 219: local variable "PlayerName" shadows a variable at a preceding level
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


2 Warnings.
Reply
#14

й warning kkkkk nao erro
Reply
#15

Quote:
Originally Posted by DraKoN
Substitui NplayerName por PlayerName
Aff^^ Parece que se fazem de burro xD
100% de acordo, se antes de virem aqui postar os erros, se vissem as linhas em questгo, nгo havia metade dos post assim estupidos... Claro que se desculpam sempre aqueles que comeзaram recentemente e tals.. mas de resto
Reply
#16

Tshadown ja й meio velhinho rsrsr


Tente Mudar para

PlayerName Por PlayerName2
Ja deve ter outro PlayerName xD
Reply
#17

Quote:
Originally Posted by DraKoN
й warning kkkkk nao erro
isso sei eu mas nгo o consigo resolver
Reply
#18

Quote:
Originally Posted by tshadow
Quote:
Originally Posted by DraKoN
й warning kkkkk nao erro
isso sei eu mas nгo o consigo resolver
Posta aн o script todo.

Pastebin.
Reply
#19

ta ai http://pastebin.com/gWvbmL5v
Reply
#20

muito bom o tutorial Nice !!!!!
Reply


Forum Jump:


Users browsing this thread: 6 Guest(s)