Jump to content
Sign in to follow this  
James222

How to find string inside a string, in an array.

Recommended Posts

I need to look for part of a weapon name within a element, in an array for each element in the array and the return the path(s) to the matching element(s) so I can replace it/them with something else. Help? :confused:

Share this post


Link to post
Share on other sites

I never tried to search stuff inside strings, but the only think i can think of would be the toArray command. Never used it, i tried but never could do what i wanted with it.

Share this post


Link to post
Share on other sites
Why not use hasWeapon? What exactly are you trying to do?

I need to do it server side, and the array of weapons isn't actually (weapons player) its stored in a separate array.

I'm trying to look through the array then find some text in one of the element of the array, then get the path to that element(ex: select 3) and then replace the entire element with something else.

Share this post


Link to post
Share on other sites

There's a few nested element arrays available in the functions module you might want to take a look at in that case.

Share this post


Link to post
Share on other sites

Yeah.. bis_fnc_help dident give me much to work off of other then bis_fnc_findnestedarray which was not helpful as find works for the entire value and matches it. Damn.

Share this post


Link to post
Share on other sites
I need to do it server side, and the array of weapons isn't actually (weapons player) its stored in a separate array.

Why not broadcast that array to the server then?

Share this post


Link to post
Share on other sites
Why not broadcast that array to the server then?

Good idea, but how do I make it so each publicvariable is different depending on player UID? I know it would be something with format but not completely sure.

Share this post


Link to post
Share on other sites

Set the variable on each player. I'm still confused how you're getting a list of weapons from a player without having access to weapons player though. Why use variables and arrays instead of what the player actually has on him?

Share this post


Link to post
Share on other sites
Set the variable on each player. I'm still confused how you're getting a list of weapons from a player without having access to weapons player though. Why use variables and arrays instead of what the player actually has on him?

I'm making sort of a persistent mission and acre is conflicting with it because it has ID's. And I want players to keep their radios after the server restarts with my inventory saving setup I'm developing.

So when they reconnect it should conflict with radio ID's of people already in the server.

Which is why I need to strip weapons player copycat array when they save it. ACRE has functions to getBaseRadio and stuff but I don't know how to find and locate the unique radio's in weapons player array because find only works on comparing the full string.

Share this post


Link to post
Share on other sites

[] call acre_api_fnc_getCurrentRadio

That's the ACRE function to find the classname of the current radio a player has.

Share this post


Link to post
Share on other sites
[] call acre_api_fnc_getCurrentRadio

That's the ACRE function to find the classname of the current radio a player has.

I know, but that isn't what I want to do. This is probably a lost cause feature, I'll just have to remove radios on disconnect I guess.

Share this post


Link to post
Share on other sites

... ACRE has functions to getBaseRadio and stuff but I don't know how to find and locate the unique radio's in weapons player ...

I know, but that isn't what I want to do.

I didn't link BaseRadio, I linked CurrentRadio. :) It returns the class name of the unique radio the player has. It doesn't use weapons player, it uses ACRE's variables.

If it's a new session anyway, does it really matter if they have the same ID as last time? Won't that all get initialized again when they reconnect?

Share this post


Link to post
Share on other sites
I didn't link BaseRadio, I linked CurrentRadio. :) It returns the class name of the unique radio the player has. It doesn't use weapons player, it uses ACRE's variables.

If it's a new session anyway, does it really matter if they have the same ID as last time? Won't that all get initialized again when they reconnect?

I think those variables are local to ACRE client. And I'm not quite sure if they will get reinitialized on reconnect since ID's are per-radio. Ill ask in ACRE thread.

Share this post


Link to post
Share on other sites

this can be done like so:

_str = some_array select (some_index);
_strUnicode = toArray _str;    // string is now array of unicode characters
_indexBegin = 0;     // where the nested string begins
_indexEnd = 0;       // where the nested string ends
_index = 0;
{

   if (_x == 39 || _x == 34) then      // ' apostrophe unicode (39 in decimal) " quotation unicode (34 in decimal)
   {
        // begin string
        // for loop begins at next character after " or '
        _indexBegin = _index + 1;   // nested string starts here (after " or ')
        for [{_i = _index + 1}, {_i < (count _strUnicode)}, {_i = _i + 1}]
        {
             if (_strUnicode select _i == 39 || _strUnicode select _i == 34) exitWith
             {
                   // end of string
                   _indexEnd = _i;
             }
         }
   }
   _index = _index + 1; // increment counter
} foreach _strUnicode

probably best to wrap this into a function than you can just use it as a sort of substring function to get only the part of the string back, with this you can then just have a for loop that starts at _indexBegin and ends at _indexEnd as a new array, converted using toString

ugly? yes. Needlessly complex? totally. Useful? Dam straight it is. Strings should be treated like cstrings in c with random access inherent in them by default.

Note: Unicode is written in hexidecimal, so you need to convert from hex to decimal first. Unless .sqf can work with hex numbers. Also its been a while since i touched sqf, so it might be written like c++ lol.

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  

×