[Pedido] Sistema de salvamento de armas.
#1

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

Ja estou criando, quando terminar eu edito aqui.
Reply
#3

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
Reply
#4

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.
Reply
#5

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...
Reply
#6

Os dois nгo testaram? '-'
Reply
#7

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?
Reply
#8

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.
Reply
#9

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
Reply
#10

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?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)