Jump to content
Sign in to follow this  
Tankbuster

player setvariable and namespaces

Recommended Posts

Am I not understanding the differences or similarities with these commands?

I'm fiddling with BIS_fnc_saveInventory and BIS_fnc_loadInventory. These save data to a namespace.

But I also see player setvariable ["invtry", _arrayvariablecontainingmyloadout, false].

I was wondering if player setvariable is the same thing as [player , [profileNamespace, "invtry"]] call BIS_fnc_saveInventory

Or perhaps the question I should be asking is..

If im planning to save a loadout so that it is there when a player rejoins a server, what's the best way for me?

Share this post


Link to post
Share on other sites

The one containing profileNamespace would be your only "persistent" code AFAIK, the player setVariable line will be attached to the player object until the player either disconnects or the mission/server restarts.

Share this post


Link to post
Share on other sites

If im planning to save a loadout so that it is there when a player rejoins a server, what's the best way for me?

If you want it to be the same within each mission use the missionNameSpace of the Server,

If you want it to be consistent throughout multiple missions use the profileNameSpace of the Server.

At least that's how I understood it.

Share this post


Link to post
Share on other sites
If you want it to be the same within each mission use the missionNameSpace of the Server,

If you want it to be consistent throughout multiple missions use the profileNameSpace of the Server.

At least that's how I understood it.

Aha! A lightbulb has just come on! profileNamespace is server side? I assumed it was client side!

---------- Post added at 15:55 ---------- Previous post was at 15:54 ----------

The one containing profileNamespace would be your only "persistent" code AFAIK, the player setVariable line will be attached to the player object until the player either disconnects or the mission/server restarts.

That's what I assumed. Thanks John.

---------- Post added at 15:56 ---------- Previous post was at 15:55 ----------

the player setVariable line will be attached to the player object until the player either disconnects or the mission/server restarts.

Follow up question then.. how does player setVariable behave when the player respawns?

Share this post


Link to post
Share on other sites

profileNamespace is both client and server side, it's just dependent on where you execute "profileNamespace" as a command. As far as an object variable on respawn, I believe it's persistent through respawn...(I kringe, do a flip, and hope that's correct, can't exactly remember atm).

Server's are players too :) (hypothetically speaking of course).

Share this post


Link to post
Share on other sites

ProfileNameSpace isn't server side, but the server should have its own namespace, so be sure to add an isServer check or similar.

player getvariable "xyz" should be nil after a respawn, as far as I know, since it's not the same "object".

Mind you my MP scripting knowledge is pretty basic.

Cheers

Share this post


Link to post
Share on other sites

player getvariable "xyz" should be nil after a respawn, as far as I know, since it's not the same "object".

Mind you my MP scripting knowledge is pretty basic.

Cheers

Actually, even if it does go nil after respawn, if you use a respawn EH you would still have access to the old object within the EH's scope, so you should be able to access it there and even apply the variable again to the new unit(should it not be persistent).

Share this post


Link to post
Share on other sites
If im planning to save a loadout so that it is there when a player rejoins a server, what's the best way for me period?

save loadout array with client-side profileNamespace setVariable.

if (!isServer) then
{
    profileNamespace setVariable ["DE_playerLoadout", _myLoadout];
};

This will create a variable called "DE_playerLoadout" which contains the contents of "_myLoadout" in your "PROFILE_NAME.vars.Arma3Profile" file located on your computer. DE_playerLoadout will be freely available to anybody that knows the name of it by using:

_myLoadout = profileNamespace getVariable ["DE_playerLoadout", []];

Note: If somebody knows the name of it, they can freely edit the contents, save it back to their profile, and you will have no idea they did. Also, I haven't found any way to bar someone from accessing a profile variable so I'm assuming it's not possible

Share this post


Link to post
Share on other sites

Note: If somebody knows the name of it, they can freely edit the contents, save it back to their profile, and you will have no idea they did. Also, I haven't found any way to bar someone from accessing a profile variable so I'm assuming it's not possible

Should be possible to save it on the servers profileNameSpace, using the playerUID or profilename as variable name.

Share this post


Link to post
Share on other sites
Should be possible to save it on the servers profileNameSpace, using the playerUID or profilename as variable name.

Yes, I was thinking the same. If you're going to save it on the server, you need to individualise it for each player.

At the moment, I'm messing with BIS_fnc (load/save)_inventory and am currently saving it to players profileNamespace and in test missions it works fine. Let's see how it we get on when I plug it into my mission, complete with revive.

Share this post


Link to post
Share on other sites
Should be possible to save it on the servers profileNameSpace, using the playerUID or profilename as variable name.

True, I was only pointing out the absolutely easiest method. Not everybody can or wants to use publicVariable, it adds another layer of complexity

Share this post


Link to post
Share on other sites

As I understand it... missionNamespace == publicVariable?

Share this post


Link to post
Share on other sites

missionNamespace == global variable.

A global variable can be synced with other machines via the use of publicVariable# commands.

if ( !isServer ) then {
waitUntil { player == player };

MyGlobalVariable = "Hello";
missionNamespace setVariable [ "MNS_Variable", "World" ];
MyPublicVariable = "Default";

player sideChat format [ "MyGlobalVariable accessed via MissionNamespace = %1",
	missionNamespace getVariable "MyGlobalVariable" ];

player sideChat format [ "MissionNamespace variable accessed as global variable = %1",
	MNS_Variable ];

player sideChat format [ "MyPublicVariable variables default value = %1",
	MyPublicVariable ];

"MyPublicVariable" addPublicVariableEventHandler {
	player sideChat format [ "MyPublicVariable synced value = %1",
		MyPublicVariable ];
};

[ [], "fnc_transmit", false ] call BIS_fnc_MP;

};

if ( isServer ) then {

MyPublicVariable = "Hello Clients";

fnc_transmit = {
	publicVariable "MyPublicVariable";
};

};

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  

×