SA-MP Forums Archive
[Pedido] Sistema de salvamento de armas. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: Non-English (https://sampforum.blast.hk/forumdisplay.php?fid=9)
+--- Forum: Languages (https://sampforum.blast.hk/forumdisplay.php?fid=33)
+---- Forum: Português/Portuguese (https://sampforum.blast.hk/forumdisplay.php?fid=34)
+---- Thread: [Pedido] Sistema de salvamento de armas. (/showthread.php?tid=372665)



Sistema de salvamento de armas. - Ley - 27.08.2012

Alф pessoas
Alguйm poderia compartilhar algum FS que faзa com que salve as armas dos players?
Grato
Espero respostas.


Re: Sistema de salvamento de armas. - Adonay - 27.08.2012

Ja estou criando, quando terminar eu edito aqui.


Re: Sistema de salvamento de armas. - Sergiosousa - 27.08.2012

Este й bom, salva todas as armas em um arquivo e ao entrar no servidor serб dado as armas quando ele deslogou do server.

https://sampforum.blast.hk/showthread.php?tid=167857


Re: Sistema de salvamento de armas. - Jason` - 27.08.2012

pawn Код:
#include <a_samp>
#include <dof2>

new string[50];

public OnFilterScriptExit() {
    DOF2_Exit();
    return 1;
}

public OnPlayerDisconnect(playerid, reason) {
    static name[24], str[50], weapon, ammo;
    GetPlayerName(playerid, name, sizeof(name));
    format(string, 50, "Armas/%s.ini", name);
    DOF2_CreateFile(string);
    for(new i = 1; i < 13; ++i) {
        GetPlayerWeaponData(playerid, i, weapon, ammo);
        format(str, sizeof(str), "Arma%d", i);
        DOF2_SetInt(string, str, weapon);
        format(str, sizeof(str), "Municao%d", i);
        DOF2_SetInt(string, str, ammo);
    }
    DOF2_SaveFile();
    return 1;
}

public OnPlayerSpawn(playerid) {
    static name[24], str[50];
    GetPlayerName(playerid, name, sizeof(name));
    format(string, 50, "Armas/%s.ini", name);
    if(DOF2_FileExists(string)) {
        static weapon, ammo;
        for(new i = 1; i < 13; ++i) {
            format(str, sizeof(str), "Arma%d", i);
            weapon = DOF2_GetInt(string, str);
            format(str, sizeof(str), "Municao%d", i);
            ammo = DOF2_GetInt(string, str);
           
            GivePlayerWeapon(playerid, weapon, ammo);
        }
    }
    return 1;
}
Precisa criar a pasta Armas nas scriptfiles. Caso nгo funcionar diga-me, nгo cheguei a testar, nem sequer compilei.


Re: Sistema de salvamento de armas. - Adonay - 27.08.2012

Pedro foi mais rбpido... que pena...

Obs: Crie a pasta Armas.

Код:
#include <a_samp>
#include <DOF2>

public OnPlayerSpawn(playerid)
{
	LoadWeapons(playerid);
	return 1;
}

public OnGameModeExit()
{
    DOF2_Exit();
    return 1;
}

public OnPlayerDisconnect(playerid)
{
	SaveWeapons(playerid);
	return 1;
}

SaveWeapons(playerid)
{
    new weapons[13][2], wstring[56], armap[24];
	format(wstring, sizeof(wstring), "Armas/%s.ini", GetNick(playerid));
	if(!DOF2_FileExists(wstring))
	    DOF2_CreateFile(wstring);
	if(DOF2_FileExists(wstring))
	{
		for (new i = 0; i < 13; i++)
		{
		    GetPlayerWeaponData(playerid, i, weapons[i][0], weapons[i][1]);
		    format(armap, sizeof(armap), "Weapon%d", i);
		    DOF2_SetInt(wstring, armap, weapons[i][0]);
		    format(armap, sizeof(armap), "Ammo%d", i);
    		DOF2_SetInt(wstring, armap, weapons[i][1]);
		}
		DOF2_SaveFile();
		print("Armas Salvas");
	}
	return 1;
}

LoadWeapons(playerid)
{
    new wstring[56], armap[24], weapons[13][2];
	format(wstring, sizeof(wstring), "Armas/%s.ini", GetNick(playerid));
	if(!DOF2_FileExists(wstring))
	    return 1;
	if(DOF2_FileExists(wstring))
	{
		for (new i = 0; i < 13; i++)
		{
		    format(armap, sizeof(armap), "Weapon%d", i);
		    weapons[i][0] = DOF2_GetInt(wstring, armap);
		    format(armap, sizeof(armap), "Ammo%d", i);
    		weapons[i][1] = DOF2_GetInt(wstring, armap);
    		if(weapons[i][0] != 0)
    			GivePlayerWeapon(playerid, weapons[i][0], weapons[i][1]);
		}
		print("Armas Carregadas");
	}
	return 1;
}

GetNick(playerid)
{
	new name[MAX_PLAYER_NAME];
	GetPlayerName(playerid, name, MAX_PLAYER_NAME);
	return name;
}
http://pastebin.com/ZrjLSgZs

Bom uso...


Re: Sistema de salvamento de armas. - Ley - 27.08.2012

Os dois nгo testaram? '-'


Re: Sistema de salvamento de armas. - Tony_Rodrigues - 27.08.2012

Quote:
Originally Posted by Adonay
Посмотреть сообщение
Pedro foi mais rбpido... que pena...

Obs: Crie a pasta Armas.

Код:
#include <a_samp>
#include <DOF2>

public OnPlayerSpawn(playerid)
{
	LoadWeapons(playerid);
	return 1;
}

public OnGameModeExit()
{
    DOF2_Exit();
    return 1;
}

public OnPlayerDisconnect(playerid)
{
	SaveWeapons(playerid);
	return 1;
}

SaveWeapons(playerid)
{
    new weapons[13][2], wstring[56], armap[24];
	format(wstring, sizeof(wstring), "Armas/%s.ini", GetNick(playerid));
	if(!DOF2_FileExists(wstring))
	    DOF2_CreateFile(wstring);
	if(DOF2_FileExists(wstring))
	{
		for (new i = 0; i < 13; i++)
		{
		    GetPlayerWeaponData(playerid, i, weapons[i][0], weapons[i][1]);
		    format(armap, sizeof(armap), "Weapon%d", i);
		    DOF2_SetInt(wstring, armap, weapons[i][0]);
		    format(armap, sizeof(armap), "Ammo%d", i);
    		DOF2_SetInt(wstring, armap, weapons[i][1]);
		}
		DOF2_SaveFile();
		print("Armas Salvas");
	}
	return 1;
}

LoadWeapons(playerid)
{
    new wstring[56], armap[24], weapons[13][2];
	format(wstring, sizeof(wstring), "Armas/%s.ini", GetNick(playerid));
	if(!DOF2_FileExists(wstring))
	    return 1;
	if(DOF2_FileExists(wstring))
	{
		for (new i = 0; i < 13; i++)
		{
		    format(armap, sizeof(armap), "Weapon%d", i);
		    weapons[i][0] = DOF2_GetInt(wstring, armap);
		    format(armap, sizeof(armap), "Ammo%d", i);
    		weapons[i][1] = DOF2_GetInt(wstring, armap);
    		if(weapons[i][0] != 0)
    			GivePlayerWeapon(playerid, weapons[i][0], weapons[i][1]);
		}
		print("Armas Carregadas");
	}
	return 1;
}

GetNick(playerid)
{
	new name[MAX_PLAYER_NAME];
	GetPlayerName(playerid, name, MAX_PLAYER_NAME);
	return name;
}
http://pastebin.com/ZrjLSgZs

Bom uso...
Tem certeza que foi vc que fez?


Re: Sistema de salvamento de armas. - Adonay - 27.08.2012

Quote:
Originally Posted by Tony_Rodrigues
Tem certeza que foi vc que fez?
Sim tenho certeza... nao preciso copiar, nada, e de ninguйm.

@TOPIC

SaveWeapons(playerid);

Coloque aonde achar que viavel colocar... onde sabe que nao hб muita frequencia de pessoas ativando a funзгo de salvamento.


Re: Sistema de salvamento de armas. - Ley - 27.08.2012

Quote:
Originally Posted by Adonay
Посмотреть сообщение
Sim tenho certeza... nao preciso copiar, nada, e de ninguйm.

@TOPIC

SaveWeapons(playerid);

Coloque aonde achar que viavel colocar... onde sabe que nao hб muita frequencia de pessoas ativando a funзгo de salvamento.
Ok


Re: Sistema de salvamento de armas. - Ley - 28.08.2012

Quote:
Originally Posted by Pedro_Miranda
Посмотреть сообщение
pawn Код:
#include <a_samp>
#include <dof2>

new string[50];

public OnFilterScriptExit() {
    DOF2_Exit();
    return 1;
}

public OnPlayerDisconnect(playerid, reason) {
    static name[24], str[50], weapon, ammo;
    GetPlayerName(playerid, name, sizeof(name));
    format(string, 50, "Armas/%s.ini", name);
    DOF2_CreateFile(string);
    for(new i = 1; i < 13; ++i) {
        GetPlayerWeaponData(playerid, i, weapon, ammo);
        format(str, sizeof(str), "Arma%d", i);
        DOF2_SetInt(string, str, weapon);
        format(str, sizeof(str), "Municao%d", i);
        DOF2_SetInt(string, str, ammo);
    }
    DOF2_SaveFile();
    return 1;
}

public OnPlayerSpawn(playerid) {
    static name[24], str[50];
    GetPlayerName(playerid, name, sizeof(name));
    format(string, 50, "Armas/%s.ini", name);
    if(DOF2_FileExists(string)) {
        static weapon, ammo;
        for(new i = 1; i < 13; ++i) {
            format(str, sizeof(str), "Arma%d", i);
            weapon = DOF2_GetInt(string, str);
            format(str, sizeof(str), "Municao%d", i);
            ammo = DOF2_GetInt(string, str);
           
            GivePlayerWeapon(playerid, weapon, ammo);
        }
    }
    return 1;
}
Precisa criar a pasta Armas nas scriptfiles. Caso nгo funcionar diga-me, nгo cheguei a testar, nem sequer compilei.
Deu alguns warnings em seu cуdigo;
pawn Код:
local variable "string" shadows a variable at a preceding level
local variable "string" shadows a variable at a preceding level
local variable "string" shadows a variable at a preceding level
Pode me ajudar?