Jump to content
Sign in to follow this  
MrZig

Naming a unit ingame?

Recommended Posts

Hi, my friend and I want to name a unit "in-game".

But he is createunit'd, but doesn't have a name.

And I don't want to name him right when he get's created, I want to call a script to name him when I want to.

Is that physicly possible? Thanks!

Share this post


Link to post
Share on other sites

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_unittype createUnit [_pos, _group, "unitname = this", _skill, _rank]

That will give the unit a name, you can also add a unit name with something like:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

unitname = (units groupname) select 0

Though that will only work if there is only 1 unit in the group, if you are creating lots of units you will just need to select the next entry in the units array.

RED

Share this post


Link to post
Share on other sites

I'm not much good with arrays and that stuff, could you give me an example?

Thanks, much, MUCH appreciated.

Share this post


Link to post
Share on other sites

Say you had this script making units:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_unittype = "soldierWB"

_pos = getpos manspawn

_group = enemygroup

_unittype createUnit [_pos, _group]

[_group] exec "unitnamer.sqs"

unitnamer.sqs:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_group = _this select 0

_numingroup = count units _group

_select = _numingroup - 1

_unit = (units group) select _select

The added unit will always be the last one in the group AFAIK.

RED

Share this post


Link to post
Share on other sites

Hi, well, I dunno if it'll work cause every unit built will be in my squad, and I wanna name every unit in my squad.

What I'm doing is modding RTS3 so I can name the units made by the barrecks so I can switch between 2 groups, via a different script I made.

Will this work with units in your squad and a whole bunch?

And how would I go by incorporating it into RTS 3?

Share this post


Link to post
Share on other sites

Well you don't need to know the names of the units in both group. I am not sure how you want the script to work though, do you want the player to become the leader of the next group, and the leader of the other group to become the leader of the players group? If so then you could do something like:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

; Example script by RED, execute with:

; [nameofplayersgroup, nameofAIgroup] exec "groupswitch.sqs"

_playergroup = _this select 0

_aigroup = _this select 1

; - Gets list of units in players group

_unitsplayergroup = units _playergroup - [leader _playergroup]

_leaderplayergroup = leader _playergroup

; - Gets list of units in AI group

_unitsaigroup = units _aigroup - [leader _aigroup]

_leaderaigroup = leader _aigroup

; - Switches leaders pos

_playerleaderpos = getpos _leaderplayergroup

_aileaderpos = getpos _leaderaigroup

_leaderplayergroup setpos _aileaderpos

_leaderaigroup setpos _playerleaderpos

; - Makes leaders exit group

[_leaderplayergroup] join grpnull

[_leaderaigroup] join grpnull

; - Switches groups

[_leaderplayergroup] join _aigroup

[_leaderaigroup] join _playergroup

; - Gets units to join groups

_unitsplayergroup join grpnull

_unitsaigroup join _playergroup

_unitsplayergroup join _playergroup

_unitsaigroup join _aigroup

Is that what you were looking for?

RED

Share this post


Link to post
Share on other sites

Great thanks! It looks like it will work perfectly biggrin_o.gif

Share this post


Link to post
Share on other sites

Can you test it with rts? I don't have time right now... Thanks if you will..

Share this post


Link to post
Share on other sites

Maybe tomorrow MrZig, I am busy with the ECP at the moment.

RED

Share this post


Link to post
Share on other sites

ECP?

Oh, and if you do tomorow, then thanks!

Share this post


Link to post
Share on other sites

I have only done a bit of testing but it does seem to work, you will have to do some MP testing though.

RED

Share this post


Link to post
Share on other sites

Oh, now that I take a close look at it, I don't think it'll work.

It needs a name of the ai leader, yet I can't have that.

Ok, maybe I don't need to name em, just, this is exactly what I want to do.

In RTS3 1.0, you start alone and make buildings, ok?

You can have a max squad of 12, like normal.

So, what I want is to have 2 squads of 12.

So, at the beginning of rts, you make a barrecks say, and you make a full squad, 12 men.

Then, you load a script that tells em all to go to grpnull.

Then, you have no squad, so you build another one.

So now you have 24 soldiers, but 12 at your command, so you tell the soldiers to go to town A and then wait for em to get there and then load a different script that tells em all to go to grpnull and then the soldiers you had before to join you, and you tell them to go to town B

Is that, physicly possible?

Share this post


Link to post
Share on other sites

You do have the name of the AI leaders:

GroupW1, GroupW2, GroupW3 etc etc

GroupE1, GroupE2, GroupE3 etc etc

Ask Kar about this (just PM him), he knows way more about MP editing than me.

RED

Share this post


Link to post
Share on other sites

Yes I know I have the name of those, but I don't want to give them my other group.

I just want my group to go to grpnull.

Share this post


Link to post
Share on other sites

Ok then, setup a trigger with this as it condition field: (count units groupname) > 1

Onactivation: [groupname] exec "leavg.sqs"

leaveg.sqs:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_group = _this select 0

(units _group - [leader _group]) join grpnull

RED

Share this post


Link to post
Share on other sites

That script will create 11 new groups (one for each unit).

Remember that there is a 64 group limit that can be used up real fast.

Might I suggest just having the player commander join grpNull? and leave the rest in that original group. Whenever a unit joins grpNull it simply looks for an available group name in the preset 64 and plops them into that slot. If you do that for each unit, you are making that many new groups. If there isn't an available slot it simply won't un-join them.

If you do the above, everytime you make a squad it'll have your group name.

Capture the group name at squad creation, load it into an array. Then have the player join grpNull. That group will still exist and you'll have a new name to get your next squad into.

You might even have a dialog that holds a list of all the groups and you can join any one as you wish.

Share this post


Link to post
Share on other sites

What your saying is make 12 guys, then load a script that tells me to join grpnull, then make 12 more guys?

Ok, so when I jooined grpnull, they would keep my old group name right? What about the new ones?

Can you give me an example? Thanks.

Share this post


Link to post
Share on other sites

Cause I'd constantly wanna switch between them.

Share this post


Link to post
Share on other sites

I think I see what you want to do.

OK, first of all you create your original group of 11 AI soldiers for your group.  You don't need to assign them a name or anything individually, since they are in your group, then you can easily pick them up with a script.

Now, in order to make them leave your group and enter another group that you can pick up control of later, do something like this:

Your group name is something like W1Group or WGroup1 (I can't remember off the top of my head what I named them)

What you need to do is use the group as an array by using the Units command like this:

Quote[/b] ]Units Wgroup1

Then your group would look something like so as an array:

Quote[/b] ]

[leader,sld1,sld2,sld3,sld4,etc.]

   0      1     2     3    4   5

You would be

Quote[/b] ]Units WGroup1 Select 0

What you want to have happen is for all the other units in your group to join another group.  There's a couple of ways to do this.  You can either leave the group yourself, and then rename the Global Variable name of their group, and reassign your groupname back to WGroup1, or you can drop them all to GrpNull, and then have them join the group of one of the soldiers, and then assign a GlobalVariable name to it.

I think it's easier to drop yourself from the group so you don't have to create a looped script for that part.  So, something like this might work, and remember, this is running on the local client so you can use the Player command for this.  You can get more specific by using Units WGroup1 as well.

Quote[/b] ]

;;(this is you, or use Player)

_oldLeader = Units Wgroup1 Select 0

;;2nd soldier in your group

_newLeader = Units Wgroup1 Select 1

;;You exit group

[(Units Wgroup1 Select 0)] JOIN GrpNull

;;assign new global variable name to new group

WGroup1Alpha = Group _newLeader

;;reassign your global var name for your group

WGroup1 = Group _oldLeader

;;Public Var the names for Multiplayer (may not be necessary)

PublicVariable "WGroup1Alpha"

PublicVariable "Wgroup1"

OK, so this simply creates a new group using the units in your current group, and leaves you alone in your group.  Now, let's say that you want to be able to do this up to 4 times, so you can have 4 different groups.  First of all, if this is only available to commanders (as it should be) then I'd recommend you name the groups something like WGroup1Alpha, WGroup1Bravo, WGroup1Charlie, WGroup1Dog, or you can make it shorter like WG1A, WG1B, etc.  The East one would of course be EGroup1Alpha, etc.

Now things can get complicated from here, and without testing, I'm just going to show you it in a more simple light.  Also remember, I'm just going from the top of my head, so this stuff probably needs some debugging for sure.

Quote[/b] ]

_oldLeader = Units Wgroup1 Select 0

_newLeader = Units Wgroup1 Select 1

[(Units Wgroup1 Select 0)] JOIN GrpNull

;;this checks to see which groups are empty and if empty assigns the units to it.

?(Count Units WGroup1Alpha) <= 0 : WGroup1Alpha = Group _newLeader; Goto "Next"

?(Count Units WGroup1Bravo) <= 0 : WGroup1Bravo = Group _newLeader; Goto "Next"

?(Count Units WGroup1Charlie) <= 0 : WGroup1Charlie = Group _newLeader; Goto "Next"

?(Count Units WGroup1Dog) <= 0 : WGroup1Dog = Group _newLeader; Goto "Next"

#Next

WGroup1 = Group _oldLeader

PublicVariable "WGroup1Alpha"

PublicVariable "WGroup1Bravo"

PublicVariable "WGroup1Charlie"

PublicVariable "WGroup1Dog"

PublicVariable "Wgroup1"

Now we've gotten it so you can dump your units into other groups.  You can refine this even more by using dialogs.  You can have a dialog that would pull up your group and the other 4 groups in lists.  Then you could click on a soldier and move him to any of the other groups until you had your lists exactly the way you wanted them.  If a soldier in a group died, you could train another at the barracks, open the dialog and assign him to the group that needed a person.  That's a bit too much to go into for this, but there's a lot of possibilites.  Multiplayer does make things more complicated, but moving to groups should work ok on a local basis.

Anyway, to be able to pick up the units in a group and have them rejoin yours would require a slight reversal of the above script, except you'd simply do this:

Quote[/b] ]

[units WGroup1Alpha] JOIN Group Player

OR

[units WGroup1Alpha] JOIN WGroup1

Remember, that you cannot have more than 12 units in your group so you might have to shed current members of your group if the addition of the troops from another group would make you go over that limit.  I think that in OFP if you tried adding 8 units to your group of 6, then the extra units would either stay in their old group, or just get dropped into GrpNull.  I'm not sure which.

Well, I hope this makes some sort of sense.  Really it just takes a lot of testing and debugging to make it work properly, and most of that you'll have to do on your own, unfortunately.  I am intrigued with the dialogs approach to group swapping, so I might mess with something like that for future versions.  ATM I don't have enough time to add new complicated features.

BTW, weren't you on the server last night?

Share this post


Link to post
Share on other sites

Yes I was smile_o.gif

I don't understand much of that, but Korax, my friend, probably does.

I'll give him this link and see what he can do smile_o.gif

Share this post


Link to post
Share on other sites

Actually, alot of that code is redundant.

For example, why get the "new" leaders name when you can call it anytime using the: leader <group> command? and why publicVariable?

all units in a players group are ALWAYS local, so in MP it doesn't matter.

four words: KISS biggrin_o.gif

Do this:

create a trigger that covers whole map

set it to WEST IS PRESENT and REPEATEDLY

name it "unitsWEST"

make a script and call it "groupList.sqf":

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">private ["_units","_numunits","_counter","_curunit","_grouparray"]

_units=list unitsWest;

_numunits = count list unitsWest;

_counter = 0;

_groupArray = [];

while {_counter < _numunits}

do

{

 _curUnit = _units select _counter;

 if !((group _curUnit) in _groupArray) then

 {

    _groupArray set [count _groupArray,(group _curUnit)]

 };

_counter = _counter +1;

}

NOTE: you can simplify this further by using a foreach command instead of while..do, but this is a "snippet" of the code I use. Mine is a bit different, but this gives you the idea of it all. Also, you can use one (Anybody) trigger and sort out the groups in this code instead. That way you can pass a side as parameter.

now in your init.sqs put:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">groupList = preprocessfile "grouplist.sqf"

this has nothing to do with joining, but will get you ALL groups in the map area that are on your side.

all you need to do is write something like

WestGroups = call groupList

and WestGroups will become an array of groups on the West Side

assuming you are using dialogs, create a listbox and add each element of the group array to the listbox.

then, a couple of buttons..

Button1 "leave group": player join grpNull

Button2 "have group join me": {_x join player} foreach units <group from listbox>

if you can make a listbox of the units in each group you can go further with the commands.

Keep in mind... there is no need to publicvariable anything. OFP can handle the networking of the groups.

One note though: do NOT leave a group when you are the driver of a vehicle... you will never get them out of it.

I have my own dialog that manages groups for SOW2. <due out soon> take a peek.. it uses the above code.

Group Management Screen

Share this post


Link to post
Share on other sites

All units in a players group are local, but when you leave a group in MP, it is no longer local, thus, you need that group's name if you wish to make use of it later. You COULD use the nearestObject command if you want to walk up to any group and take control of it, but that's not what he's after.

Also note, that this limits the number of groups you can do this with intentionally. Otherwise, you might have a commander who creates a ton of groups and leaves them all over the place which would lead to a lot of lag in MP.

My example is quite specific to what he's trying to do. Yours merely grabs all groups for his side which would be more than he needs. If you're playing with 5 other Players, why would you want to spend the cpu cycles grabbing all of their AI group members as well? That's like throwing all of the hay in one stack and then resorting it, when you already have the specific units you're manipulating in a subset.

KISS - just use the single group local to the commander, break it up, give it a Global Var you can use later to grab it again, and presto, you're done.

The PublicVar is in case there's some server-side scripts running so it's not entirely necessary, but from the hours of experience I've had with MP scripting, you never know. OFP is funny that way.

Share this post


Link to post
Share on other sites

True, but if you want to interchange groups, you need to grab all groups. If that's not the goal, then you are right - you can save them into a variable. I thought that was what you were trying to get at with publicvariable, though.

Saving them into a series of publicVariables(global vars) is still much more tasking and prone to network error. You are better off creating a group array instead then:

myGroupsArray = []

and add/delete the actual groups to the array as needed. You wouldn't even need to broadcast it because if you want player specific groups, myGroupsArray would be different on each machine. It is much stronger too. Thus, any scripts or such running against a group will not be hindered. You can then iterate through the array and list them in a comboBox.

So I guess as you hit a button or action to remove yourself from a group you would run this:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

myGroupsArray = myGroupsArray + [group player]

player join grpNull

then when you want them back, get the index number of the group (comboBox or other) and use:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

{_x join group player} forEach units (myGroupsArray select <index>)

myGroupsArray = myGroupsArray - [myGroupsArray select <index>]

I am sorry if I came across strongly, but I was just suggesting that getting the leader and using multiple variables is probably a little overkill.

wink_o.gif

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  

×