Jump to content
Sign in to follow this  
boydee

Save Ammobox Contents After Restart

Recommended Posts

Hey guys, First of all thank you to all of you who have helped me out with questions I've had recently.

I was wondering if its even possible and how to save the contents of an ammobox even after a restart of the server ?

I have a locker system in the mission I'm working on and I'm wondering if I can save the contents.

Share this post


Link to post
Share on other sites

As far as I know when the server is restarted, everything is dropped from it, unless within your script you have the arrays all defined as you want them and the sort, there is no "saving" after restart. It would be different however if it was persistent, but your talking restart, at which point it still wouldn't matter.

There might be something that you could do with databases, but I've never touched that side of things :p.

Edited by JShock

Share this post


Link to post
Share on other sites

There are no public/usable commands that we can run that can create/modify files on a client's computer, you need an addon. The most we can do is copy strings to the clipboard.

BUT

@iniDBi is a really nice addon for this, very easy to use, the hard part was multiplayer...

Edited by DreadedEntity

Share this post


Link to post
Share on other sites

there is profilenamespace (don't worry about this page showing TKOH) that can be used to saved data from one mission to another.

I can't recall if that was fixed for dedicated servers though.

alternatively inidb is a good move forward.

Share this post


Link to post
Share on other sites

I did a quick bit of research nothing lengthy tho. How would I implement this ?

Share this post


Link to post
Share on other sites

Well, setVariable and getVariable takes arrays, so you could squish the whole crate content in to one array, and then successfully fill them back from that array.

I'm not really able to test code until 6 hours or so, but here is some experimental code

Check below post;

Edited by 654wak654

Share this post


Link to post
Share on other sites

Awesome! I'll have to look at trying to implement it tomorrow tho as I'm also away from my computer.

Thanks for the help tho!

Share this post


Link to post
Share on other sites

Allright, so I'm pretty sure I've overdid myself with this. Here are 3 functions that does exactly what you want, and it's sooo pretty! They even have a little bit of configurability. I know it's changeable because I used this and will keep on using it after this point :cool:. Hope rest of the community enjoys these functions, I hope they are self-explanatory, but if anyone needs help I'd be happy to help.

Here is a really small example mission with the functions.

Wak_fnc_saveCrateContent

[color=#FF8040]Wak_fnc_saveCrateContent [color=#8B3E2F][b]=[/b][/color] [color=#8B3E2F][b]{[/b][/color]
   [color=#006400][i]/*
   Author: 654wak654
   Version 1.0

   Description:
   Saves content of given crate to profileNamespace.

   Parameter(s):
       0 : OBJ - the crate (default: _this).

   Returns:
   BOOL
   */[/i][/color]
   [color=#1874CD]_crate[/color] [color=#8B3E2F][b]=[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#000000]_this[/color][color=#8B3E2F][b],[/b][/color] [color=#FF0000]0[/color][color=#8B3E2F][b],[/b][/color] [color=#000000]_this[/color][color=#8B3E2F][b],[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#000000]objNull[/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b]][/b][/color] [color=#191970][b]call[/b][/color] BIS_fnc_param[color=#8B3E2F][b];[/b][/color]

   [color=#1874CD]_weapons[/color] [color=#8B3E2F][b]=[/b][/color] [color=#191970][b]getWeaponCargo[/b][/color] [color=#1874CD]_crate[/color][color=#8B3E2F][b];[/b][/color]
   [color=#1874CD]_ammo[/color] [color=#8B3E2F][b]=[/b][/color] [color=#191970][b]getMagazineCargo[/b][/color] [color=#1874CD]_crate[/color][color=#8B3E2F][b];[/b][/color]
   [color=#1874CD]_items[/color] [color=#8B3E2F][b]=[/b][/color] [color=#191970][b]getItemCargo[/b][/color] [color=#1874CD]_crate[/color][color=#8B3E2F][b];[/b][/color]
   [color=#1874CD]_backpacks[/color] [color=#8B3E2F][b]=[/b][/color] [color=#191970][b]getBackpackCargo[/b][/color] [color=#1874CD]_crate[/color][color=#8B3E2F][b];[/b][/color]

   [color=#1874CD]_cargo[/color] [color=#8B3E2F][b]=[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#1874CD]_weapons[/color][color=#8B3E2F][b],[/b][/color] [color=#1874CD]_ammo[/color][color=#8B3E2F][b],[/b][/color] [color=#1874CD]_items[/color][color=#8B3E2F][b],[/b][/color] [color=#1874CD]_backpacks[/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b];[/b][/color]
   [color=#191970][b]profileNamespace[/b][/color] [color=#191970][b]setVariable[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#7A7A7A]"Wak_crateContent"[/color][color=#8B3E2F][b],[/b][/color] [color=#1874CD]_cargo[/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b];[/b][/color]
   [color=#191970][b]saveProfileNamespace[/b][/color][color=#8B3E2F][b];[/b][/color]

   [color=#1874CD]_str[/color] [color=#8B3E2F][b]=[/b][/color] [color=#191970][b]parseText[/b][/color] [color=#191970][b]format[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#7A7A7A]"<t color='#00FF00'>Content Saved</t>"[/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b];[/b][/color]
   [color=#191970][b]hintSilent[/b][/color] [color=#1874CD]_str[/color][color=#8B3E2F][b];[/b][/color]
   [color=#000000]true[/color]
[color=#8B3E2F][b]}[/b][/color][color=#8B3E2F][b];[/b][/color][/color]

Wak_fnc_loadCrateContent

[color="#FF8040"]Wak_fnc_loadCrateContent [color="#8B3E2F"][b]=[/b][/color] [color="#8B3E2F"][b]{[/b][/color]
[color="#006400"][i]/*
Author: 654wak654
Version 1.0

Description:
Fills cargo of crate set by Wak_fnc_saveCrateContent.
If no save is found, returns false.

Parameter(s):
	0 : OBJ - the crate (default: _this).

Returns:
BOOL - True is save is found and loaded.
*/[/i][/color]
[color="#1874CD"]_crate[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#000000"]_this[/color][color="#8B3E2F"][b],[/b][/color] [color="#FF0000"]0[/color][color="#8B3E2F"][b],[/b][/color] [color="#000000"]_this[/color][color="#8B3E2F"][b],[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#000000"]objNull[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b]][/b][/color] [color="#191970"][b]call[/b][/color] BIS_fnc_param[color="#8B3E2F"][b];[/b][/color]

[color="#1874CD"]_cargo[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#191970"][b]profileNamespace[/b][/color] [color="#191970"][b]getVariable[/b][/color] [color="#7A7A7A"]"Wak_crateContent"[/color][color="#8B3E2F"][b];[/b][/color]
[color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#191970"][b]isNil[/b][/color] [color="#7A7A7A"]"_cargo"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color] [color="#8B3E2F"][b]{[/b][/color]
	[color="#191970"][b]hintSilent[/b][/color] [color="#7A7A7A"]"No Content to Load!"[/color][color="#8B3E2F"][b];[/b][/color]
	[color="#000000"]false[/color]
[color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]

[color="#1874CD"]_weapons[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#1874CD"]_cargo[/color] [color="#191970"][b]select[/b][/color] [color="#FF0000"]0[/color][color="#8B3E2F"][b];[/b][/color]
[color="#1874CD"]_ammo[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#1874CD"]_cargo[/color] [color="#191970"][b]select[/b][/color] [color="#FF0000"]1[/color][color="#8B3E2F"][b];[/b][/color]
[color="#1874CD"]_items[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#1874CD"]_cargo[/color] [color="#191970"][b]select[/b][/color] [color="#FF0000"]2[/color][color="#8B3E2F"][b];[/b][/color]
[color="#1874CD"]_backpacks[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#1874CD"]_cargo[/color] [color="#191970"][b]select[/b][/color] [color="#FF0000"]3[/color][color="#8B3E2F"][b];[/b][/color]

[color="#191970"][b]clearWeaponCargoGlobal[/b][/color] [color="#1874CD"]_crate[/color][color="#8B3E2F"][b];[/b][/color]
[color="#191970"][b]for[/b][/color] [color="#7A7A7A"]"_i"[/color] [color="#191970"][b]from[/b][/color] [color="#FF0000"]0[/color] [color="#191970"][b]to[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#8B3E2F"][b]([/b][/color][color="#191970"][b]count[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_weapons[/color] [color="#191970"][b]select[/b][/color] [color="#FF0000"]0[/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b])[/b][/color] [color="#8B3E2F"][b]-[/b][/color] [color="#FF0000"]1[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]do[/b][/color] [color="#8B3E2F"][b]{[/b][/color]
	[color="#1874CD"]_crate[/color] [color="#191970"][b]addWeaponCargoGlobal[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#8B3E2F"][b]([/b][/color][color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_weapons[/color] [color="#191970"][b]select[/b][/color] [color="#FF0000"]0[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]select[/b][/color] [color="#1874CD"]_i[/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b],[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_weapons[/color] [color="#191970"][b]select[/b][/color] [color="#FF0000"]1[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]select[/b][/color] [color="#1874CD"]_i[/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color]
[color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]

[color="#191970"][b]clearMagazineCargoGlobal[/b][/color] [color="#1874CD"]_crate[/color][color="#8B3E2F"][b];[/b][/color]
[color="#191970"][b]for[/b][/color] [color="#7A7A7A"]"_i"[/color] [color="#191970"][b]from[/b][/color] [color="#FF0000"]0[/color] [color="#191970"][b]to[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#8B3E2F"][b]([/b][/color][color="#191970"][b]count[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_ammo[/color] [color="#191970"][b]select[/b][/color] [color="#FF0000"]0[/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b])[/b][/color] [color="#8B3E2F"][b]-[/b][/color] [color="#FF0000"]1[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]do[/b][/color] [color="#8B3E2F"][b]{[/b][/color]
	[color="#1874CD"]_crate[/color] [color="#191970"][b]addMagazineCargoGlobal[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#8B3E2F"][b]([/b][/color][color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_ammo[/color] [color="#191970"][b]select[/b][/color] [color="#FF0000"]0[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]select[/b][/color] [color="#1874CD"]_i[/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b],[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_ammo[/color] [color="#191970"][b]select[/b][/color] [color="#FF0000"]1[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]select[/b][/color] [color="#1874CD"]_i[/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color]
[color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]

[color="#191970"][b]clearItemCargoGlobal[/b][/color] [color="#1874CD"]_crate[/color][color="#8B3E2F"][b];[/b][/color]
[color="#191970"][b]for[/b][/color] [color="#7A7A7A"]"_i"[/color] [color="#191970"][b]from[/b][/color] [color="#FF0000"]0[/color] [color="#191970"][b]to[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#8B3E2F"][b]([/b][/color][color="#191970"][b]count[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_items[/color] [color="#191970"][b]select[/b][/color] [color="#FF0000"]0[/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b])[/b][/color] [color="#8B3E2F"][b]-[/b][/color] [color="#FF0000"]1[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]do[/b][/color] [color="#8B3E2F"][b]{[/b][/color]
	[color="#1874CD"]_crate[/color] [color="#191970"][b]addItemCargoGlobal[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#8B3E2F"][b]([/b][/color][color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_items[/color] [color="#191970"][b]select[/b][/color] [color="#FF0000"]0[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]select[/b][/color] [color="#1874CD"]_i[/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b],[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_items[/color] [color="#191970"][b]select[/b][/color] [color="#FF0000"]1[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]select[/b][/color] [color="#1874CD"]_i[/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color]
[color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]

[color="#191970"][b]clearBackpackCargoGlobal[/b][/color] [color="#1874CD"]_crate[/color][color="#8B3E2F"][b];[/b][/color]
[color="#191970"][b]for[/b][/color] [color="#7A7A7A"]"_i"[/color] [color="#191970"][b]from[/b][/color] [color="#FF0000"]0[/color] [color="#191970"][b]to[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#8B3E2F"][b]([/b][/color][color="#191970"][b]count[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_backpacks[/color] [color="#191970"][b]select[/b][/color] [color="#FF0000"]0[/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b])[/b][/color] [color="#8B3E2F"][b]-[/b][/color] [color="#FF0000"]1[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]do[/b][/color] [color="#8B3E2F"][b]{[/b][/color]
	[color="#1874CD"]_crate[/color] [color="#191970"][b]addBackpackCargoGlobal[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#8B3E2F"][b]([/b][/color][color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_backpacks[/color] [color="#191970"][b]select[/b][/color] [color="#FF0000"]0[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]select[/b][/color] [color="#1874CD"]_i[/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b],[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_backpacks[/color] [color="#191970"][b]select[/b][/color] [color="#FF0000"]1[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]select[/b][/color] [color="#1874CD"]_i[/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color]
[color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]

[color="#1874CD"]_str[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#191970"][b]parseText[/b][/color] [color="#191970"][b]format[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#7A7A7A"]"<t color='#0000FF'>Content Loaded</t>"[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color]
[color="#191970"][b]hintSilent[/b][/color] [color="#1874CD"]_str[/color][color="#8B3E2F"][b];[/b][/color]
[color="#000000"]true[/color]
[color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color][/color]

Wak_fnc_deleteCrateContent

[color=#FF8040]Wak_fnc_deleteCrateContent [color=#8B3E2F][b]=[/b][/color] [color=#8B3E2F][b]{[/b][/color]
   [color=#006400][i]/*
   Author: 654wak654
   Version 1.0

   Description:
   Deletes crate saves of a player from profileNamespace.

   Returns:
   BOOL - True is save is found and deleted.
   */[/i][/color]
   [color=#1874CD]_cargo[/color] [color=#8B3E2F][b]=[/b][/color] [color=#191970][b]profileNamespace[/b][/color] [color=#191970][b]getVariable[/b][/color] [color=#7A7A7A]"Wak_crateContent"[/color][color=#8B3E2F][b];[/b][/color]
   [color=#191970][b]if[/b][/color] [color=#8B3E2F][b]([/b][/color][color=#191970][b]isNil[/b][/color] [color=#7A7A7A]"_cargo"[/color][color=#8B3E2F][b])[/b][/color] [color=#191970][b]exitWith[/b][/color] [color=#8B3E2F][b]{[/b][/color]
       [color=#191970][b]hintSilent[/b][/color] [color=#7A7A7A]"No Content to Delete!"[/color][color=#8B3E2F][b];[/b][/color]
       [color=#000000]false[/color]
   [color=#8B3E2F][b]}[/b][/color][color=#8B3E2F][b];[/b][/color]

   [color=#191970][b]profileNamespace[/b][/color] [color=#191970][b]setVariable[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#7A7A7A]"Wak_crateContent"[/color][color=#8B3E2F][b],[/b][/color] [color=#000000]nil[/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b];[/b][/color]
   [color=#191970][b]saveProfileNamespace[/b][/color][color=#8B3E2F][b];[/b][/color]

   [color=#1874CD]_str[/color] [color=#8B3E2F][b]=[/b][/color] [color=#191970][b]parseText[/b][/color] [color=#191970][b]format[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#7A7A7A]"<t color='#FF0000'>Content Deleted</t>"[/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b];[/b][/color]
   [color=#191970][b]hintSilent[/b][/color] [color=#1874CD]_str[/color][color=#8B3E2F][b];[/b][/color]
   [color=#000000]true[/color]
[color=#8B3E2F][b]}[/b][/color][color=#8B3E2F][b];[/b][/color][/color]

Made with KK's SQF to BBCode Converter.

Edited by 654wak654

Share this post


Link to post
Share on other sites

Forgive my ignorance, do I add that to a sqf and call it from each init of the ammobox ?

Share this post


Link to post
Share on other sites
Allright, so I'm pretty sure I've overdid myself with this. Here are 2 functions that does exactly what you want, and it's sooo pretty! They even have a little bit of configurability. I used non Global "addBlahBlahCargo" commands because I think that's how your private locker system works, but if not those are easily changeable. I know it's changeable because I used this and will keep on using it after this point :cool:. Hope rest of the community enjoys these functions, I hope they are self-explanatory, but if anyone needs help feel free to ask.

I also did some changes after final testing, so it might not be working :p.

Wak_fnc_saveCrateContent

[color=#FF8040]Wak_fnc_saveCrateContent [color=#8B3E2F][b]=[/b][/color] [color=#8B3E2F][b]{[/b][/color]
   [color=#006400][i]/*
   Author: 654wak654
   Version 1.0

   Description:
   Saves content of given crate to profileNamespace.

   Parameter(s):
       0 : OBJ - the crate (default: _this).

   Returns:
   BOOL
   */[/i][/color]
   [color=#1874CD]_crate[/color] [color=#8B3E2F][b]=[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#000000]_this[/color][color=#8B3E2F][b],[/b][/color] [color=#FF0000]0[/color][color=#8B3E2F][b],[/b][/color] [color=#000000]_this[/color][color=#8B3E2F][b],[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#000000]objNull[/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b]][/b][/color] [color=#191970][b]call[/b][/color] BIS_fnc_param[color=#8B3E2F][b];[/b][/color]

   [color=#1874CD]_weapons[/color] [color=#8B3E2F][b]=[/b][/color] [color=#191970][b]getWeaponCargo[/b][/color] [color=#1874CD]_crate[/color][color=#8B3E2F][b];[/b][/color]
   [color=#1874CD]_ammo[/color] [color=#8B3E2F][b]=[/b][/color] [color=#191970][b]getMagazineCargo[/b][/color] [color=#1874CD]_crate[/color][color=#8B3E2F][b];[/b][/color]
   [color=#1874CD]_items[/color] [color=#8B3E2F][b]=[/b][/color] [color=#191970][b]getItemCargo[/b][/color] [color=#1874CD]_crate[/color][color=#8B3E2F][b];[/b][/color]
   [color=#1874CD]_backpacks[/color] [color=#8B3E2F][b]=[/b][/color] [color=#191970][b]getBackpackCargo[/b][/color] [color=#1874CD]_crate[/color][color=#8B3E2F][b];[/b][/color]

   [color=#1874CD]_cargo[/color] [color=#8B3E2F][b]=[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#1874CD]_weapons[/color][color=#8B3E2F][b],[/b][/color] [color=#1874CD]_ammo[/color][color=#8B3E2F][b],[/b][/color] [color=#1874CD]_items[/color][color=#8B3E2F][b],[/b][/color] [color=#1874CD]_backpacks[/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b];[/b][/color]

   [color=#191970][b]profileNamespace[/b][/color] [color=#191970][b]setVariable[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#7A7A7A]"Wak_crateContent"[/color][color=#8B3E2F][b],[/b][/color] [color=#1874CD]_cargo[/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b];[/b][/color]
   [color=#191970][b]saveProfileNamespace[/b][/color][color=#8B3E2F][b];[/b][/color]
   [color=#000000]true[/color]
[color=#8B3E2F][b]}[/b][/color][color=#8B3E2F][b];[/b][/color][/color]

Wak_fnc_loadCrateContent

[color=#FF8040]Wak_fnc_loadCrateContent [color=#8B3E2F][b]=[/b][/color] [color=#8B3E2F][b]{[/b][/color]
   [color=#006400][i]/*
   Author: 654wak654
   Version 1.0

   Description:
   Fills cargo of crate set by Wak_fnc_saveCrateContent.
   If no result is found, crate is emptied or left as is.

   Parameter(s):
       0 : OBJ - the crate (default: _this).
       1 (Optional) : BOOL - if no save is found, empty the crate or not (default: true).

   Returns:
   BOOL
   */[/i][/color]
   [color=#1874CD]_crate[/color] [color=#8B3E2F][b]=[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#000000]_this[/color][color=#8B3E2F][b],[/b][/color] [color=#FF0000]0[/color][color=#8B3E2F][b],[/b][/color] [color=#000000]_this[/color][color=#8B3E2F][b],[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#000000]objNull[/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b]][/b][/color] [color=#191970][b]call[/b][/color] BIS_fnc_param[color=#8B3E2F][b];[/b][/color]
   [color=#1874CD]_empty[/color] [color=#8B3E2F][b]=[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#000000]_this[/color][color=#8B3E2F][b],[/b][/color] [color=#FF0000]1[/color][color=#8B3E2F][b],[/b][/color] [color=#000000]true[/color][color=#8B3E2F][b]][/b][/color] [color=#191970][b]call[/b][/color] BIS_fnc_param[color=#8B3E2F][b];[/b][/color]

   [color=#1874CD]_cargo[/color] [color=#8B3E2F][b]=[/b][/color] [color=#191970][b]profileNamespace[/b][/color] [color=#191970][b]getVariable[/b][/color] [color=#7A7A7A]"Wak_crateContent"[/color][color=#8B3E2F][b];[/b][/color]

   [color=#191970][b]if[/b][/color] [color=#8B3E2F][b]([/b][/color][color=#191970][b]isNil[/b][/color] [color=#7A7A7A]"_cargo"[/color][color=#8B3E2F][b])[/b][/color] [color=#191970][b]exitWith[/b][/color] [color=#8B3E2F][b]{[/b][/color]
       [color=#191970][b]if[/b][/color] [color=#8B3E2F][b]([/b][/color][color=#1874CD]_empty[/color][color=#8B3E2F][b])[/b][/color] [color=#191970][b]then[/b][/color] [color=#8B3E2F][b]{[/b][/color]
       [color=#191970][b]clearWeaponCargo[/b][/color] [color=#1874CD]_crate[/color][color=#8B3E2F][b];[/b][/color]
       [color=#191970][b]clearMagazineCargo[/b][/color] [color=#1874CD]_crate[/color][color=#8B3E2F][b];[/b][/color]
       [color=#191970][b]clearItemCargo[/b][/color] [color=#1874CD]_crate[/color][color=#8B3E2F][b];[/b][/color]
       [color=#191970][b]clearBackpackCargo[/b][/color] [color=#1874CD]_crate[/color][color=#8B3E2F][b];[/b][/color]
       [color=#8B3E2F][b]}[/b][/color][color=#8B3E2F][b];[/b][/color]
   [color=#8B3E2F][b]}[/b][/color][color=#8B3E2F][b];[/b][/color]

   [color=#1874CD]_weapons[/color] [color=#8B3E2F][b]=[/b][/color] [color=#1874CD]_cargo[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]0[/color][color=#8B3E2F][b];[/b][/color]
   [color=#1874CD]_ammo[/color] [color=#8B3E2F][b]=[/b][/color] [color=#1874CD]_cargo[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]1[/color][color=#8B3E2F][b];[/b][/color]
   [color=#1874CD]_items[/color] [color=#8B3E2F][b]=[/b][/color] [color=#1874CD]_cargo[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]2[/color][color=#8B3E2F][b];[/b][/color]
   [color=#1874CD]_backpacks[/color] [color=#8B3E2F][b]=[/b][/color] [color=#1874CD]_cargo[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]3[/color][color=#8B3E2F][b];[/b][/color]

   [color=#191970][b]clearWeaponCargo[/b][/color] [color=#1874CD]_crate[/color][color=#8B3E2F][b];[/b][/color]
   [color=#191970][b]for[/b][/color] [color=#7A7A7A]"_i"[/color] [color=#191970][b]from[/b][/color] [color=#FF0000]0[/color] [color=#191970][b]to[/b][/color] [color=#8B3E2F][b]([/b][/color][color=#8B3E2F][b]([/b][/color][color=#191970][b]count[/b][/color] [color=#8B3E2F][b]([/b][/color][color=#1874CD]_weapons[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]0[/color][color=#8B3E2F][b])[/b][/color][color=#8B3E2F][b])[/b][/color] [color=#8B3E2F][b]-[/b][/color] [color=#FF0000]1[/color][color=#8B3E2F][b])[/b][/color] [color=#191970][b]do[/b][/color] [color=#8B3E2F][b]{[/b][/color]
       [color=#1874CD]_crate[/color] [color=#191970][b]addWeaponCargo[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#8B3E2F][b]([/b][/color][color=#8B3E2F][b]([/b][/color][color=#1874CD]_weapons[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]0[/color][color=#8B3E2F][b]) [/b][/color][color=#191970][b]select[/b][/color] [color=#1874CD]_i[/color][color=#8B3E2F][b])[/b][/color][color=#8B3E2F][b],[/b][/color] [color=#8B3E2F][b]([/b][/color][color=#8B3E2F][b]([/b][/color][color=#1874CD]_weapons[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]1[/color][color=#8B3E2F][b])[/b][/color] [color=#191970][b]select[/b][/color] [color=#1874CD]_i[/color][color=#8B3E2F][b])[/b][/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b];[/b][/color]
   [color=#8B3E2F][b]}[/b][/color][color=#8B3E2F][b];[/b][/color]

   [color=#191970][b]clearMagazineCargo[/b][/color] [color=#1874CD]_crate[/color][color=#8B3E2F][b];[/b][/color]
   [color=#191970][b]for[/b][/color] [color=#7A7A7A]"_i"[/color] [color=#191970][b]from[/b][/color] [color=#FF0000]0[/color] [color=#191970][b]to[/b][/color] [color=#8B3E2F][b]([/b][/color][color=#8B3E2F][b]([/b][/color][color=#191970][b]count[/b][/color] [color=#8B3E2F][b]([/b][/color][color=#1874CD]_ammo[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]0[/color][color=#8B3E2F][b])[/b][/color][color=#8B3E2F][b])[/b][/color] [color=#8B3E2F][b]-[/b][/color] [color=#FF0000]1[/color][color=#8B3E2F][b])[/b][/color] [color=#191970][b]do[/b][/color] [color=#8B3E2F][b]{[/b][/color]
       [color=#1874CD]_crate[/color] [color=#191970][b]addMagazineCargo[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#8B3E2F][b]([/b][/color][color=#8B3E2F][b]([/b][/color][color=#1874CD]_ammo[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]0[/color][color=#8B3E2F][b]) [/b][/color][color=#191970][b]select[/b][/color] [color=#1874CD]_i[/color][color=#8B3E2F][b])[/b][/color][color=#8B3E2F][b],[/b][/color] [color=#8B3E2F][b]([/b][/color][color=#8B3E2F][b]([/b][/color][color=#1874CD]_ammo[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]1[/color][color=#8B3E2F][b])[/b][/color] [color=#191970][b]select[/b][/color] [color=#1874CD]_i[/color][color=#8B3E2F][b])[/b][/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b];[/b][/color]
   [color=#8B3E2F][b]}[/b][/color][color=#8B3E2F][b];[/b][/color]

   [color=#191970][b]clearItemCargo[/b][/color] [color=#1874CD]_crate[/color][color=#8B3E2F][b];[/b][/color]
   [color=#191970][b]for[/b][/color] [color=#7A7A7A]"_i"[/color] [color=#191970][b]from[/b][/color] [color=#FF0000]0[/color] [color=#191970][b]to[/b][/color] [color=#8B3E2F][b]([/b][/color][color=#8B3E2F][b]([/b][/color][color=#191970][b]count[/b][/color] [color=#8B3E2F][b]([/b][/color][color=#1874CD]_items[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]0[/color][color=#8B3E2F][b])[/b][/color][color=#8B3E2F][b])[/b][/color] [color=#8B3E2F][b]-[/b][/color] [color=#FF0000]1[/color][color=#8B3E2F][b])[/b][/color] [color=#191970][b]do[/b][/color] [color=#8B3E2F][b]{[/b][/color]
       [color=#1874CD]_crate[/color] [color=#191970][b]addMagazineCargo[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#8B3E2F][b]([/b][/color][color=#8B3E2F][b]([/b][/color][color=#1874CD]_items[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]0[/color][color=#8B3E2F][b]) [/b][/color][color=#191970][b]select[/b][/color] [color=#1874CD]_i[/color][color=#8B3E2F][b])[/b][/color][color=#8B3E2F][b],[/b][/color] [color=#8B3E2F][b]([/b][/color][color=#8B3E2F][b]([/b][/color][color=#1874CD]_items[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]1[/color][color=#8B3E2F][b])[/b][/color] [color=#191970][b]select[/b][/color] [color=#1874CD]_i[/color][color=#8B3E2F][b])[/b][/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b];[/b][/color]
   [color=#8B3E2F][b]}[/b][/color][color=#8B3E2F][b];[/b][/color]

   [color=#191970][b]clearBackpackCargo[/b][/color] [color=#1874CD]_crate[/color][color=#8B3E2F][b];[/b][/color]
   [color=#191970][b]for[/b][/color] [color=#7A7A7A]"_i"[/color] [color=#191970][b]from[/b][/color] [color=#FF0000]0[/color] [color=#191970][b]to[/b][/color] [color=#8B3E2F][b]([/b][/color][color=#8B3E2F][b]([/b][/color][color=#191970][b]count[/b][/color] [color=#8B3E2F][b]([/b][/color][color=#1874CD]_backpacks[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]0[/color][color=#8B3E2F][b])[/b][/color][color=#8B3E2F][b])[/b][/color] [color=#8B3E2F][b]-[/b][/color] [color=#FF0000]1[/color][color=#8B3E2F][b])[/b][/color] [color=#191970][b]do[/b][/color] [color=#8B3E2F][b]{[/b][/color]
       [color=#1874CD]_crate[/color] [color=#191970][b]addMagazineCargo[/b][/color] [color=#8B3E2F][b][[/b][/color][color=#8B3E2F][b]([/b][/color][color=#8B3E2F][b]([/b][/color][color=#1874CD]_backpacks[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]0[/color][color=#8B3E2F][b]) [/b][/color][color=#191970][b]select[/b][/color] [color=#1874CD]_i[/color][color=#8B3E2F][b])[/b][/color][color=#8B3E2F][b],[/b][/color] [color=#8B3E2F][b]([/b][/color][color=#8B3E2F][b]([/b][/color][color=#1874CD]_backpacks[/color] [color=#191970][b]select[/b][/color] [color=#FF0000]1[/color][color=#8B3E2F][b])[/b][/color] [color=#191970][b]select[/b][/color] [color=#1874CD]_i[/color][color=#8B3E2F][b])[/b][/color][color=#8B3E2F][b]][/b][/color][color=#8B3E2F][b];[/b][/color]
   [color=#8B3E2F][b]}[/b][/color][color=#8B3E2F][b];[/b][/color]
   [color=#000000]true[/color]
[color=#8B3E2F][b]}[/b][/color][color=#8B3E2F][b];[/b][/color][/color]

Shown with KK's SQF to BBCode Converter.

Ok so I'm still new to scripting and stuff but this is what I'm doing

savecontent.sqf

Wak_fnc_saveCrateContent = {
   /*
   Author: 654wak654
   Version 1.0

   Description:
   Saves content of given crate to profileNamespace.

   Parameter(s):
       0 : OBJ - the crate (default: _this).

   Returns:
   BOOL
   */
   _crate = [_this, 0, _this, [objNull]] call BIS_fnc_param;

   _weapons = getWeaponCargo _crate;
   _ammo = getMagazineCargo _crate;
   _items = getItemCargo _crate;
   _backpacks = getBackpackCargo _crate;

   _cargo = [_weapons, _ammo, _items, _backpacks];

   profileNamespace setVariable ["Wak_crateContent", _cargo];
   saveProfileNamespace;
   true
};

loadcontent.sqf

Wak_fnc_loadCrateContent = {
   /*
   Author: 654wak654
   Version 1.0

   Description:
   Fills cargo of crate set by Wak_fnc_saveCrateContent.
   If no result is found, crate is emptied or left as is.

   Parameter(s):
       0 : OBJ - the crate (default: _this).
       1 (Optional) : BOOL - if no save is found, empty the crate or not (default: true).

   Returns:
   BOOL
   */
   _crate = [_this, 0, _this, [objNull]] call BIS_fnc_param;
   _empty = [_this, 1, true] call BIS_fnc_param;

   _cargo = profileNamespace getVariable "Wak_crateContent";

   if (isNil "_cargo") exitWith {
       if (_empty) then {
       clearWeaponCargoGlobal _crate;
       clearMagazineCargoGlobal _crate;
       clearItemCargoGlobal _crate;
       clearBackpackCargoGlobal _crate;
       };
   };

   _weapons = _cargo select 0;
   _ammo = _cargo select 1;
   _items = _cargo select 2;
   _backpacks = _cargo select 3;

   clearWeaponCargoGlobal _crate;
   for "_i" from 0 to ((count (_weapons select 0)) - 1) do {
       _crate addWeaponCargoGlobal [((_weapons select 0) select _i), ((_weapons select 1) select _i)];
   };

   clearMagazineCargoGlobal _crate;
   for "_i" from 0 to ((count (_ammo select 0)) - 1) do {
       _crate addMagazineCargoGlobal [((_ammo select 0) select _i), ((_ammo select 1) select _i)];
   };

   clearItemCargoGlobal _crate;
   for "_i" from 0 to ((count (_items select 0)) - 1) do {
       _crate addMagazineCargoGlobal [((_items select 0) select _i), ((_items select 1) select _i)];
   };

   clearBackpackCargoGlobal _crate;
   for "_i" from 0 to ((count (_backpacks select 0)) - 1) do {
       _crate addMagazineCargoGlobal [((_backpacks select 0) select _i), ((_backpacks select 1) select _i)];
   };
   true
};

And in the ammobox i want saved i have :

this addaction [("<t color=""#0074E8"">" + ("Save Content") +"</t>"),"scripts\savecontent.sqf","",5,false,true,"",""];this addAction ["Locker D-5", ""]; this allowDamage False;this addaction [("<t color=""#ffff00"">" + ("Boydee") +"</t>"),"","",5,false,true,"",""];

and in the mission init.sqf

[] execVM "scripts\loadcontent.sqf"; // Loads lockers save state

Im obviously doing something wrong im not sure what tho. I also added Global to the end of some of the commands for mp.

Share this post


Link to post
Share on other sites

Hey Boydee that code was a little bit broken and I haven't explained how to use functions in mission and stuff. There is an example mission in the original post now, and if you want to know more, here is some reading material.

Share this post


Link to post
Share on other sites

Awesome I'll check it out. Should this work on a dedicated server??

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×