ATGSS 0 Posted January 24, 2020 Hi all, first sorry for my bad english.... I want a script for do this : In a Coop Mission on the server, a option with Addaction to save a gear in a crate or object, then, if the player got DC or crash , he can join again and in the crate or objetc select "load gear" to get the same gear he had saved. I cant use a arsenal, because i have a limit number of gear (the rol of the mission), This is only for play 1 time, i dont need save permanently after server restart. I am looking for that, but no luck, i tried some tutorial but dont work withow database. ¿Can anyone help me pls? Thank you very much!! Share this post Link to post Share on other sites
7erra 629 Posted January 24, 2020 In the init line put this: TER_fnc_handleLoadout = { params ["_mode", "_this"]; params ["_target", "_caller"]; switch _mode do { case "save":{ _dbLoadouts = _target getVariable ["db_loadouts",[]]; _loadout = getUnitLoadout _caller; [_dbLoadouts, [getPlayerUID _caller, "loadout"], _loadout] call BIS_fnc_dbValueSet; _target setVariable ["db_loadouts", _dbLoadouts]; }; case "load":{ _dbLoadouts = _target getVariable ["db_loadouts", []]; _loadout = [_dbLoadouts, [getPlayerUID _caller, "loadout"]] call BIS_fnc_dbValueReturn; if (isNil "_loadout") exitWith { "No saved loadout found." remoteExec ["hint", _caller]; }; _caller setUnitLoadout _loadout; }; }; }; this addAction ["Save Gear",{ ["save", _this] remoteExec ["TER_fnc_handleLoadout", 2]; }]; this addAction ["Load Gear",{ ["load", _this] remoteExec ["TER_fnc_handleLoadout", 2]; }]; Tested on SP, Hosted-MP, Dedicated This script will save the loadouts to a scripted database (more info) and save that variable to the object the action is attached to. It is persistent as long as the server doesn't get shut down. The database is only available on the server. 2 2 Share this post Link to post Share on other sites
ATGSS 0 Posted January 24, 2020 Thank you very much!!!!!!! It work perfect!... Only a question, is possible modifing this code, for do another . : If the player got DC or Crash, spawn a crate at the last position with the actual gear before DC or crash??? Thank you very much again,!!!!!!! Share this post Link to post Share on other sites
ATGSS 0 Posted January 25, 2020 I got this script, and dont work correct if a player got DC or Crash.... but if i use a addaction "this addAction ["Save loadout", "server_onPlayerDisconnect.sqf"]" the script is working...... Any ideas what was wrong???? Thank you! init.sqf server_onPlayerDisconnect = compile preprocessFileLineNumbers "server_onPlayerDisconnect.sqf"; server_onPlayerDisconnect.sqf _caja = C; _principal = primaryWeapon player; _cargadorPrincipal = primaryWeaponMagazine player; _accesoriosPrimaria = primaryWeaponItems player; _lanzador = secondaryWeapon player; _cargadorLanzador = secondaryWeaponMagazine player; _accesoriosLanzador = secondaryWeaponItems player; _secundaria = handgunWeapon player; _cargadorSecundaria = handgunMagazine player; _accesoriosSecundaria = handgunItems player; _items = (vestitems player + uniformitems player + backpackitems player); if (_principal != "") then{ _caja addWeaponCargoGlobal [_principal, 1]; _caja addItemCargoGlobal [_cargadorPrincipal select 0, 1]; }; if (_lanzador != "") then{ _caja addWeaponCargoGlobal [_lanzador, 1]; _caja addItemCargoGlobal [_cargadorLanzador select 0, 1]; }; if (_secundaria != "") then{ _caja addWeaponCargoGlobal [_secundaria, 1]; _caja addItemCargoGlobal [_cargadorSecundaria select 0, 1]; }; _contarItems = _items call BIS_fnc_consolidateArray; for "_i" from 0 to count _contarItems -1 do { _elemento = _contarItems select _i; _objeto = _elemento select 0; _contar = _elemento select 1; _caja addItemCargoGlobal [_objeto, _contar]; }; _totalAccesorios = (_accesoriosPrimaria + _accesoriosSecundaria + _accesoriosLanzador); for "_i" from 0 to count _totalAccesorios -1 do { _objeto = _totalAccesorios select _i; if (_objeto != "") then{ _caja addItemCargoGlobal [_objeto, 1]; }; }; Share this post Link to post Share on other sites
Dedmen 2716 Posted January 29, 2020 On 1/25/2020 at 4:53 AM, ATGSS said: I got this script, and dont work correct if a player got DC or Crash.... What do you mean not correct? how are you launching it on disconnect? Btw your script is just a very complicated getUnitLoadout/setUnitLoadout. 1 Share this post Link to post Share on other sites
ATGSS 0 Posted January 29, 2020 3 hours ago, Dedmen said: What do you mean not correct? how are you launching it on disconnect? Btw your script is just a very complicated getUnitLoadout/setUnitLoadout. Hi, thanks for your response,I left this for impossible and i did another post for this question, i get another script for this, but not work, Thanks! Share this post Link to post Share on other sites
LSValmont 789 Posted January 30, 2020 On 1/24/2020 at 5:43 AM, 7erra said: In the init line put this: TER_fnc_handleLoadout = { params ["_mode", "_this"]; params ["_target", "_caller"]; switch _mode do { case "save":{ _dbLoadouts = _target getVariable ["db_loadouts",[]]; _loadout = getUnitLoadout _caller; [_dbLoadouts, [getPlayerUID _caller, "loadout"], _loadout] call BIS_fnc_dbValueSet; _target setVariable ["db_loadouts", _dbLoadouts]; }; case "load":{ _dbLoadouts = _target getVariable ["db_loadouts", []]; _loadout = [_dbLoadouts, [getPlayerUID _caller, "loadout"]] call BIS_fnc_dbValueReturn; if (isNil "_loadout") exitWith { "No saved loadout found." remoteExec ["hint", _caller]; }; _caller setUnitLoadout _loadout; }; }; }; this addAction ["Save Gear",{ ["save", _this] remoteExec ["TER_fnc_handleLoadout", 2]; }]; this addAction ["Load Gear",{ ["load", _this] remoteExec ["TER_fnc_handleLoadout", 2]; }]; Tested on SP, Hosted-MP, Dedicated This script will save the loadouts to a scripted database (more info) and save that variable to the object the action is attached to. It is persistent as long as the server doesn't get shut down. The database is only available on the server. Wow that was amazing! How can we save this to a profileNamespace? So that it is truly persistent. Share this post Link to post Share on other sites
7erra 629 Posted January 30, 2020 25 minutes ago, LSValmont said: How can we save this to a profileNamespace? Instead of using the box as the namespace (variable holder) just use profileNamespace. In this case the profileNamepsace of the server or whoever hosted it will be used. Keep in mind that using profileNamespace for persistency is not the best practice because it clutters the user's profile. If you need to save larger amounts of data use iniDBI or extDB. Also, declaring the function is neccessary only once. Create a game module and paste the function declaration in the init field of this one. Add the actions in the init line of the object. Game module init: TER_fnc_handleLoadout = { params ["_mode", "_this"]; params ["_target", "_caller"]; switch _mode do { case "save":{ _dbLoadouts = profileNamespace getVariable ["db_loadouts",[]]; _loadout = getUnitLoadout _caller; [_dbLoadouts, [getPlayerUID _caller, "loadout"], _loadout] call BIS_fnc_dbValueSet; profileNamespace setVariable ["db_loadouts", _dbLoadouts]; }; case "load":{ _dbLoadouts = profileNamespace getVariable ["db_loadouts", []]; _loadout = [_dbLoadouts, [getPlayerUID _caller, "loadout"]] call BIS_fnc_dbValueReturn; if (isNil "_loadout") exitWith { "No saved loadout found." remoteExec ["hint", _caller]; }; _caller setUnitLoadout _loadout; }; }; }; Object init: this addAction ["Save Gear",{ ["save", _this] remoteExec ["TER_fnc_handleLoadout", 2]; }]; this addAction ["Load Gear",{ ["load", _this] remoteExec ["TER_fnc_handleLoadout", 2]; }]; Script is not tested. I hate MP debugging. 1 Share this post Link to post Share on other sites
ATGSS 0 Posted January 31, 2020 On 1/30/2020 at 1:45 AM, 7erra said: Instead of using the box as the namespace (variable holder) just use profileNamespace. In this case the profileNamepsace of the server or whoever hosted it will be used. Keep in mind that using profileNamespace for persistency is not the best practice because it clutters the user's profile. If you need to save larger amounts of data use iniDBI or extDB. Also, declaring the function is neccessary only once. Create a game module and paste the function declaration in the init field of this one. Add the actions in the init line of the object. Game module init: TER_fnc_handleLoadout = { params ["_mode", "_this"]; params ["_target", "_caller"]; switch _mode do { case "save":{ _dbLoadouts = profileNamespace getVariable ["db_loadouts",[]]; _loadout = getUnitLoadout _caller; [_dbLoadouts, [getPlayerUID _caller, "loadout"], _loadout] call BIS_fnc_dbValueSet; profileNamespace setVariable ["db_loadouts", _dbLoadouts]; }; case "load":{ _dbLoadouts = profileNamespace getVariable ["db_loadouts", []]; _loadout = [_dbLoadouts, [getPlayerUID _caller, "loadout"]] call BIS_fnc_dbValueReturn; if (isNil "_loadout") exitWith { "No saved loadout found." remoteExec ["hint", _caller]; }; _caller setUnitLoadout _loadout; }; }; }; Object init: this addAction ["Save Gear",{ ["save", _this] remoteExec ["TER_fnc_handleLoadout", 2]; }]; this addAction ["Load Gear",{ ["load", _this] remoteExec ["TER_fnc_handleLoadout", 2]; }]; Script is not tested. I hate MP debugging. Is any way to use this on HandleDisconnect and Playerconected function? Share this post Link to post Share on other sites
7erra 629 Posted January 31, 2020 14 hours ago, ATGSS said: Is any way to use this on HandleDisconnect and Playerconected function? if (isServer) then { addMissionEventHandler ["HandleDisconnect", { params ["_unit", "_id", "_uid", "_name"]; ["save", [nil, _unit]] call TER_fnc_handleLoadout; }]; addMissionEventHandler ["EntityRespawned", { params ["_entity", ["_corpse", objNull]]; if (isNull _corpse) then { ["load", [nil, _entity]] call TER_fnc_handleLoadout; }; }]; }; Can be pasted into the module where TER_fnc_handleLoadout is declared. I am not sure about the EntityRespawned EH because the PlayerConnected EH fires before the player controls a unit and this is the closest EH I could find to have the unit as a param. I am also not sure if the EH fires at the beggining of the mission or when a player joins. 1 Share this post Link to post Share on other sites
ATGSS 0 Posted February 1, 2020 Thanks you very much 7erra, i put the code on the module with TER_fnc_handleLoadout , also, i did a test object if EntityRespawned dont work, with this : this addAction ["Save Gear",{ ["save", _this] remoteExec ["TER_fnc_handleLoadout", 2]; }]; this addAction ["Load Gear",{ ["load", _this] remoteExec ["TER_fnc_handleLoadout", 2]; }]; When i reconnect , dont work, and if i use the test code all work correct, maybe the HandleDisconnect is not working??? Share this post Link to post Share on other sites
7erra 629 Posted February 4, 2020 On 2/1/2020 at 9:01 AM, ATGSS said: maybe the HandleDisconnect is not working? Huh seems like it. I tried the following code but no log entry appeared for the HandleDisconnect EH while the EntityRespawned EH logged the args as expected: if (isServer) then { addMissionEventHandler ["HandleDisconnect", { diag_log "Diconnect"; diag_log _this; diag_log "Discconnect End"; params ["_unit", "_id", "_uid", "_name"]; ["save", [nil, _unit]] call TER_fnc_handleLoadout; }]; addMissionEventHandler ["EntityRespawned", { diag_log "Repawn:"; diag_log _this; diag_log "Repawn End"; params ["_entity", ["_corpse", objNull]]; ["load", [nil, _entity]] call TER_fnc_handleLoadout; }]; }; 2 Share this post Link to post Share on other sites