Jump to content

Recommended Posts

i want to load all players names to my rsclistbox then click on a player and select it and by pressing the button just hint the selected players name. 

My next step is to teleport the target to me.

Trying to learn for a small admin panel.

why does this not work?

heres what i got:

 

_display = findDisplay 46 createDisplay "RscDisplayEmpty";

 

_playerlist = _display ctrlCreate ["RscListbox", 1500];

_playerlist ctrlSetPosition [-0.3,0.02,0.48793,0.744756];

_playerlist ctrlCommit 0.26;

_playerlist ctrlSetFontHeight 0.028;

_playerlist ctrlsetFont "PuristaLight";

_playerlist ctrlSetTextColor [1,1,1,1];

 

lbClear _playerlist;

{

_index = lbAdd [ 1500, name _x ];

lbSetData [ 1500, _index, name _x ];

} forEach playableUnits;


 

button = _display ctrlCreate ["RscButton", -1];

button ctrlSetPosition [0.625,0.2,0.423497,0.276817];

button ctrlsetFont "PuristaLight";

button ctrlSetText "hint selected!";

button ctrlSetFontHeight 0.03;

button ctrlCommit 0.26;

 

button buttonSetAction "

_data = lbData [ 1500, ( lbCurSel 1500 ) ];

HINT FORMAT ['%1',_data];

";

Share this post


Link to post
Share on other sites

What does not work, is there no hint when you click the button?

 

do you have error reporting on?

 

  • Like 1

Share this post


Link to post
Share on other sites

Doesnt list any player and because of that the button doesnt show an hint

Share this post


Link to post
Share on other sites

Instead of

_index = lbAdd [ 1500, name _x ];

Try this to make sure it's not the id that's causing problem:

_playerlist lbAdd (name _x);

I always use allPlayers instead of playableUnits. But not sure which one is better. You might want to try that too

  • Like 1

Share this post


Link to post
Share on other sites
Just now, gc8 said:

Instead of


_index = lbAdd [ 1500, name _x ];

Try this to make sure it's not the id that's causing problem:


_playerlist lbAdd (name _x);

I always use allPlayers instead of playableUnits. But not sure which one is better. You might want to try that

lol thank you it works it lists all players but how can i output the selected index or item? it doesnt show any hint right now

Share this post


Link to post
Share on other sites

Not sure what's up with that but maybe the new lines in quote are causing error...

 

  • Like 1

Share this post


Link to post
Share on other sites

maybe with lbSetData [ 1500, _index, (name _x) ];
also check that your button works properly with a simple hint before.

  • Like 1

Share this post


Link to post
Share on other sites
38 minutes ago, Mr H. said:

maybe with lbSetData [ 1500, _index, (name _x) ];
also check that your button works properly with a simple hint before.

so i have at least this and still it doesnt work :/

 

_display = findDisplay 46 createDisplay "RscDisplayEmpty";

 

_playerlist = _display ctrlCreate ["RscListbox", 2000];

_playerlist ctrlSetPosition [-0.3,0.02,0.48793,0.744756];

_playerlist ctrlCommit 0.26;

_playerlist ctrlSetFontHeight 0.028;

_playerlist ctrlsetFont "PuristaLight";

_playerlist ctrlSetTextColor [1,1,1,1];

_playerlist ctrlAddEventHandler

lbClear _playerlist;

{

_playerlist lbAdd (name _x);

} forEach allPlayers;


 

button = _display ctrlCreate ["RscButton", -1];

button ctrlSetPosition [0.625,0.2,0.423497,0.276817];

button ctrlsetFont "PuristaLight";

button ctrlSetText "hint selected!";

button ctrlSetFontHeight 0.03;

button ctrlCommit 0.26;

 

button buttonSetAction "

_data = lbData [ 2000, ( lbCurSel 2000 ) ];

HINT FORMAT ['%1',_data];

";

Share this post


Link to post
Share on other sites

with the latest code you posted it can't work, since you do not set the data
also, stupid question but: do you test it in MP? It won't work if you try in SP

EDIT: also if you're planning on doing something more elaborate further down the line you should maybe create a dialog with the UI editor and not create all your controls by script, it will save you a lot of trouble.

  • Like 1

Share this post


Link to post
Share on other sites
On 23.6.2018 at 7:36 PM, gc8 said:

I always use allPlayers instead of playableUnits. But not sure which one is better.

allPlayers will work in SP too but only list all active players (connected). playableUnits returns all units that might be controlled by a player and includes ai units, doesn't work in SP.

On 23.6.2018 at 7:30 PM, Armanda551 said:

Doesnt list any player and because of that the button doesnt show an hint

The first syntax is not very reliable. Try to always use the alt syntax where you define the control beforehand.

On 23.6.2018 at 10:20 PM, Mr H. said:

EDIT: also if you're planning on doing something more elaborate further down the line you should maybe create a dialog with the UI editor and not create all your controls by script, it will save you a lot of trouble.

^agreed. Though this will require some better understanding of the descritption.ext. There are enough tutorials out there to take a look at (KK's tutorial, perspective of another newbie, Iceman's tutorial*) . If you need further help you can also ask me.

*this is where I started off from

 

Here is my (working) code:

description.ext

class TER_RscTestDialog
{
   idd = 73000;// only important for this number
};

script.sqf:

createDialog "TER_RscTestDialog";
_display = findDisplay 73000;// unique idd
_playerList = _display ctrlCreate ["RscListbox",1500];
_playerList ctrlSetPosition [-0.3,0.02,0.48793,0.744756]; // viable only for your screen. Try to use safeZone, GUI_GRID and/or pixelGrid variables instead
_playerList ctrlCommit 0;// no need for the short delay as the controls will start wherever their base defines are set
{
	_playerList lbAdd name _x;// no need to set the data. can also be returned with lbText (see below)
} forEach allPlayers;

_button = _display ctrlCreate ["RscButtonMenu",-1];
_button ctrlSetPosition [0.625,0.2,0.423497,0.276817]; // see above
_button	ctrlCommit 0;
_button ctrlSetText "Name of player";
_button ctrlAddEventHandler ["ButtonClick",{ // eh is better since setButtonAction uses .sqs and not .sqf syntax
	params ["_button"];
	_playerList = (findDisplay 73000) displayCtrl 1500;
	_curName = _playerList lbText (lbCurSel _playerList); // better syntax, other one is not reliable
	hint _curName;
}];

 

PS: and some advice as you are new to the whole ui editing: it can get really frustrating but the possibilities are incredible and there is no better feeling than getting it to work :f:

  • Like 1

Share this post


Link to post
Share on other sites
On 6/24/2018 at 1:45 AM, 7erra said:

script.sqf:


createDialog "TER_RscTestDialog";
_display = findDisplay 73000;// unique idd
_playerList = _display ctrlCreate ["RscListbox",1500];
_playerList ctrlSetPosition [-0.3,0.02,0.48793,0.744756]; // viable only for your screen. Try to use safeZone, GUI_GRID and/or pixelGrid variables instead
_playerList ctrlCommit 0;// no need for the short delay as the controls will start wherever their base defines are set
{
	_playerList lbAdd name _x;// no need to set the data. can also be returned with lbText (see below)
} forEach allPlayers;

_button = _display ctrlCreate ["RscButtonMenu",-1];
_button ctrlSetPosition [0.625,0.2,0.423497,0.276817]; // see above
_button	ctrlCommit 0;
_button ctrlSetText "Name of player";
_button ctrlAddEventHandler ["ButtonClick",{ // eh is better since setButtonAction uses .sqs and not .sqf syntax
	params ["_button"];
	_playerList = (findDisplay 73000) displayCtrl 1500;
	_curName = _playerList lbText (lbCurSel _playerList); // better syntax, other one is not reliable
	hint _curName;
}];

PS: and some advice as you are new to the whole ui editing: it can get really frustrating but the possibilities are incredible and there is no better feeling than getting it to work :f:

 

Hi, I'm trying to use this script to create a teleport script, merging one of my working script written to teleport me on map. So, you click on the list shown by this script and use the player _curName to set his position on mine.

So

_curName setPos (getpos player);

 

😐 it doesn't work. 

I have a doubt about the use of the _curName var in this script. It seems that it "contains" the string of the selected player and NOT the "player" himself. Is it true?

Infact in the "" hint _curName; "" you pass a string, otherwise, if player, it should be "" hint name _curName; "" (or something like that).

So the question is,  is there a way to "identify" the player that has that name? Something like 

(<player having _curName>) setPos (getpos player);

 

Thanks in advance

Share this post


Link to post
Share on other sites
5 hours ago, Enigx said:

It seems that it "contains" the string of the selected player and NOT the "player" himself. Is it true?

Yes.

 

5 hours ago, Enigx said:

So the question is,  is there a way to "identify" the player that has that name? 

Just store a reference to the objects vehicleVarName( create one if non existent ) in the listbox data

 

//snip

{
	_index = _playerList lbAdd name _x;
	_playerList lbSetData[ _index, _x call BIS_fnc_objectVar ]; //Give _x a unique vehicleVarName and store in LB data
}forEach allPlayers;

//snip

_button ctrlAddEventHandler[ "ButtonClick",{
	params[ "_button" ];
	
	_playerList = ctrlParent _button displayCtrl 1500;
	_currentSelectedIndex = lbCurSel _playerList;
	
	_curName = _playerList lbText _currentSelectedIndex;
	hint _curName;
	
	_objectName = _playerList lbData _currentSelectedIndex;
	_object = missionNamespace getVariable _objectName;
	_object setPosATL getPosATL player; //Teleport selected to users( player ) position
}];

 

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

×