bumyplum 10 Posted September 8, 2019 How do you get a player profileName from their objVar for eample: profileName = "Player1"; how do i get Player1's object var just from their name Share this post Link to post Share on other sites
M1ke_SK 230 Posted September 8, 2019 12 minutes ago, bumyplum said: How do you get a player profileName from their objVar for eample: profileName = "Player1"; how do i get Player1's object var just from their name https://community.bistudio.com/wiki/profileName https://community.bistudio.com/wiki/vehicleVarName https://community.bistudio.com/wiki/format Share this post Link to post Share on other sites
bumyplum 10 Posted September 8, 2019 13 minutes ago, M1ke_SK said: https://community.bistudio.com/wiki/profileName https://community.bistudio.com/wiki/vehicleVarName https://community.bistudio.com/wiki/format I've already attempted, _name = format["%1", profileName]; _id = vehicleVarName _name; hint str _id; // which doesn't seem to work Share this post Link to post Share on other sites
wogz187 1085 Posted September 8, 2019 @bumyplum, Like this? playerID= profileName; hintSilent format ["%1", playerID]; Have fun! Share this post Link to post Share on other sites
bumyplum 10 Posted September 8, 2019 8 minutes ago, wogz187 said: @bumyplum, Like this? playerID= profileName; hintSilent format ["%1", playerID]; Have fun! Thanks for the input how ever i'm trying to get what BIS_fnc_objectVar returns hint str (player call BIS_fnc_objectVar); // "bis_o2_692" just using a profileName, hint str (profileName call BIS_fnc_objectVar); Would be good but doesn't work ie. i'm attempting to get the "bis_o2_692" from a profileName and not player Share this post Link to post Share on other sites
Mr H. 400 Posted September 8, 2019 I'm guessing his question is for multiplayer. How to get profileName from a remote player. Since profilename is local to a player's machine you can't directly know who's who on a remote machine. You have to gather them in a public var. {_allNames =missionNameSpace getVariable ["allNames",[]]; _allnames pushbackUnique [profileName,player]; missionNameSpace setVariable ["allNames",_allNames,true]} RemoteExec ["Call",0]; This will create a missionnamespace array of arrays where select 0 is profilename and select 1 associated player object Sorry for not formatting in proper code textblock but I'm on my phone 2 Share this post Link to post Share on other sites
bumyplum 10 Posted September 8, 2019 1 hour ago, Mr H. said: Sorry for not formatting in proper code textblock but I'm on my phone []spawn { missionNameSpace setVariable ["allNames",[] ,true]; _selectedTargetName = "FR0STY"; [{ _allNames = missionNameSpace getVariable ["allNames",[]]; _allNames pushbackUnique [profileName, player]; missionNameSpace setVariable ["allNames",_allNames,true]; }] remoteExec ["BIS_fnc_spawn",0,false]; sleep 0.1; _allNames = missionNameSpace getVariable ["allNames",false]; hint str _allNames; private _subNames = []; for "_i" from 0 to (count _allNames - 1) do { _findNamePos = ((_allNames select _i) find _selectedTargetName); if !(_findNamePos isEqualTo -1) then { _subNames pushBack [_i ,_findNamePos, ((_allNames select _i)select 0), ((_allNames select _i)select 1)]; }; }; _selectedTarget = ((_subNames select 0) select 3); player setVariable["_selectedTarget", _selectedTarget]; hint str _selectedTarget; }; []spawn { sleep 0.1; _selectedTarget = player getVariable["_selectedTarget", false]; hint format["%1", _selectedTarget]; _selectedTarget setDamage 1; }; is what i currently have and works accordingly // with some extra details 2 Share this post Link to post Share on other sites
Dedmen 2588 Posted September 11, 2019 On 9/8/2019 at 10:40 PM, bumyplum said: []spawn { missionNameSpace setVariable ["allNames",[] ,true]; _selectedTargetName = "FR0STY"; [{ _allNames = missionNameSpace getVariable ["allNames",[]]; _allNames pushbackUnique [profileName, player]; missionNameSpace setVariable ["allNames",_allNames,true]; }] remoteExec ["BIS_fnc_spawn",0,false]; sleep 0.1; _allNames = missionNameSpace getVariable ["allNames",false]; hint str _allNames; private _subNames = []; for "_i" from 0 to (count _allNames - 1) do { _findNamePos = ((_allNames select _i) find _selectedTargetName); if !(_findNamePos isEqualTo -1) then { _subNames pushBack [_i ,_findNamePos, ((_allNames select _i)select 0), ((_allNames select _i)select 1)]; }; }; _selectedTarget = ((_subNames select 0) select 3); player setVariable["_selectedTarget", _selectedTarget]; hint str _selectedTarget; }; []spawn { sleep 0.1; _selectedTarget = player getVariable["_selectedTarget", false]; hint format["%1", _selectedTarget]; _selectedTarget setDamage 1; }; oh my gawd.... For one, sleep 0.1 is not enough. Second what is that _subnames thing where you do such complicated stuff in a very inefficient for loop, just to get a single element out of the array at the end? Here's my go at that. //optimally you put //player setVariable ["profileName", profileName, true]; //into initPlayerLocal.sqf. //If you want to have this serverside only then you can call this from the server once: ded_fnc_profileNameVarInit = { [{ player setVariable ["profileName", profileName, true]; }] remoteExec ["call",0,true]; }; ded_fnc_findPlayerByProfileName = { params ["_profileName"]; _selectedTargetName = ""; //Wait for all players to have their profileName set. waitUntil {allPlayers findIf {isNull (_x getVariable ["profileName", scriptNull])} == -1}; private _allPlayers = allPlayers; //copy as it might change between now and the select at the end. private _playerIndex = _allPlayers findIf {((_x getVariable["profileName", ""]) find _profileName) != -1}; _allPlayers param [_playerIndex, objNull]; }; []spawn { _selectedTarget = ["FR0STY"] call ded_fnc_findPlayerByProfileName; hint format["%1", _selectedTarget]; _selectedTarget setDamage 1; }; On 9/8/2019 at 9:31 PM, bumyplum said: Thanks for the input how ever i'm trying to get what BIS_fnc_objectVar returns hint str (player call BIS_fnc_objectVar); // "bis_o2_692" just using a profileName You don't. That's not how that works. 3 Share this post Link to post Share on other sites
bumyplum 10 Posted September 11, 2019 12 hours ago, Dedmen said: You don't. That's not how that works. I realised it wasn't the best option, how ever i figured my own way of doing it. private _arr = []; { _1 = [name _x]; _2 = [_x]; _3 = _1 + _2; _arr pushBack _3; } forEach allPlayers; private _selectedTarget = []; for "_i" from 0 to (count _arr - 1) do { _findNamePos = ((_arr select _i) find _selectedTargetName); if !(_findNamePos isEqualTo -1) then { _selectedTarget pushBack ((_arr select _i)select 1); }; }; _selectedTarget = _selectedTarget select 0; Instead of remote executing it your able to do it though a foreach statement. Thanks 🙂 1 Share this post Link to post Share on other sites
Dedmen 2588 Posted September 12, 2019 12 hours ago, bumyplum said: Instead of remote executing it your able to do it though a foreach statement. Thanks 🙂 That doesn't check profileName at all. Also you still have that nonsense complicated inefficient for loop mess in there. Why? For what purpose? 12 hours ago, bumyplum said: _1 = [name _x]; _2 = [_x]; _3 = _1 + _2; _arr pushBack _3; What are you trying to do here? That's just _arr pushBack [name _x, _x] Your mess of code up there is essentially just _selectedTarget = (allPlayers select {((name _x) find _selectedTargetName) != -1}) select 0; Filter out all players whose name matches, and then take the first of that list. Done. Though that is still inefficient, a more efficient variant would be private _players = allPlayers; private _index = _players findIf {((name _x) find _selectedTargetName) != -1}; _selectedTarget = _players param [_index, objNull]; And that would also gracefully handle the case where a player with such name is not found, instead of returning nil 3 Share this post Link to post Share on other sites