Home   Help Search Login Register  

Author Topic: Dialog to control units  (Read 4014 times)

0 Members and 1 Guest are viewing this topic.

Offline MI_Fred

  • Members
  • *
  • AA
    • OFP Team Finlanders
Dialog to control units
« on: 31 May 2003, 13:35:51 »
According to the comref the lbSetData command stores a string, but what I need is it to store an object, or so to speak. When I try to use any command to control the stored unit, it complains it's a string not an object I'm referring to. Here's how I set it up:

Quote
_listunit = lbAdd [13962,(name(units _unit select _u))]
lbSetData [13962,_listunit,units _unit select _u]
I increment _u so it takes all units of the group to the listbox and the visible text is the units name. Here's how I dig it up:
Quote
_u = 0
_max = (lbsize 13963) - 1
#equiploop
_name = lbText[13963,_u]
_unit = lbData[13963,_u]
removeAllWeapons _unit
_u = _u + 1
? (_u <= _max) : goto "equiploop"

lbClear 13963
exit

So is there a way to control the above _unit? Don't worry about the differing id, I use 1 listbox to gather all units within 50 meters of the leader who uses it, and another where to he can drop the ones he wants to be affected...
There's gooks over there, there's mines over there, and watch out those goddamn monkeys talk, I'll bite ya.

Offline Sui

  • Former Staff
  • ****
    • OFPEC
Re:Dialog to control units
« Reply #1 on: 01 Jun 2003, 04:29:22 »
To change a string to an object, try:

format ["",+string ]

So inserting that into your script, should look something like this:

Code: [Select]
...
#equiploop
_name = lbText[13963,_u]
_unit = format [""+(lbData[13963,_u])]
removeAllWeapons _unit
_u = _u + 1
...

I dunno... looks a bit dodgey :P

Try it and see if it works...

Offline MI_Fred

  • Members
  • *
  • AA
    • OFP Team Finlanders
Re:Dialog to control units
« Reply #2 on: 01 Jun 2003, 13:51:17 »
You know what... Na a  ...Sigh,

What's the difference between
_unit = format [""+(lbData[13963,_u])]
and
_unit = format ["%1"+(lbData[13963,_u])] ?

Though, neither worked. Still a string. I am totally confident someone has handled units via listboxes before, there aren't that many other choises... But how exactly I don't know.

Here's a preview. You'll have to be clever to figure out what it's ment for  ;D

O and if anyone knows the paths to the icons you see there on the right, the unit type icons, if there are any whole ones, spill it out or I'll club ya  ;D Also the paths to the sidearms are a mystery to me.
Plz  ::)
« Last Edit: 01 Jun 2003, 16:32:58 by MI_Fred »
There's gooks over there, there's mines over there, and watch out those goddamn monkeys talk, I'll bite ya.

Offline Sui

  • Former Staff
  • ****
    • OFPEC
Re:Dialog to control units
« Reply #3 on: 02 Jun 2003, 02:19:05 »
Hmm.... just my dodgey syntax most like... try:

_unit = call format [""+(lbData[13963,_u])]

That should work, according to a quick test run I did, but that wasn't using a dialog...

What's the difference between
_unit = format [""+(lbData[13963,_u])]
and
_unit = format ["%1"+(lbData[13963,_u])] ?

Umm... in the second one you're pointing the format command to a variable that doesn't exist? The %1 would normally be replaced by the variable after the comma, however if you look closely at that line you'll notice there's no comma at all ;)

The "" + XXX merely adds XXX into the empty string "".

Anyway, hope it works for you this time ;)

Offline MI_Fred

  • Members
  • *
  • AA
    • OFP Team Finlanders
Re:Dialog to control units
« Reply #4 on: 02 Jun 2003, 15:32:28 »
We're definitely closing in on the prob, no error this time but no results either  :) Now _unit is a scalar bool array thingy, is that undefined? I can get the text of that listboxs current selection (_u), but still the data seems to be under the rock.

Yeah didn't see that comma heh. Didn't know about that command which fills empty space with something, but filling it in this case with that lbdata, which is invisible, isn't quite working. I could ofcourse take the easy way and take the unit from the trigger which inits the dialog, but that wouldn't be so elegant  ;)
There's gooks over there, there's mines over there, and watch out those goddamn monkeys talk, I'll bite ya.

Offline MI_Fred

  • Members
  • *
  • AA
    • OFP Team Finlanders
Re:Dialog to control units
« Reply #5 on: 02 Jun 2003, 16:51:55 »
Tested feeding the listbox with data as follows:
Quote
_info = format ["%1:%2 (%3 / %4)",_u+1,(name(units _unit select _u)),(primaryWeapon(units _unit select _u)),(secondaryWeapon(units _unit select _u))]
_uniti = format ["%1",(units _unit select _u)]
_listunit = lbAdd [13962,_info]
lbSetData [13962,_listunit,_uniti]

So now the data is visible and it is a string. Now it shows up as WEST alpha black:1 and such with the command _unit = lbData[13963,_u]. There is no way to feed anything else than a string into a listbox entry, that I am pretty confident of.
It needs to be converted (in the script that processes it) into something usable for object commands as it now produces an error after reading the first word of the string.
How? :D
« Last Edit: 02 Jun 2003, 17:38:45 by MI_Fred »
There's gooks over there, there's mines over there, and watch out those goddamn monkeys talk, I'll bite ya.

Offline Sui

  • Former Staff
  • ****
    • OFPEC
Re:Dialog to control units
« Reply #6 on: 04 Jun 2003, 01:36:49 »
Hmm...

I'm afraid not even my snippets file can tell me how to convert an object into a string...

I'm sure it's possible, but I'm afraid I don't know how it's done... (yet! ;)).

Hopefully someone out there knows and can enlighten us...

Offline CrashDome

  • Members
  • *
Re:Dialog to control units
« Reply #7 on: 06 Jun 2003, 08:08:54 »
I've done it....
You are going about it all wrong actually....there are many ways but here is one

Here's what you need to do:
1. save the objects into an array such as: TEMPARRAY=[object1,object2,etc....]
2. place the integer value of its position in the array into the lbsetdata
i.e. if your array was [object1,object2,object3] then you would
lbsetdata[12345,0,"0"]
lbsetdata[12345,1,"1"]
lbsetdata[12345,2,"2"]

3. to retrieve selected unit use the data in a CALL statement
for example if I had highlighted the third object in the list then:
Code: [Select]
SELECTION= lbData [12345,lbCurSel 12345]
call format["RETRIEVEDOBJECT=TEMPARRAY select %1",selection]
what this does then is retrieve the "2" and assign it to variable SELECTION then rewrites a statement as:
RETRIEVEDOBJECT=TEMPARRAY select 2
and then executes it and assigns object3 to variable RETRIEVEDOBJECT


edit: btw... I am pretty sure you cannot convert an object into a string, and then turn the string back into an object. I wouldn't bet my life on it, but I would bet yours ;)
« Last Edit: 06 Jun 2003, 08:12:53 by CrashDome »

Offline MI_Fred

  • Members
  • *
  • AA
    • OFP Team Finlanders
Re:Dialog to control units
« Reply #8 on: 06 Jun 2003, 16:52:17 »
Ok, that works, with the exception of lbData containing a string ofcourse and lbValue would suit this situation better, maybe it's ment for it, as you can't select a string from an array. Call would convert it ofcourse but why bother  ;D

But thanks now it works  ;)

I still would need info on the pics, the .paa's of sidearms and if there are any images of the units u see at the bottom as whole, I can only find parts like you see in the attachement above...

There's gooks over there, there's mines over there, and watch out those goddamn monkeys talk, I'll bite ya.

Offline CrashDome

  • Members
  • *
Re:Dialog to control units
« Reply #9 on: 06 Jun 2003, 23:43:31 »
You know... I missed lbSetValue completely. ::)]

You are absolutely right. Use lbSetValue and eliminate redundant code.

Sorry, don't know the paa's :-[

Offline MI_Fred

  • Members
  • *
  • AA
    • OFP Team Finlanders
Re:Dialog to control units
« Reply #10 on: 07 Jun 2003, 22:30:15 »
Here's a hard one. I'm trying to categorize or just sort the weapons and magazines of a unit for the "database" I've constructed for the weapon dialog. Whenever a unit takes weapons from it his current weapons are stored. I'm using rather complex syntax to retreive them and am getting tangled on nesting multiple while...do and if...then...else structures, just to make it fast,flexible and reliable. This is what I've come up reduced to the structure:


while "a <= b" do
{
if () then {while "" do {}} else { if () then {}}
a = a + 1
}


I can't paste the whole thing here, as it has way too many characters for a post heh. There's 4 of those if structures in that while structure.  The question is, is that possible? Nesting so many. And are multiple while conditions possible?

Atm I'm getting an invalid number in expression error, due to either the spacing, the nested structure or the multiple while conditions, but which could it be?
There's gooks over there, there's mines over there, and watch out those goddamn monkeys talk, I'll bite ya.

vektorboson

  • Guest
Re:Dialog to control units
« Reply #11 on: 08 Jun 2003, 16:25:54 »
@MI_Fred

nested if and while statements are possible in OFP, but:

while the uppermost if or while statement may expand over several lines, nested if's and while's have to remain in one single line. As I see, they all seem to be in one single line. Perhaps you should check, if you end all statements with a semicolon (even those which end with a closing bracket "}".

I've had a similar problem, best is to outsource them into either variables or sqf-files.

Offline MI_Fred

  • Members
  • *
  • AA
    • OFP Team Finlanders
Re:Dialog to control units
« Reply #12 on: 08 Jun 2003, 19:11:30 »
Alright, I should be able to do that, but before I try, I think you'd be able to see from the actual code if it is correctly semicoloned  :)

Quote
if ("_x == _weps select _uwc" count MIF_WQprimaries > 0) then
{
_pri = 0;
_prmax = (count MIF_WQprimaries) - 1;
   while "(_pri <= _prmax) && ((_weps select _uwc) != (MIF_WQprimaries select _pri))" do
   {
   _pri = _pri + 1;
   };
_newPrimStock = (MIF_WQprimstock select _pri);
_newPrimStock = _newPrimStock + 1;
MIF_WQprimstock set [(MIF_WQprimstock select _pri),_newPrimStock];
}
else
{
   if ((_weps select _uwc) == (primaryWeapon _curunit)) then
   {
   MIF_WQprimstock = MIF_WQprimstock + [1];
   MIF_WQprimaries = MIF_WQprimaries + [(_weps select _uwc)];
   MIF_WQprimicons = MIF_WQprimicons + [""];
   _newWep = lbAdd [13968,(MIF_WQprimaries select (_weps select _uwc))];
   lbSetData [13968,_newWep,(MIF_WQprimaries select (_weps select _uwc))];
   };
};
That's the spaced out version of one of the if structures inside the topmost while structure. After I make a sqf out of each of the above, I think I can then just put the call to each of them on a separate line followed by a semicolon. Am I right?

And I wanted to know if the while condition I've put in red is possible, as it has 2 conditions. Somewhere I red that 2 aint possible or then that was some fairy whispering into my ear...  ;D
« Last Edit: 08 Jun 2003, 19:16:37 by MI_Fred »
There's gooks over there, there's mines over there, and watch out those goddamn monkeys talk, I'll bite ya.

Offline MI_Fred

  • Members
  • *
  • AA
    • OFP Team Finlanders
Re:Dialog to control units
« Reply #13 on: 09 Jun 2003, 02:26:55 »
Yesh, okey, I found out that in an sqs file you must write everything in 1 row. In an sqf you can space it to multiple rows, as follows. And now the errors are gone. Now I've still got this prob with the double while condition, I'd like a sexier approach to it really  :D and to a few other things some answers. Ok *cough* if I may, (again):
Quote
if ("_x == _curWeapon" count _stock > 0) then
{
_pri = 0;
_prmax = (count _stock) - 1;
while "(_pri <= _prmax) && (_curWeapon != (_stock select _pri))" do {_pri = _pri + 1;};
_newPrimStock = (_stockno select _pri);
_newPrimStock = _newPrimStock + 1;
_stockno set [(_stockno select _pri),_newPrimStock];
}
else add new lb entry and so on...look at 3rd q
What that does is if there is a matching weapon in the database, the red while structure will seek it and place the array pointer to it. Is there a better way to define _newPrimStock?

Secondly, it seems not to work. The number is not incremented. The array set command was new to me just a while back so ...

Thirdly, does _stockno = _stockno + [1]; add a new element to an array and set it to 1 automaticly? That is a number I need to add there, that is needed when a new weapon is put into stock.

[EDIT] Ah hell, why bother, I found out both. array set [index,value] pffft. And I had to resize the array to get in a new value. So now I get everything nicely to the stock except magazines.

I can't tell wether a mag is a normal mag or a sidearm mag as I have them in different lb's. It leads to a plethora of problems... any genius for this one? This is where my brain starts to hurt  :-X [/EDIT]
« Last Edit: 11 Jun 2003, 03:39:46 by MI_Fred »
There's gooks over there, there's mines over there, and watch out those goddamn monkeys talk, I'll bite ya.

Offline benreeper

  • Members
  • *
  • I'm a llama!
Re:Dialog to control units
« Reply #14 on: 16 Jun 2003, 06:04:44 »
What I did was have the label hold an index to a known array of objects.

Ben

Offline MI_Fred

  • Members
  • *
  • AA
    • OFP Team Finlanders
Re:Dialog to control units
« Reply #15 on: 17 Jun 2003, 00:55:05 »
Yeah, I'll have to ask users to input all sidearm magazine names (he intends to use in a mission) into an array for it to work correctly. Not quite user-friendly  :( It works and I got this kinda solved, but I got atleast 1 more interesting dilemma in need of solving.

I'd wan't to get an array of weapon and mags in the cargo space of a vehicle  ;D ummmm, I'm not at all sure miself tis is possible heh.
There's gooks over there, there's mines over there, and watch out those goddamn monkeys talk, I'll bite ya.

Offline MI_Fred

  • Members
  • *
  • AA
    • OFP Team Finlanders
Re:Dialog to control units
« Reply #16 on: 25 Jan 2004, 17:13:31 »
I got this kinda solved, but I got atleast 1 more interesting dilemma in need of solving.

After half a year nothing is that interesting, what a n00b ^  ;D

Ok I am at the same spot quite much, but I've made a significant amount of little improvements, and I'm ready to release this messy monster, which really isn't about controlling units but arming them without the radio menu. More than 1 guy and 1 clip at a time  :-X all at once is the name of the game! should come handy if your experiencing the "weapon-to-ammocrate = potentially-to-insane-amounts-multiplying-weaponholders-on-the-ground" bug.

But, since I wan't to include the option of creating the selected weapons on the ground, I've hit a dead end. How do you make weaponholders visible to those players which were not local when the dialog was created (the script doesn't exit for them, just that the dialog doesn't show on them)?
Code: [Select]
_caller = _this select 0
_unit = _this select 1
? (local _unit) : createDialog "equipDialog"
jadajadajadacode...

and the creation point of the processing script (which is launched from a button, does that make it global?):
Code: [Select]
_primstr = lbData [13968, lbCurSel 13968]
...
_mag1str = lbData [139617, lbCurSel 139617]
...
if ((_primstr != "NONE") && (MIF_WQprimstock select (lbCurSel 13968) > 0)) then {_primhold = "weaponholder" createVehicle getPos _curunit; _primhold setPos getPos _curunit; _primhold addWeaponCargo [format ["%1",_primstr],1];_newPrimStock = (MIF_WQprimstock select (lbCurSel 13968));_newPrimStock = _newPrimStock - 1;MIF_WQprimstock set [(lbCurSel 13968),_newPrimStock]}
...
if ((_mag1str != "NONE") || (_mag1amo != 0)) then {_mag1hold = "weaponholder" createVehicle getPos _curunit; _mag1hold setPos getPos _curunit; _mc = 0;while "(_mc < _mag1amo) && (MIF_WQmagastock select (lbCurSel 139617) > 0)" do {_mag1hold addMagazineCargo [format ["%1",_mag1str],1];_newMagStock = (MIF_WQmagastock select (lbCurSel 139617));_newMagStock = _newMagStock - 1;MIF_WQmagastock set [(lbCurSel 139617),_newMagStock];_mc = _mc + 1}}
...
_whis = [_mag1hold,_mag2hold,_mag3hold,_mag4hold,_primhold,_sechold,_thihold,_fouhold,_fifhold]
_whi = 0
while "(whi < (count _whis))" do {if(format [{%1},isnull (_whis select _whi)] != {true}) then {publicVariable (_whis select _whi)}; _whi = _whi + 1;};
So, there you have the _primstr which is from the dialogs listbox which selections contain strings as data. For example "HK".
Then the same with _mag1str, "HK" again.
Then if the _primstr is "HK" or anything it will create a weaponholder and stuff the "HK" in it.
Then the same with _mag1str.
Lastly, I do a PV command for each of the strings that are not null.

The problem is, the weapons and mags & equipment show up only on the client who used the dialog. I don't make them exit the script anywhere...

EDIT: ofcourse the dialog is launched via used action; ofcourse the other clients are thrown out. duh. sigh
« Last Edit: 26 Jan 2004, 01:24:48 by MI_Fred »
There's gooks over there, there's mines over there, and watch out those goddamn monkeys talk, I'll bite ya.

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re:Dialog to control units
« Reply #17 on: 26 Jan 2004, 04:04:01 »
Hi MI_Fred,

there you got one big multiplayer problem to deal with.

You can't publicVariable "strings" or arrays

In your case it's the strings, that won't become updated
by PV command.

You should try to use a technique, where you will be able
to PV numeric variables, and let the clients use these numerics
to select strings from global arrays.

Also the prob, that the script executes local only, because of
the custom action - you could make a boolean true, PV it, and
let everybody start another script upon this boolean.

~S~ CD
Dont argue with idiots....they will bring you down to their level and beat you there with experience.

How to use Waypoint type Scripted

Offline MI_Fred

  • Members
  • *
  • AA
    • OFP Team Finlanders
Re:Dialog to control units
« Reply #18 on: 26 Jan 2004, 13:02:59 »
Thx for the answer.

I guess I messed that post up, you didn't notice that I was trying to PV the weaponholders which are objects? Or wouldn't that work in any case? Atleast it doesn't like I have it now there...

Agh I don't wanna write yet another script to run for others at that point... a brilliant flash of an extra gadget to that dialog flashed in my brain last night and it's more important  ;D Oh well. All so new to me this PV stuff...

There's gooks over there, there's mines over there, and watch out those goddamn monkeys talk, I'll bite ya.