Sauvegarde Position Civil (Temporaire)


#1

Je vais vous expliquer comment insérer la sauvegarde de position des joueurs dans votre Altis Life 4.4.
Pour commencer nous allons insérer quelques données dans votre BDD.

1. Création de 2 colonnes pour enregistrer si vous êtes en vie et votre position en temps réel.

ALTER TABLE `players` ADD `civ_alive` tinyint(1) NOT NULL DEFAULT '0';  
ALTER TABLE `players` ADD `civ_position` varchar(50) NOT NULL DEFAULT '"[]"';  

Maintenant commençons à modifier quelques fichiers côté client.

2. mpmissions/Altis_Life.Altis/Config_Master.hpp

!
Trouver:

    save_playerStats = false; //Save food & water (all sides)?  

Ajouter en dessous:

    save_civ_position = true; //Save civilian location?  
    save_civ_positionStrict = false; //Strip the player if possible combat-log?  WARNING: Server crashes and lack of reliable syncing can trigger this.  

3. mpmissions/Altis_Life.Altis/core/configuration.sqf

Trouver:

life_disable_getOut = false;  

Ajouter en dessous:

life_civ_position = [];  

Trouver:

life_is_arrested = false;   

Ajouter en dessous:

life_is_alive = false;  

4. mpmissions/Altis_Life.Altis/core/fn_initCiv.sqf

Ajouter dans l’en-tête du fichier ceci:

#include "..\script_macros.hpp" ```

**Trouver:**


if(life_is_arrested) then {  
	life_is_arrested = false;  
	[player,true] spawn life_fnc_jail;  
} else {  
	[] call life_fnc_spawnMenu;  
	waitUntil{!isNull (findDisplay 38500)}; //Wait for the spawn selection to be open.  
	waitUntil{isNull (findDisplay 38500)}; //Wait for the spawn selection to be done.  
};  

Remplacer par:

if(life_is_alive && !life_is_arrested) then {  
	/* Spawn at our last position */  
	player setPosWorld life_civ_position;  
} else {  
	if(!life_is_alive && !life_is_arrested) then {  
		if(EQUAL(LIFE_SETTINGS(getNumber,"save_civ_positionStrict"),1)) then {  
			_handle = [] spawn life_fnc_civLoadout;  
			waitUntil {scriptDone _handle}; CASH = 0;  
		};  
		[] call life_fnc_spawnMenu;  
		waitUntil{!isNull (findDisplay 38500)}; //Wait for the spawn selection to be open.  
		waitUntil{isNull (findDisplay 38500)}; //Wait for the spawn selection to be done.  
	} else {  
		if(life_is_arrested) then {  
			life_is_arrested = false;  
			[player,true] spawn life_fnc_jail;  
		};  
	};  
};  
life_is_alive = true;  

5. mpmissions/Altis_Life.Altis/core/medical/fn_onPlayerKilled.sqf

Trouver:

 CASH = 0;  

Ajouter en dessous:

life_is_alive = false;  

Trouver:

[3] call SOCK_fnc_updatePartial;  

Ajouter en dessous:

[4] call SOCK_fnc_updatePartial;  

6. mpmissions/Altis_Life.Altis/core/medical/**fn_revived.sqf **

Trouver:

deleteVehicle life_corpse;  

Ajouter en dessous:


life_is_alive = true;  

Trouver:

[] call life_fnc_hudUpdate; //Request update of hud.  

Ajouter en dessous:

[] call SOCK_fnc_updateRequest;  

7. mpmissions/Altis_Life.Altis/core/session/**fn_requestReceived.sqf **

Trouver:

		life_houses = SEL(_this,10);  

Remplacer par:

		life_houses = SEL(_this,12);  

Trouver dans case civilian:

			life_hunger = SEL(SEL(_this,9),0);  
			life_thirst = SEL(SEL(_this,9),1);  
		};  

Ajouter en dessous:


		//Position  
		if(EQUAL(LIFE_SETTINGS(getNumber,"save_civ_position"),1)) then {  
			life_is_alive = SEL(_this,10);  
			life_civ_position = SEL(_this,11);  
			if(life_is_alive) then {  
				if(count life_civ_position != 3) then {diag_log format["[requestReceived] Bad position received. Data: %1",life_civ_position];life_is_alive =false;};  
				if(life_civ_position distance (getMarkerPos "respawn_civilian") < 300) then {life_is_alive = false;};  
			};  
		};  

Trouver:

		life_gangData = SEL(_this,11);  

Remplacer par:

		life_gangData = SEL(_this,13);  

Trouver:

if(count (SEL(_this,13)) > 0) then {  
	{life_vehicles pushBack _x;} foreach (SEL(_this,13));  
};  

Remplacer par:

if(count (SEL(_this,15)) > 0) then {  
	{life_vehicles pushBack _x;} foreach (SEL(_this,15));  
};  

8. mpmissions/Altis_Life.Altis/core/session/**fn_updatePartial.sqf **

Trouver:

	case 4: {  
		//Not yet implemented  
	};  

Remplacer par:

	case 4: {  
		_packet set[2,life_is_alive];  
		_packet set[4,getPosWorld player];  
	};  

9. mpmissions/Altis_Life.Altis/core/session/fn_updateRequest.sqf

Trouver:

private["_packet","_array","_flag"];  

Remplacer par:

private["_packet","_array","_flag","_alive","_position"];  

Trouver:

_array = [];  

Ajouter en dessous:

_alive = alive player;  
_position = getPosWorld player;  

Trouver:

switch (playerSide) do {  
	case civilian: {  
		_packet pushBack life_is_arrested;  
	};  
};  

Remplacer par:

switch (playerSide) do {  
	case civilian: {  
		_packet pushBack life_is_arrested;  
		_packet pushBack _alive;  
		_packet pushBack _position;  
	};  
};  

Maintenant attaquons nous côté serveur !

10. life_server/Functions/MySQL/fn_queryRequest.sqf

Trouver:

	case civilian: {_returnCount = 10; format["SELECT playerid, name, cash, bankacc, adminlevel, donatorlvl, civ_licenses, arrested, civ_gear, civ_stats FROM players WHERE playerid='%1'",_uid];};  

Remplacer par:

	case civilian: {_returnCount = 12; format["SELECT playerid, name, cash, bankacc, adminlevel, donatorlvl, civ_licenses, arrested, civ_gear, civ_stats, civ_alive, civ_position FROM players WHERE playerid='%1'",_uid];};  

Trouver:

		//Parse Stats  
		_new = [(_queryResult select 9)] call DB_fnc_mresToArray;  
		if(typeName _new == "STRING") then {_new = call compile format["%1", _new];};  
		_queryResult set[9,_new];  

Ajouter en dessous:


		//Position  
		_queryResult set[10,([_queryResult select 10,1] call DB_fnc_bool)];  
		_new = [(_queryResult select 11)] call DB_fnc_mresToArray;  
		if(typeName _new == "STRING") then {_new = call compile format["%1",_new];};  
		_queryResult set[11,_new];  

Trouver:

_queryResult set[13,_keyArr];  

Remplacer par:

_queryResult set[15,_keyArr];  

**11. **life_server/Functions/MySQL/fn_updatePartial.sqf

Trouver:

	_query = format["UPDATE players SET alive='%1' WHERE playerid='%2'",_value,_uid]; ```

Remplacer par:

		_value2 = [_this,4,[],[[]]] call BIS_fnc_param;  
		_value2 = if(count _value2 == 3) then {_value2} else {[0,0,0]};  
		_value2 = [_value2] call DB_fnc_mresArray;  
		_query = format["UPDATE players SET civ_alive='%1', civ_position='%2' WHERE playerid='%3'",_value,_value2,_uid];  

12. life_server/Functions/MySQL/fn_updateRequest.sqf

Trouver:

private["_uid","_side","_cash","_bank","_licenses","_gear","_stats","_name","_query","_thread"];  

Remplacer par:

private["_uid","_side","_cash","_bank","_licenses","_gear","_stats","_name","_alive","_position","_query","_thread"];  

Trouver:

_stats = [_this,7,[100,100],[[]]] call BIS_fnc_param;  

Ajouter en dessous:

_alive = [_this,9,0,[0]] call BIS_fnc_param;  
_position = [_this,10,[],[[]]] call BIS_fnc_param;  

Trouver:

_bank = [_bank] call DB_fnc_numberSafe;  

Ajouter en dessous:

_position = if(_side == civilian) then {[_position] call DB_fnc_mresArray} else {[]};  

Trouver:

	case civilian: {_query = format["UPDATE players SET name='%1', cash='%2', bankacc='%3', civ_licenses='%4', civ_gear='%5', arrested='%6', civ_stats='%7' WHERE playerid='%8'",_name,_cash,_bank,_licenses,_gear,[_this select 8] call DB_fnc_bool,_stats,_uid];};  

Remplacer par:

	case civilian: {_query = format["UPDATE players SET name='%1', cash='%2', bankacc='%3', civ_licenses='%4', civ_gear='%5', arrested='%6', civ_stats='%7', civ_alive='%8', civ_position='%9' WHERE playerid='%10'",_name,_cash,_bank,_licenses,_gear,[_this select 8] call DB_fnc_bool,_stats,[_this select 9] call DB_fnc_bool,_position,_uid];};  

13. life_server/init.sqf

Trouver:

PVAR_ALL("life_server_isReady");  

Ajouter en dessous:

life_save_civ_position = if(EQUAL(LIFE_SETTINGS(getNumber,"save_civ_position"),0)) then {false} else {true};  

ENJOY!