Jump to content
TomMack

Save Object to Profile Namesapce

Recommended Posts

Hi all,

 

I need to save certain objects, like vehicles, weapon crates (and their contents) as well as units.

 

Also, for destroyed vehicles and killed units to not be saved to the namespace.

 

How would I do this? Currently I have been able to load and save a units loadout to the namespace (using get/setUnitLoadout), but have not been able to get further.

 

Thanks,

Tom

Share this post


Link to post
Share on other sites
2 hours ago, das attorney said:

you can't save the objects themselves, but you can save their classes and positions etc onto profileNameSpace.

 

If you google "persistence profilenamespace" there's a ton of hits like these:

 

https://gist.github.com/MosesUK/4a92eafb71be1ca14eb7

 

Thanks for the response,

 

I'm not using this on a server and while I understand that the base code will still work... filtering through the server side stuff on the GitHib link is really difficult. For example; I dont understand how it can get the variable for the position or the direction (it just gets a variable, which isnt defined in that script). Obviously you can use "position" and "direction", but it isn't explained. 

 

I want a way to check if the unit is alive too and most importantly, be able to carry the cargo from inside a container across.

 

Something like this ::

 

"all vehicles in this area/trigger" get pos, direction, health and save to namespace

save to namespace "content of all ammo crates in this area/trigger"

 

//buddy

if (alive buddy) then {buddy-alive = true} <--- save this variable to namespace (this can be checked in the next mission and if true, then he will be visible.)

Share this post


Link to post
Share on other sites

Off the top of my head, I would try something like this (untested):

// define an area (like a marker or something)
_myPos = markerPos "myMarker";
// find the vehicles
_myVehicles = _myPos nearEntities ["LandVehicle",300];
_list = [];
{
    _list pushBack [typeOf _x,getPosWorld _x,getDir _x,damage _x]
} forEach _myVehicles;
profileNamespace setVariable ["myVehicles",_list];
saveProfileNamespace;

 

Then to reassemble:

 

{
    _x params ["_typ","_pos","_dir","_dam"];
    _veh = createVehicle [_typ,_pos,[],0,"can_collide"];
    _veh setPosWorld _pos;
    _veh setDir _dir;
    _veh setDamage _dam;
} forEach (profileNamespace getVariable ["myVehicles",[]]);

 

Share this post


Link to post
Share on other sites
50 minutes ago, das attorney said:

Off the top of my head, I would try something like this (untested):


// define an area (like a marker or something)
_myPos = markerPos "myMarker";
// find the vehicles
_myVehicles = _myPos nearEntities ["LandVehicle",300];
_list = [];
{
    _list pushBack [typeOf _x,getPosWorld _x,getDir _x,damage _x]
} forEach _myVehicles;
profileNamespace setVariable ["myVehicles",_list];
saveProfileNamespace;

 

Then to reassemble:

 


{
    _x params ["_typ","_pos","_dir","_dam"];
    _veh = createVehicle [_typ,_pos,[],0,"can_collide"];
    _veh setPosWorld _pos;
    _veh setDir _dir;
    _veh setDamage _dam;
} forEach (profileNamespace getVariable ["myVehicles",[]]);

 

 

thanks,

 

While it didnt return any errors, the code didnt work.

Share this post


Link to post
Share on other sites

any further ideas?

Share this post


Link to post
Share on other sites

I just tried the code in the editor and it works fine.  Not sure what's gone wrong for you there. 

 

If you put this into the debug console, what do you see on screen in the chat area? (after running code)

 

systemChat format ["myVar: %1", profileNamespace getVariable ["myVehicles",[]]]

 

Share this post


Link to post
Share on other sites
22 hours ago, das attorney said:

I just tried the code in the editor and it works fine.  Not sure what's gone wrong for you there. 

 

If you put this into the debug console, what do you see on screen in the chat area? (after running code)

 


systemChat format ["myVar: %1", profileNamespace getVariable ["myVehicles",[]]]

 

 

Never mind, seemed to work having tried it a second time, many thanks.

 

I suppose for ammo crates and/or units, i can create an array of object classes and stick that array name into the nearEntities function? or even better the ID names of the objects.

Share this post


Link to post
Share on other sites

Yes either of those would be fine depending on what you want to do.

 

Bear in mind though that if you want to keep the contents of crates/vehicles and inventory of units persistent, then you'll need to write in some additional code to grab them and replicate them.

  • Like 1

Share this post


Link to post
Share on other sites

Psssst.

Try checking this out, I hope it might help you out !

 

Careful: if you want to use this for multiplayer use, remember that players can edit this namespace very easily.

 

xbwb

Share this post


Link to post
Share on other sites
1 hour ago, xBowBii said:

Psssst.

 

 

Can this be modified to only save ammo crates within a certain area?

Share this post


Link to post
Share on other sites
On 6/11/2017 at 5:07 PM, TomMack said:

 

Can this be modified to only save ammo crates within a certain area?

Sure! 

Check for the "foreach allMissionObjects" if I remember correctly. Replace that with an array containing the list of ammo crates which you van get easily. (NearSupplies, nearObjects, allMissionObjects etc, then filter all those objects with typeOf)

Share this post


Link to post
Share on other sites
2 hours ago, xBowBii said:

Sure! 

Check for the "foreach allMissionObjects" if I remember correctly. Replace that with an array containing the list of ammo crates which you van get easily. (NearSupplies, nearObjects, allMissionObjects etc, then filter all those objects with typeOf)

 

I created an array called "_ammoBoxClass" which contained the classes of the ammo boxes I wanted saved and changed the ForEach to the array I'd made. However i get this error...

 

In the saveVehicle.sqf I added...

_ammoBoxClass = ["Box_IND_AmmoOrd_F","Box_IND_Wps_F"];    ...line after the "SURV_VehiclesLoaded" = false; line

 

then changed the ForEach line to say..

} forEach _ammoBoxClass;

 

Any ideas? Having an array of the classes I want saved would be very useful indeed.

 

Thanks.

 

Share this post


Link to post
Share on other sites
1 hour ago, TomMack said:

 

I created an array called "_ammoBoxClass" which contained the classes of the ammo boxes I wanted saved and changed the ForEach to the array I'd made. However i get this error...

 

In the saveVehicle.sqf I added...

_ammoBoxClass = ["Box_IND_AmmoOrd_F","Box_IND_Wps_F"];    ...line after the "SURV_VehiclesLoaded" = false; line

 

then changed the ForEach line to say..

} forEach _ammoBoxClass;

 

Any ideas? Having an array of the classes I want saved would be very useful indeed.

 

Thanks.

 

Make it something like this 

ForEach (allMissionObjects ["classnameAmmoBox1", "classnameAmmoBox2"]) ;

 

I think that should work.

https://community.bistudio.com/wiki/allMissionObjects

 

Édit:

Yours would use forEach (allMissionObjects _ammoBoxClass); try both methods I listed ;)

Share this post


Link to post
Share on other sites

Alrighty. Thanks so so much!

 

I've made some additions so it handles ammobox's. It may be very useful for you to see too. I'll make a reply to your scripts thread instead tho.

 

Once again, thanks both of you. 

 

Tom

 

  • Like 1

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

×