Skip to content

Instantly share code, notes, and snippets.

@wiking-at
Created August 28, 2014 14:54
Show Gist options
  • Save wiking-at/fbd32ce0a3ce31d7cbcb to your computer and use it in GitHub Desktop.
Save wiking-at/fbd32ce0a3ce31d7cbcb to your computer and use it in GitHub Desktop.
BankMoney value migration
// @file Name: c_applyPlayerData.sqf
// @file Author: AgentRev
// This is where you load player status & inventory data which will be wiped upon death, for persistent variables use c_applyPlayerInfo.sqf instead
if (isDedicated) exitWith {};
private ["_data", "_name", "_value"];
_data = _this;
removeAllWeapons player;
removeAllAssignedItems player;
removeUniform player;
removeVest player;
removeBackpack player;
removeGoggles player;
removeHeadgear player;
{
_name = _x select 0;
_value = _x select 1;
switch (_name) do
{
case "Damage": { player setDamage _value };
case "Hunger": { hungerLevel = _value };
case "Thirst": { thirstLevel = _value };
case "Money": { player setVariable ["cmoney", _value, true] };
case "BankMoney": {
if (_value > 0) then
{
player setVariable ["bmoney", _value, true];
};
};
case "Position": { player setPosATL _value };
case "Direction": { player setDir _value };
case "Uniform":
{
// If uniform cannot be worn by player due to different team, try to convert it, else give default instead
if (_value != "") then
{
if (player isUniformAllowed _value) then
{
player addUniform _value;
}
else
{
_newUniform = [player, _value] call uniformConverter;
if (player isUniformAllowed _newUniform) then
{
player addUniform _newUniform;
}
else
{
player addUniform ([player, "uniform"] call getDefaultClothing);
}
};
};
};
case "Vest": { if (_value != "") then { player addVest _value } };
case "Backpack":
{
removeBackpack player;
if (_value != "") then
{
if (_value isKindOf "Weapon_Bag_Base") then
{
player addBackpack "B_AssaultPack_rgr"; // NO SOUP FOR YOU
}
else
{
player addBackpack _value;
};
};
};
case "Goggles": { if (_value != "") then { player addGoggles _value } };
case "Headgear":
{
// If wearing one of the default headgears, give the one belonging to actual team instead
if (_value != "") then
{
_defHeadgear = [player, "headgear"] call getDefaultClothing;
_defHeadgears =
[
[typeOf player, "headgear", BLUFOR] call getDefaultClothing,
[typeOf player, "headgear", OPFOR] call getDefaultClothing,
[typeOf player, "headgear", INDEPENDENT] call getDefaultClothing
];
if (_value != _defHeadgear && {_defHeadgear != ""} && {{_value == _x} count _defHeadgears > 0}) then
{
player addHeadgear _defHeadgear;
}
else
{
player addHeadgear _value;
};
};
};
case "LoadedMagazines":
{
player addBackpack "B_Carryall_Base"; // temporary backpack to hold mags
{ player addMagazine _x } forEach _value;
};
case "PrimaryWeapon": { player addWeapon _value; removeAllPrimaryWeaponItems player };
case "SecondaryWeapon": { player addWeapon _value };
case "HandgunWeapon": { player addWeapon _value; removeAllHandgunItems player };
case "PrimaryWeaponItems": { { if (_x != "") then { player addPrimaryWeaponItem _x } } forEach _value };
case "SecondaryWeaponItems": { { if (_x != "") then { player addSecondaryWeaponItem _x } } forEach _value };
case "HandgunItems": { { if (_x != "") then { player addHandgunItem _x } } forEach _value };
case "AssignedItems":
{
{
if ([player, _x] call isAssignableBinocular) then
{
player addWeapon _x;
}
else
{
player linkItem _x;
};
} forEach _value;
};
case "CurrentWeapon": { player selectWeapon _value };
case "Stance": { player switchMove ([player, _value] call getFullMove) };
case "UniformWeapons": { { (uniformContainer player) addWeaponCargoGlobal _x } forEach _value };
case "UniformItems": { { (uniformContainer player) addItemCargoGlobal _x } forEach _value };
case "UniformMagazines": { { (uniformContainer player) addMagazineCargoGlobal _x } forEach _value };
case "VestWeapons": { { (vestContainer player) addWeaponCargoGlobal _x } forEach _value };
case "VestItems": { { (vestContainer player) addItemCargoGlobal _x } forEach _value };
case "VestMagazines": { { (vestContainer player) addMagazineCargoGlobal _x } forEach _value };
case "BackpackWeapons": { { (backpackContainer player) addWeaponCargoGlobal _x } forEach _value };
case "BackpackItems": { { (backpackContainer player) addItemCargoGlobal _x } forEach _value };
case "BackpackMagazines": { { (backpackContainer player) addMagazineCargoGlobal _x } forEach _value };
case "PartialMagazines": { { player addMagazine _x } forEach _value };
case "WastelandItems": { { [_x select 0, _x select 1, true] call mf_inventory_add } forEach _value };
};
} forEach _data;
// @file Name: c_applyPlayerInfo.sqf
// @file Author: AgentRev
// This is where you load custom player variables that must persist between deaths, i.e. bank money amount if you have an ATM addon
if (isDedicated) exitWith {};
private ["_data", "_name", "_value"];
_data = _this;
{
_name = _x select 0;
_value = _x select 1;
switch (_name) do
{
case "Donator": { player setVariable ["isDonator", _value > 0] };
case "BankMoney": { player setVariable ["bmoney", _value max 0] }; // Not implemented in vanilla mission
};
} forEach _data;
// @file Name: c_savePlayerData.sqf
// @file Author: AgentRev
if (isDedicated) exitWith {};
if (!isNil "savePlayerHandle" && {typeName savePlayerHandle == "SCRIPT"} && {!scriptDone savePlayerHandle}) exitWith {};
savePlayerHandle = _this spawn
{
if (alive player &&
{!isNil "isConfigOn" && {["A3W_playerSaving"] call isConfigOn}} &&
{!isNil "playerSetupComplete" && {playerSetupComplete}} &&
{!isNil "respawnDialogActive" && {!respawnDialogActive}} &&
{player getVariable ["FAR_isUnconscious", 0] == 0}) then
{
_UID = getPlayerUID player;
_manualSave = [_this, 0, false, [false]] call BIS_fnc_param;
// In case script is triggered via menu action
if (!_manualSave) then
{
_manualSave = [_this, 3, false, [false]] call BIS_fnc_param;
};
_info =
[
["UID", _UID],
["Name", name player],
["LastGroupSide", str side group player],
["LastPlayerSide", str playerSide],
["BankMoney", player getVariable ["bmoney", 0]] // Not implemented in vanilla mission
];
_hitPoints = [];
{
_hitPoint = configName _x;
_hitPoints pushBack [_hitPoint, player getHitPointDamage _hitPoint];
} forEach (player call getHitPoints);
_data =
[
["Damage", damage player],
["HitPoints", _hitPoints],
["Hunger", ["hungerLevel", 0] call getPublicVar],
["Thirst", ["thirstLevel", 0] call getPublicVar],
["Money", player getVariable ["cmoney", 0]], // Money is always saved, but only restored if A3W_moneySaving = 1
["BankMoney", 0] //old
];
// Only save those when on ground or underwater (you probably wouldn't want to spawn 500m in the air if you get logged off in flight)
if (isTouchingGround vehicle player || {(getPos player) select 2 < 0.5 || (getPosASL player) select 2 < 0.5}) then
{
_data pushBack ["Position", getPosATL player];
_data pushBack ["Direction", direction player];
if (vehicle player == player) then
{
_data pushBack ["CurrentWeapon", format ["%1", currentMuzzle player]]; // currentMuzzle returns a number sometimes, hence the format
_data pushBack ["Stance", [player, ["P"]] call getMoveParams];
};
};
_gear =
[
["Uniform", uniform player],
["Vest", vest player],
["Backpack", backpack player],
["Goggles", goggles player],
["Headgear", headgear player],
["PrimaryWeapon", primaryWeapon player],
["SecondaryWeapon", secondaryWeapon player],
["HandgunWeapon", handgunWeapon player],
["PrimaryWeaponItems", primaryWeaponItems player],
["SecondaryWeaponItems", secondaryWeaponItems player],
["HandgunItems", handgunItems player],
["AssignedItems", assignedItems player]
];
_uMags = [];
_vMags = [];
_bMags = [];
_partialMags = [];
{
_magArr = _x select 0;
{
_mag = _x select 0;
_ammo = _x select 1;
if (_ammo == getNumber (configFile >> "CfgMagazines" >> _mag >> "count")) then
{
[_magArr, _mag, 1] call fn_addToPairs;
}
else
{
if (_ammo > 0) then
{
_partialMags pushBack [_mag, _ammo];
};
};
} forEach magazinesAmmoCargo (_x select 1);
}
forEach
[
[_uMags, uniformContainer player],
[_vMags, vestContainer player],
[_bMags, backpackContainer player]
];
_loadedMags = [];
{
_mag = _x select 0;
_ammo = _x select 1;
_loaded = _x select 2;
_type = _x select 3;
// if loaded in weapon, not empty, and not hand grenade
if (_loaded && _ammo > 0 && _type != 0) then
{
_loadedMags pushBack [_mag, _ammo];
};
} forEach magazinesAmmoFull player;
_data pushBack ["UniformWeapons", (getWeaponCargo uniformContainer player) call cargoToPairs];
_data pushBack ["UniformItems", (getItemCargo uniformContainer player) call cargoToPairs];
_data pushBack ["UniformMagazines", _uMags];
_data pushBack ["VestWeapons", (getWeaponCargo vestContainer player) call cargoToPairs];
_data pushBack ["VestItems", (getItemCargo vestContainer player) call cargoToPairs];
_data pushBack ["VestMagazines", _vMags];
_data pushBack ["BackpackWeapons", (getWeaponCargo backpackContainer player) call cargoToPairs];
_data pushBack ["BackpackItems", (getItemCargo backpackContainer player) call cargoToPairs];
_data pushBack ["BackpackMagazines", _bMags];
_gear pushBack ["PartialMagazines", _partialMags];
_gear pushBack ["LoadedMagazines", _loadedMags];
_wastelandItems = [];
{
if (_x select 1 > 0) then
{
_wastelandItems pushBack [_x select 0, _x select 1];
};
} forEach call mf_inventory_all;
_gear pushBack ["WastelandItems", _wastelandItems];
_gearStr = str _gear;
if (_gearStr != ["playerData_gear", ""] call getPublicVar) then
{
{ _data pushBack _x } forEach _gear;
playerData_gear = _gearStr;
};
if (alive player) then
{
savePlayerData = [_UID, _info, _data, player];
publicVariableServer "savePlayerData";
if (_manualSave) then
{
cutText ["\nPlayer saved!", "PLAIN DOWN", 0.2];
};
};
};
};
if (typeName savePlayerHandle == "SCRIPT") then
{
_savePlayerHandle = savePlayerHandle;
waitUntil {scriptDone _savePlayerHandle};
savePlayerHandle = nil;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment