English Separate garages according to their position to store and remove vehicles in the same place.

  • Auteur de la discussion Auteur de la discussion Mathis
  • Date de début Date de début

Mathis

The-Programmer
Membre du personnel
29/12/19
504
16
48
1 100
Welcome to this tutorial that will allow you separate garages according to their position. For example, vehicles stored in a specific garage can only be retrieved from this garage.
This tutorial is a follow to the request for help from L Lilbape.

Let's go !

On your mapping, you should have a line like this in the init of the object to store your vehicle in the garage:
Code:
this addAction[localize "STR_MAR_Store_vehicle_in_Garage",life_fnc_storeVehicle,"",0,false,false,"",'!life_garage_store'];

Replace :
Code:
life_fnc_storeVehicle
By :
Code:
{[cursorObject,player,"kavala"] call life_fnc_storeVehicle;}

This will result in :
Code:
this addAction[localize "STR_MAR_Store_vehicle_in_Garage",{[player,false,"kavala"] call life_fnc_storeVehicle;},"",0,false,false,"",'!life_garage_store'];

In the init of the garage for take out the vehicles, replace this line :
Code:
[getPlayerUID player,playerSide,"Car",player] remoteExecCall ["TON_fnc_getVehicles",2];
By :
Code:
[getPlayerUID player,playerSide,"Car",player,"kavala"] remoteExecCall ["TON_fnc_getVehicles",2];
You can replace "kavala" by the name of your garage, it must correspond to the name of the storeVehicle where you are (the name does not matter as long as it is the same).

In your core/actions/fn_storeVehicle.sqf, search this line :
Code:
[_vehicle,false,(_this select 1),_storetext] remoteExec ["TON_fnc_vehicleStore",RSERV];
And replace by :
Code:
[_vehicle,false,(_this select 1),_storetext,(param [2,"",["",0]])] remoteExec ["TON_fnc_vehicleStore",RSERV];

Add at the end of your life_server/Functions/Systems/fn_vehicleStore.sqf :
Code:
_garageName = param [4,"",["",0]];
if (_garageName isEqualType "") then {
    if !(_garageName isEqualTo "") then {
        _query = format ["UPDATE vehicles SET garage_name='""%1""' WHERE pid='%2' AND plate='%3'",_garageName,_uid,_plate];
        [_query,1] call DB_fnc_asyncCall;
    };
};

In your life_server/Functions/Systems/fn_getVehicles.sqf, replace :
Code:
_query = format ["SELECT id, side, classname, type, pid, alive, active, plate, color FROM vehicles WHERE pid='%1' AND alive='1' AND active='0' AND side='%2' AND type='%3'",_pid,_side,_type];
By these lines :
Code:
_garageName = param [4,"",[""]];
_query = format ["SELECT id, side, classname, type, pid, alive, active, plate, color FROM vehicles WHERE pid='%1' AND alive='1' AND active='0' AND side='%2' AND type='%3'",_pid,_side,_type];
if !(_garageName isEqualTo "") then {
    _query = format ["SELECT id, side, classname, type, pid, alive, active, plate, color FROM vehicles WHERE pid='%1' AND alive='1' AND active='0' AND side='%2' AND type='%3' AND garage_name='""%4""'",_pid,_side,_type,_garageName];
};
WARNING, if the line you have in your file is not exactly the same, which is very likely, do not copy the line directly but add the changes to the one you have in your file.

In your database, run the following code :
Code:
ALTER TABLE `vehicles` ADD COLUMN  `garage_name` TEXT NOT NULL;

-----

If all your garages depend on a position, you will need to set a default garage for new purchased vehicles that are not stored in the garage before the server reboot, otherwise they will not be visible anywhere in the garages.

To do this, in your life_server/Functions/MySQL/fn_insertVehicle.sqf, replace this line :
Code:
_query = format ["INSERT INTO vehicles (side, classname, type, pid, alive, active, inventory, color, plate, gear, damage) VALUES ('%1', '%2', '%3', '%4', '1','1','""[[],0]""', '%5', '%6','""[]""','""[]""')",_side,_className,_type,_uid,_color,_plate];
by this one :
Code:
_query = format ["INSERT INTO vehicles (side, classname, type, pid, alive, active, inventory, color, plate, gear, damage, garage_name) VALUES ('%1', '%2', '%3', '%4', '1','1','""[[],0]""', '%5', '%6','""[]""','""[]""','""kavala""')",_side,_className,_type,_uid,_color,_plate];
WARNING, if the line you have in your file is not exactly the same, which is very likely, do not copy the line directly but add the changes to the one you have in your file.

-----

Here we go !

Sincerely,
Forum Manager - Mathis
 
Dernière édition par un modérateur:
  • Like
Les réactions: IceEagle132