Jump to content
Sign in to follow this  
CptBBQ

Getting a clean string out of 'group _unit'

Recommended Posts

Hi there,

first of all, thanks for looking at this. I´m running against a wall with one of my scripts, and (again) I´m desperate for help...

I´ll try to keep it as short as possible...

So, lets say I have the groups alpha and bravo and I want to store their kills in arrays named alphaKills and bravoKills. When a killedEventHandler goes of, I need to know in which array to store the kill. The script will eventually have to handle a lot more group names so I don´t want to use 'if' or 'switch' statements.

I came up with this, because I already used a similar syntax using player names.

_groupKills = str(group (_killer)) + "Kills";  //_killer is the unit passed by the EH

call compile format ["%1 set [count %1, _victim]", _groupKills];

But it cannot work, because

hint format ["%1", group (_killer)];

returns e.g. "B Alpha" if _killer is in team alpha. So the array would be

called 'B AlphaKills' which is bad in many ways. I´ve got no idea where those "B"s come from, neither how to get rid of them. I´ve looked for methods to trim or edit characters in stings but haven´t found anything.

I think an answer to one of the following questions would solve my problem:

1. Can I somehow obtain the name of a group as given via 'createUnit' and 'groupName = group _unit' in form of a string? (I need the exact name without any added characters)

2. Is there a feasible method to change individual characters in strings?

3. This would be more of a last resort but could I somehow rename the initial arrays to e.g. 'B alphaKills' despite the whitespace?

4. How would you approach this problem if you wouldn´t want to 'switch' through several groupnames to access their respective arrays?

If you have any insights on this issue, please share.

Thanks in advance!

Cheers,

CptBBQ

Share this post


Link to post
Share on other sites

*bumb*

pleeease... there´s got to be a way to achieve this.

Share this post


Link to post
Share on other sites

Maybe save variables to the mission namespace and have a switch, if the kill comes from group alpha increase alphaKills by one, if it comes from bravo increase bravoKills by one? Look into setVariable and getVariable.

Share this post


Link to post
Share on other sites

group this setgroupid ["Alpha"];

_grp = toarray str group _killer;
_grp set [0,"DEL"];
_grp set [1,"DEL"];
_grp = _grp - ["DEL"];
_grp = tostring _grp;

I'm sure there must be a more elegant way to do it, but try that. :)

Share this post


Link to post
Share on other sites
group this setgroupid ["Alpha"];

_grp = toarray str group _killer;
_grp set [0,"DEL"];
_grp set [1,"DEL"];
_grp = _grp - ["DEL"];
_grp = tostring _grp;

I'm sure there must be a more elegant way to do it, but try that. :)

Haha! Maybe it´s not elegant, but I think it´s a really smart approach :D

Exactly what I was looking for.

Thanks to both of you!

Cheers,

CptBBQ

-----------------

edit:

aaaaand, it works! :yay:

great stuff, thanks again.

Edited by CptBBQ

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  

×