Ce tutoriel vous permettra d'ajouter une assurance contre les explosions à vos véhicules
1 - Installation de l'assurance dans la mission
- Dans votre fichier function.hpp, ajoutez en dessous de
file = "dialog\function";
:
class insureCar {};
- Dans votre fichier CfgRemoteExec.hpp, ajoutez en dessous de
F(TON_fnc_houseGarage,SERVER)
:F(TON_fnc_insureCar,SERVER)
- Dans le dossier dialog, puis le dossier function, créér un fichier fn_insureCar.sqf et mettez le code ci dessous dedans :
Code:
#include "..\..\script_macros.hpp"
/*
Original Author: Guit0x "Lintox"
Modified by : Maxence for The Programmer Forum
Description: Send information to insure a vehicle to server and pay
*/
disableSerialization;
if ((lbCurSel 2802) isEqualTo -1) exitWith {hint localize "STR_Global_NoSelection"};
_vehicle = lbData[2802,(lbCurSel 2802)];
_vehicle = (call compile format ["%1",_vehicle]) select 0;
_vehicleLife = _vehicle;
_vid = lbValue [2802,(lbCurSel 2802)];
_pid = getPlayerUID player;
if (isNil "_vehicle") exitWith {hint localize "STR_Garage_Selection_Error"};
if ((time - life_action_delay) < 1.5) exitWith {hint localize "STR_NOTF_ActionDelay"};
if !(isClass (missionConfigFile >> "LifeCfgVehicles" >> _vehicleLife)) then {
_vehicleLife = "Default";
diag_log format ["%1: LifeCfgVehicles class doesn't exist",_vehicle];
};
_multiplier = 1;
_purchasePrice = 0;
_price = M_CONFIG(getNumber,"LifeCfgVehicles",_vehicleLife,"price");
switch (playerSide) do {
case civilian: {
_multiplier = LIFE_SETTINGS(getNumber,"vehicle_insurance_multiplier_CIVILIAN");
_purchasePrice = _price * LIFE_SETTINGS(getNumber,"vehicle_purchase_multiplier_CIVILIAN");
};
case west: {
_multiplier = LIFE_SETTINGS(getNumber,"vehicle_insurance_multiplier_COP");
_purchasePrice = _price * LIFE_SETTINGS(getNumber,"vehicle_purchase_multiplier_COP");
};
case independent: {
_multiplier = LIFE_SETTINGS(getNumber,"vehicle_insurance_multiplier_MEDIC");
_purchasePrice = _price * LIFE_SETTINGS(getNumber,"vehicle_purchase_multiplier_MEDIC");
};
case east: {
_multiplier = LIFE_SETTINGS(getNumber,"vehicle_insurance_multiplier_OPFOR");
_purchasePrice = _price * LIFE_SETTINGS(getNumber,"vehicle_purchase_multiplier_OPFOR");
};
};
_insurancePrice = _purchasePrice * _multiplier;
if (!(_insurancePrice isEqualType 0) || _insurancePrice < 1) then {_insurancePrice = 500};
if (BANK < _insurancePrice) exitWith {hint format [(localize "STR_GNOTF_NotEnoughMoney"),[_insurancePrice] call life_fnc_numberText]};
if (life_HC_isActive) then {
[_vid,_pid] remoteExecCall ["HC_fnc_insureCar",HC_Life];
} else {
[_vid,_pid] remoteExecCall ["TON_fnc_insureCar",RSERV];
};
hint "Vous avez assuré votre véhicule !";
BANK = BANK - _insurancePrice;
life_action_delay = time;
closeDialog 0;
- Dans le dossier dialog, ouvrez le fichier impound.hpp et ajoutez en dessous après la class SellCar ceci :
Code:
class Insure : life_RscButtonMenu {
idc = 2804;
text = "Assurer";
onButtonClick = "[] call life_fnc_insureCar;";
x = 0.43 + (6.25 / 40) + (1 / 250 / (safezoneW / safezoneH));
y = 0.9 - (1 / 25);
w = (6.25 / 40);
h = (1 / 25);
};
- Dans le dossier config, dans le fichier config_master.hpp, ajoutez ces lignes et modifier les valeurs comme vous le souhaitez :
Code:
vehicle_insurance_multiplier_CIVILIAN = .25; // Le prix de l'assurance est le prix d'achat * cette valeur pour les civils
vehicle_insurance_multiplier_COP = .1; // Le prix de l'assurance est le prix d'achat * cette valeur pour les policiers
vehicle_insurance_multiplier_MEDIC = .1; // Le prix de l'assurance est le prix d'achat * cette valeur pour les médecins
vehicle_insurance_multiplier_OPFOR = -1; // Le prix de l'assurance est le prix d'achat * cette valeur pour les adacs
- Dans le dossier dialog, puis le dossier function, ouvrez le fichier fn_impoundMenu.sqf, trouvez cette ligne :
_tmp = [(_x select 2),(_x select 8)];
et ajoutez : (_x select 9) de cette manière :_tmp = [(_x select 2),(_x select 8),(_x select 9)];
Si vous avez déjà (_x select 9), ajoutez après le (_x select 9) : (_x select 10) etc..
- Dans le dossier dialog, puis le dossier function, ouvrez le fichier fn_garageLbChange.sqf, remplacez ces lignes :
Code:
switch (playerSide) do {
case civilian: {
_purchasePrice = _price * LIFE_SETTINGS(getNumber,"vehicle_purchase_multiplier_CIVILIAN");
_sellMultiplier = LIFE_SETTINGS(getNumber,"vehicle_sell_multiplier_CIVILIAN");
};
case west: {
_purchasePrice = _price * LIFE_SETTINGS(getNumber,"vehicle_purchase_multiplier_COP");
_sellMultiplier = LIFE_SETTINGS(getNumber,"vehicle_sell_multiplier_COP");
};
case independent: {
_purchasePrice = _price * LIFE_SETTINGS(getNumber,"vehicle_purchase_multiplier_MEDIC");
_sellMultiplier = LIFE_SETTINGS(getNumber,"vehicle_sell_multiplier_MEDIC");
};
case east: {
_purchasePrice = _price * LIFE_SETTINGS(getNumber,"vehicle_purchase_multiplier_OPFOR");
_sellMultiplier = LIFE_SETTINGS(getNumber,"vehicle_sell_multiplier_OPFOR");
};
};
_retrievePrice = _purchasePrice * _storageFee;
_sellPrice = _purchasePrice * _sellMultiplier;
if (!(_sellPrice isEqualType 0) || _sellPrice < 1) then {_sellPrice = 500;};
if (!(_retrievePrice isEqualType 0) || _retrievePrice < 1) then {_retrievePrice = 500;};
Code:
_insuranceMultiplier = 0.2;
_insurance = (_dataArr select 2);
switch (playerSide) do {
case civilian: {
_purchasePrice = _price * LIFE_SETTINGS(getNumber,"vehicle_purchase_multiplier_CIVILIAN");
_sellMultiplier = LIFE_SETTINGS(getNumber,"vehicle_sell_multiplier_CIVILIAN");
_insuranceMultiplier = LIFE_SETTINGS(getNumber,"vehicle_insurance_multiplier_CIVILIAN");
};
case west: {
_purchasePrice = _price * LIFE_SETTINGS(getNumber,"vehicle_purchase_multiplier_COP");
_sellMultiplier = LIFE_SETTINGS(getNumber,"vehicle_sell_multiplier_COP");
_insuranceMultiplier = LIFE_SETTINGS(getNumber,"vehicle_insurance_multiplier_COP");
};
case independent: {
_purchasePrice = _price * LIFE_SETTINGS(getNumber,"vehicle_purchase_multiplier_MEDIC");
_sellMultiplier = LIFE_SETTINGS(getNumber,"vehicle_sell_multiplier_MEDIC");
_insuranceMultiplier = LIFE_SETTINGS(getNumber,"vehicle_insurance_multiplier_MEDIC");
};
case east: {
_purchasePrice = _price * LIFE_SETTINGS(getNumber,"vehicle_purchase_multiplier_OPFOR");
_sellMultiplier = LIFE_SETTINGS(getNumber,"vehicle_sell_multiplier_OPFOR");
_insuranceMultiplier = LIFE_SETTINGS(getNumber,"vehicle_insurance_multiplier_OPFOR");
};
};
_retrievePrice = _purchasePrice * _storageFee;
_sellPrice = _purchasePrice * _sellMultiplier;
_insurancePrice = _purchasePrice * _insuranceMultiplier;
if (!(_sellPrice isEqualType 0) || _sellPrice < 1) then {_sellPrice = 500;};
if (!(_retrievePrice isEqualType 0) || _retrievePrice < 1) then {_retrievePrice = 500;};
if (!(_insurancePrice isEqualType 0) || _insurancePrice < 1) then {_insurancePrice = 500;};
- Encore dans le même fichier, trouvez cette ligne :
" +(localize "STR_Shop_Veh_UI_SellP")+ " <t color='#8cff9b'>€%2</t><br/>
et ajoutez en dessous :
Code:
Prix de l'assurance: <t color='#8cff9b'>%9€</t><br/>
Etat de l'assurance: %10 <br/>
- Toujours dans le même fichier, trouvez cette ligne :
_vehicleColor
, ajoutez une virgule à la fin de la ligne et ajoutez en dessous :
Code:
[_insurancePrice] call life_fnc_numberText,
if (_insurance isEqualTo 1) then {"<t color='#8cff9b'>Assuré</t>"} else {"<t color='#FF0000'>Pas d'assurance</t>"}
- Une dernière fois dans le même fichier, ajoutez tout à la fin :
Code:
if (_insurance isEqualTo 1) then {
ctrlShow [2804,false];
} else {
ctrlShow [2804,true];
};
2 - Installation de l'assurance dans le life_server
- Dans votre fichier config.cpp, ajoutez en dessous de
file = "\life_server\Functions\Systems";
:
Code:
class insureCar {};
class getInsureCar {};
- Dans le dossier functions, puis le dossier systems, créér un fichier fn_insureCar.sqf et mettez le code ci dessous dedans :
Code:
/*
Author: Maxence for The Programmer Forum
Description: Save insure status to the database
*/
params [
["_vid",-1,[0]],
["_pid","",[""]]
];
if ((_vid isEqualTo -1) OR (_pid isEqualTo "")) exitWith {};
_query = format ["UPDATE vehicles SET insure='1' WHERE pid='%1' AND id='%2'",_pid,_vid];
[_query,1] call DB_fnc_asyncCall;
- Dans le même dossier, créez un fichier un fichier fn_getinsureCar.sqf et mettez le code ci dessous dedans :
Code:
/*
Author: Jean-Baptiste for The Programmer Forum
Description: Save insure status to the database
*/
params [
["_vid",-1,[0]],
["_pid","",[""]],
["_vehicle",objNull,[objNull]],
["_unit",-1,[0]]
];
if (_vid isEqualTo -1 || {_pid isEqualTo ""} || {isNull _vehicle}) exitWith {};
_query = format ["SELECT id, insure FROM vehicles WHERE id='%1' AND pid='%2'",_vid,_pid];
_queryResult = [_query,2] call DB_fnc_asyncCall;
if (_queryResult isEqualType "") exitWith {};
_insureStatus = (_queryResult select 1);
_vehicle setVariable ["vehicle_insure_status",_insureStatus,true];
if (_insureStatus isEqualTo 1) then {
[1,"Votre véhicule est disponible et est assuré !"] remoteExecCall ["life_fnc_broadcast",_unit];
} else {
[1,"Votre véhicule est disponible mais n'est pas assuré !"] remoteExecCall ["life_fnc_broadcast",_unit];
};
- Dans le dossier Functions, puis le dossier System, ouvrez le fichier fn_getVehicles.sqf, trouvez cette ligne :
_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];
et ajoutez : insure de cette manière :_query = format ["SELECT id, side, classname, type, pid, alive, active, plate, color, insure FROM vehicles WHERE pid='%1' AND alive='1' AND active='0' AND side='%2' AND type='%3'",_pid,_side,_type];
- Dans le dossier Functions, puis le dossier System, ouvrez le fichier fn_spawnVehicle.sqf, remplacez
[1,_spawntext] remoteExecCall ["life_fnc_broadcast",_unit];
par cette ligne :
Code:
[_vid,_pid,_vehicle,_unit] spawn TON_fnc_getInsureCar;
- Dans le dossier FSM, ouvrez le fichier cleanup.fsm, remplacez l'intégralité du fichier par :
Code:
/*%FSM<COMPILE "scriptedFSM.cfg, Server-Side Cleanup">*/
/*%FSM<HEAD>*/
/*
item0[] = {"init",0,250,-62.908096,-391.651611,27.091887,-341.651672,0.000000,"init"};
item1[] = {"true",8,218,-62.976639,-315.185364,27.023363,-265.185364,0.000000,"true"};
item2[] = {"Share__Work_load",2,250,-64.183350,-224.681931,25.816656,-174.681931,0.000000,"Share " \n "Work-load"};
item3[] = {"Continue__",4,4314,-220.591476,74.216980,-130.591476,124.216980,0.000000,"" \n "" \n "Continue" \n "" \n ""};
item4[] = {"Time_Check",4,218,-219.425827,-133.310532,-129.425964,-83.310455,0.000000,"Time Check"};
item5[] = {"Delete_Dead_Cars",2,250,-220.186951,-29.248400,-130.187195,20.751413,0.000000,"Delete" \n "Dead" \n "Cars"};
item6[] = {"",7,210,-312.538239,95.295059,-304.538239,103.295059,0.000000,""};
item7[] = {"",7,210,-312.798218,-204.081940,-304.798218,-196.081940,0.000000,""};
item8[] = {"End_Cleanup_",1,250,-64.828239,87.581070,25.171984,137.581238,0.000000,"" \n "End Cleanup" \n ""};
item9[] = {"Check_for_HC_",4,218,-65.059021,-30.047342,24.941008,19.952658,0.000000,"" \n "Check for HC" \n ""};
link0[] = {0,1};
link1[] = {1,2};
link2[] = {2,4};
link3[] = {3,6};
link4[] = {4,5};
link5[] = {5,3};
link6[] = {5,9};
link7[] = {6,7};
link8[] = {7,2};
link9[] = {9,8};
globals[] = {0.000000,0,0,0,0,640,480,1,53,6316128,1,-481.887177,425.726196,554.522583,-436.926575,857,816,1};
window[] = {0,-1,-1,-32000,-32000,1120,545,1909,159,1,875};
*//*%FSM</HEAD>*/
class FSM
{
fsmName = "Server-Side Cleanup";
class States
{
/*%FSM<STATE "init">*/
class init
{
name = "init";
itemno = 0;
init = /*%FSM<STATEINIT""">*/"private [""_impound"",""_cars"",""_objs"",""_totCars"",""_thread""];" \n
"_impound = time;" \n
"_cars = time;" \n
"_objs = time;" \n
"cleanupFSM setFSMVariable [""stopfsm"",false];"/*%FSM</STATEINIT""">*/;
precondition = /*%FSM<STATEPRECONDITION""">*/""/*%FSM</STATEPRECONDITION""">*/;
class Links
{
/*%FSM<LINK "true">*/
class true
{
itemno = 1;
priority = 0.000000;
to="Share__Work_load";
precondition = /*%FSM<CONDPRECONDITION""">*/""/*%FSM</CONDPRECONDITION""">*/;
condition=/*%FSM<CONDITION""">*/"true"/*%FSM</CONDITION""">*/;
action=/*%FSM<ACTION""">*/""/*%FSM</ACTION""">*/;
};
/*%FSM</LINK>*/
};
};
/*%FSM</STATE>*/
/*%FSM<STATE "Share__Work_load">*/
class Share__Work_load
{
name = "Share__Work_load";
itemno = 2;
init = /*%FSM<STATEINIT""">*/""/*%FSM</STATEINIT""">*/;
precondition = /*%FSM<STATEPRECONDITION""">*/""/*%FSM</STATEPRECONDITION""">*/;
class Links
{
/*%FSM<LINK "Time_Check">*/
class Time_Check
{
itemno = 4;
priority = 0.000000;
to="Delete_Dead_Cars";
precondition = /*%FSM<CONDPRECONDITION""">*/""/*%FSM</CONDPRECONDITION""">*/;
condition=/*%FSM<CONDITION""">*/"((time - _cars) > (3 * 60))"/*%FSM</CONDITION""">*/;
action=/*%FSM<ACTION""">*/""/*%FSM</ACTION""">*/;
};
/*%FSM</LINK>*/
};
};
/*%FSM</STATE>*/
/*%FSM<STATE "Delete_Dead_Cars">*/
class Delete_Dead_Cars
{
name = "Delete_Dead_Cars";
itemno = 5;
init = /*%FSM<STATEINIT""">*/"{" \n
" if (!alive _x) then {" \n
" _dbInfo = _x getVariable [""dbInfo"",[]];" \n
" if (count _dbInfo > 0) then {" \n
" _uid = _dbInfo select 0;" \n
" _plate = _dbInfo select 1;" \n
" _insureStatus = _x getVariable [""vehicle_insure_status"",0];" \n
" if (_insureStatus == 1) then {" \n
" _query_0 = format [""UPDATE vehicles SET alive='1', insure='0', active='0' WHERE pid='%1' AND plate='%2'"",_uid,_plate];" \n
" _query_0 spawn {" \n
" _thread = [_this,1] call DB_fnc_asyncCall;" \n
" };" \n
" } else {" \n
" _query_1 = format[""UPDATE vehicles SET alive='0' WHERE pid='%1' AND plate='%2'"",_uid,_plate]; " \n
" _query_1 spawn {" \n
" _thread = [_this,1] call DB_fnc_asyncCall;" \n
" };" \n
" };" \n
" };" \n
" if (!isNil ""_x"" && {!isNull _x}) then {" \n
" deleteVehicle _x;" \n
" };" \n
" };" \n
"} forEach allMissionObjects ""LandVehicle"";" \n
"" \n
"{" \n
" if (!alive _x) then {" \n
" _dbInfo = _x getVariable [""dbInfo"",[]];" \n
" if (count _dbInfo > 0) then {" \n
" _uid = _dbInfo select 0;" \n
" _plate = _dbInfo select 1;" \n
" _insureStatus = _x getVariable [""vehicle_insure_status"",0];" \n
" if (_insureStatus == 1) then {" \n
" _query_0 = format [""UPDATE vehicles SET alive='1', insure='0', active='0' WHERE pid='%1' AND plate='%2'"",_uid,_plate];" \n
" _query_0 spawn {" \n
" _thread = [_this,1] call DB_fnc_asyncCall;" \n
" };" \n
" } else {" \n
" _query_1 = format[""UPDATE vehicles SET alive='0' WHERE pid='%1' AND plate='%2'"",_uid,_plate]; " \n
" _query_1 spawn {" \n
" _thread = [_this,1] call DB_fnc_asyncCall;" \n
" };" \n
" };" \n
" };" \n
" if (!isNil ""_x"" && {!isNull _x}) then {" \n
" deleteVehicle _x;" \n
" };" \n
" };" \n
"} forEach allMissionObjects ""Air"";" \n
"_cars = time;" \n
"" \n
"//Group cleanup." \n
"{" \n
" if (units _x isEqualTo [] && local _x) then {" \n
" deleteGroup _x;" \n
" };" \n
"} forEach allGroups;"/*%FSM</STATEINIT""">*/;
precondition = /*%FSM<STATEPRECONDITION""">*/""/*%FSM</STATEPRECONDITION""">*/;
class Links
{
/*%FSM<LINK "Check_for_HC_">*/
class Check_for_HC_
{
itemno = 9;
priority = 0.000000;
to="End_Cleanup_";
precondition = /*%FSM<CONDPRECONDITION""">*/""/*%FSM</CONDPRECONDITION""">*/;
condition=/*%FSM<CONDITION""">*/"cleanupFSM getFSMVariable ""stopfsm"""/*%FSM</CONDITION""">*/;
action=/*%FSM<ACTION""">*/""/*%FSM</ACTION""">*/;
};
/*%FSM</LINK>*/
/*%FSM<LINK "Continue__">*/
class Continue__
{
itemno = 3;
priority = 0.000000;
to="Share__Work_load";
precondition = /*%FSM<CONDPRECONDITION""">*/""/*%FSM</CONDPRECONDITION""">*/;
condition=/*%FSM<CONDITION""">*/"!(cleanupFSM getFSMVariable ""stopfsm"")"/*%FSM</CONDITION""">*/;
action=/*%FSM<ACTION""">*/""/*%FSM</ACTION""">*/;
};
/*%FSM</LINK>*/
};
};
/*%FSM</STATE>*/
/*%FSM<STATE "End_Cleanup_">*/
class End_Cleanup_
{
name = "End_Cleanup_";
itemno = 8;
init = /*%FSM<STATEINIT""">*/""/*%FSM</STATEINIT""">*/;
precondition = /*%FSM<STATEPRECONDITION""">*/""/*%FSM</STATEPRECONDITION""">*/;
class Links
{
};
};
/*%FSM</STATE>*/
};
initState="init";
finalStates[] =
{
"End_Cleanup_",
};
};
/*%FSM</COMPILE>*/
___
3 - Installation de l'assurance dans la base de données
- Exécutez le code suivant dans votre base de données :
Code:
ALTER TABLE vehicles ADD insure INT(1) NOT NULL DEFAULT '0';
Dernière édition par un modérateur: