Jump to content
Sign in to follow this  
Spudgunner

Am I using the FIND function correctly?

Recommended Posts

I'm trying to search a dynamic array (_list) to see if the AI in civArray (selected by _i) are in the vehicle. However, hint never displays a number, even if it's zero. I tested the assignedCargo function, which display an array with numbers like [C 1-1-B:1], so that seems to work ok. Any ideas what I'm doing wrong.

_i = round (random 12); // 0 to 12
_list = [url="http://community.bistudio.com/wiki/assignedCargo"]assignedCargo[/url] bus1;
_num =  _list [url="http://community.bistudio.com/wiki/find"]find [/url](civArray select _i);
hint str(_num);
if (_num > -1) {
// do stuff
}

Share this post


Link to post
Share on other sites
I'm trying to search a dynamic array (_list) to see if the AI in civArray (selected by _i) are in the vehicle. However, hint never displays a number, even if it's zero. I tested the assignedCargo function, which display an array with numbers like [C 1-1-B:1], so that seems to work ok. Any ideas what I'm doing wrong.

Check your arma2.rpt file. It will tell you what went wrong.

I guess the script bails out with an error before hint.

Is civArray an array with objects or is it an array with string types ?

assignedCargo returns an array of objects.

Btw, this one will work too (civArray elements must be AI objects):

[font=monospace]
[/font]_i = round (random 12); // 0 to 12
if ((civArray select _i) in bus1) then {
};

Xeno

Share this post


Link to post
Share on other sites

So you're trying to pick a random occupant of a bus and see if it's a member of civArray? Is "civArray" a pre-set array of 13 objects?

Using the Functions module you could do something like this:

civArray = [c1,c2,c3,c4,c5,c6,c7,c8];

_rider = (assignedCargo bus1) call BIS_fnc_selectRandom;
player sideChat format["Your randomly chosen rider is %1", _rider];

if (_rider in civArray) then {
    // do stuff
    player sideChat format["%1 is in the bus!", _rider];
} else {
    player sideChat "None of your group is on the bus.";
};

Share this post


Link to post
Share on other sites

Xeno

The civArray contain AI, which I guess makes them objects. I looked for the arma2.rpt file, but its not in the installation directory. Again the script didn't process, just like mine.

kylania:

I tried the script, but although it can read who is onboard, oddly, it never matches up with the civArray. I'm wondering if seating position is interfering with the matching process.

As a side point, it worked better when I didn't put !isnil "bis_fnc_init" in the triggers condition field. :eek:

.

.

I'll print to screen the contents of civArray and see if there are any diffrences.

Share this post


Link to post
Share on other sites

In my test c1 - c8 were editor placed civilian units.

I had a bus grouped with one unnamed group of civilians. Then another group named c1-c8. The named ones started outside and had a GET IN waypoint. The unnamed started as Cargo of the bus.

And oops, i forgot this line at the top when I pasted it:

waituntil {!isnil "bis_fnc_init"};

Then i had a trigger that simply ran: nul = [] execVM "bus.sqf";

Share this post


Link to post
Share on other sites

The civilians in civArray are randomly produced via script. I printed the contents of civArray and compared it to _rider.

civArray >> [C 1-1- B, C 1-1-C, C 1-1-D, C 1-1-E, C 1-1-E, C 1-1-F, C 1-1-G, C 1-1-H, C 1-1-I, C-1-1 K, C 1-1-L, C 1-1-M]

_rider >> [C-1-1-B:1], [C-1-1-F:1] like above.

Except for [b 1-1-A[b]:1[/b]] & [b 1-1-A[b]:[/b]2] which would be the player's group of two members riding as cargo.

The difference is the extra colon and number (like :1). I'm guessing that indicates group members.

So if there's a way to ignore these extra characters, it would work. Another way is to Add :1 to civArray temporarilly. Is there any way to do this?

Edited by Spudgunner
clarify

Share this post


Link to post
Share on other sites

I'm a little confused about what you're doing.. what exactly are you trying to check for, if members of the players group are in the bus?

Share this post


Link to post
Share on other sites
I'm a little confused about what you're doing.. what exactly are you trying to check for, if members of the players group are in the bus?

When the trigger fires, there's a random chance that one or more passengers will disembark at a bus stop. The random number ( which might run more than once) will index civArray and the passenger(s), if on board, will leave the vehicle. The comparing bit above was just to find out whats going on. Its the extra characters (:1) that are causing it to fail.

Share this post


Link to post
Share on other sites

If there is a set group of civilians that may disembark, just name them all. That will solve the extra character things since they'll have easy to identify names, as in my example. C1, C2, C3 and so on.

Share this post


Link to post
Share on other sites

The way I'm working it is that every so often, random civs of all types, will wait at the bus stops. Atm, its 1 at each bus stop, making 12 at one time. Editor placed units will defeat the point. Perhaps there is a way to name dynamically generated civs.

I was wondering if I converted the C-1-1 characters to a string, then see if I can edit them. So I could the do "C -1-1 D" + ":1" = C 1-1 D:1. then convert back.

Edited by Spudgunner
spelling error

Share this post


Link to post
Share on other sites

I think you just want "in" - if _i in _civArray, then do whatever?

Also, there's a new BIS function to randomly select from an array. Sorry if I misunderstand....

Share this post


Link to post
Share on other sites

If it's only the ones in the bus that you want to be randomly advised to get off, that's even easier.

This code will make 1-4 random bus riders disembark.

for [{_i=0},{_i < (round(random 3) + 1)},{_i=_i+1}] do {
_rider = (assignedCargo bus1) call BIS_fnc_selectRandom;
unassignVehicle _rider;
};

Share this post


Link to post
Share on other sites
If it's only the ones in the bus that you want to be randomly advised to get off, that's even easier.

This code will make 1-4 random bus riders disembark.

for [{_i=0},{_i < (round(random 3) + 1)},{_i=_i+1}] do {
_rider = (assignedCargo bus1) call BIS_fnc_selectRandom;
unassignVehicle _rider;
};

Funnily enough, I ended up doing something similar. The only trouble is, they are now difficult to control after disembarking, since _rider will change. Who is who in terms of the original civArray. If there's away to identify them back with civArray again, it would be ok -or I could build a new array and null the old one. Thanks for athe help, much appreciated.

Btw, do you know how to send civs to maps objects such as building. The work type civs need to go to industrial building, secretary types to civic building s etc? Once they are out of sight, I'll probably disolve them - if I new how :o

Share this post


Link to post
Share on other sites
setVehicleVarName

That does basically the same as the "name" field in editor.

Thats handy! I could create names automatically with _name = "civ" + str (_num).

Shame it doesn't work for AI NPC's as hoped... they stopped spawning.

Edited by Spudgunner
update

Share this post


Link to post
Share on other sites

I use it for units I spawn with createunit, works fine.

Share this post


Link to post
Share on other sites
I use it for units I spawn with createunit, works fine.

For some reason I can't name them. Here's how I'm trying to do it.

for [{_i = 0},{_i <= 10},{_i = (_i + 1)}] do {
_name = "civ" + str(_i);
(civArray select _i) setVehicleVarName _name;
hint _name;		 
};

Share this post


Link to post
Share on other sites

Just tested quickly in Utes with 3 units and 2 radio triggers:

for "_i" from 0 to ((count units group player)-1) do {((units group player) select _i) setVehicleVarName "civ" + str _i;};

{player sidechat str _x;} foreach units group player

Chat showed:

civ0

civ1

civ2

Share this post


Link to post
Share on other sites

This is the trimmed down version of my code. If you run it, you'll need to place three markers (spwn0, spwn1, spwn2) on the map. Run once to show it works, then uncomment the code at the end, and run again.

I noticed that when printing array contents to screen, it lacks some characters (:1) that I have seen elsewhere. i.e [C 1-1 B] rather than [C 1-1 B:1 ]I'm not sure if its normal. I'm guessing the :1 is numbers or positions in a group - even groups of one member :) .

Could you have a look and see why I can't name the AI in civArray? I must be doing something wrong somewhere. :confused:

_civClassArray0 = ["Citizen1", "Citizen2", "Citizen3", "Citizen4", "Damsel1", "Damsel2", "Damsel3", "Damsel4", "Damsel5"];
_civClassArray1 = ["Functionary1", "Functionary2", "Functionary1", "Functionary2", "Secretary3", "Secretary2", "Secretary1", "Secretary5", "Secretary4"];
_civClassArray2 = ["Rocker1", "Rocker2", "Rocker3", "Rocker4", "Hooker4", "Hooker3", "Hooker2", "Hooker5", "Hooker1"];

// main Array
civArray = [];
_civSelect = [];

// CODE
for "_i" from 0 to 2 do {
// pick civClassArrayx, then copy it to _civSelect
_rand = round (random 2);
switch (_rand) do {   
	case 0: { _civSelect = + _civClassArray0; };   
	case 1: { _civSelect = + _civClassArray1; };
	case 2: { _civSelect = + _civClassArray2; };
	default { hint "ERROR";}; 
}; 
_rand = round (random 8); // because 0...8 elements in static arrays above
_spwn = "spwn" + str (_i); // Place three markers called spwn0, spwn1, spwn2 respectively	
_currentGroup = createGroup civilian;
_currentGroup createUnit [_civSelect select _rand, [(getMarkerPos _spwn) select 0, (getMarkerPos _spwn) select 1, 0], [], 0, "NONE"];
civArray = civArray + [_currentgroup];  // <-----<<< creates working array

//  >>>--------> hint will display something like [C 1-1 B] but not anything like [C 1-1 B:1] (note extra characters).  <-------<<<
// >>>--------> This might be the problem (or not).  I'm guessing they denote group numbers //<-------<<<
// hint str(_currentgroup); 
// sleep 3;
};

// >>>--------> THIS IS THE PROBLEMATIC PART. RUN  ONCE <--------<<<
// >>>--------> TO SHOW CODE WORKS, THEN UNCOMMENT <--------<<<

// for [{_i = 0},{_i <= 2},{_i = (_i + 1)}] do {
// _name = "civ" + str(_i);
// ((civArray) select _i) setVehicleVarName _name;
// hint str(civArray);	 
// };

Edited by Spudgunner
Make meaning clearer

Share this post


Link to post
Share on other sites

C 1-1-B is a group, C 1-1-B:1 is the first member of that group.

Anyway, I don't really understand if you are trying to add groups or units to the civArray, and how many. I assumed you wanted units.

_unit = _currentGroup createUnit [_civSelect select _rand, [(getMarkerPos _spwn) select 0, (getMarkerPos _spwn) select 1, 0], [], 0, "NONE"];
_unit setVehicleVarName format ["civ%1",_i];
civArray = civArray + [_unit];

That will give you an array named civArray with 3 units, named civ0, civ1 and civ2.

Share this post


Link to post
Share on other sites

That right, all AI are independant of each other. Although, I read somewhere that the game sees everything as groups, including units. Only units are groups of one member only (preety exclusive group!).

Where I put _currentGroup = createGroup civilian; I now placed in a switch-case structure ...

_civGroup0 = createGroup civilian; _civGroup1 = createGroup civilian; _civGroup2 = createGroup civilian; etc including createUnit & adding to civArray...

Unfortunately it doesn't run when I do that.

I'll try your code and see what happens. Thanks!

Share this post


Link to post
Share on other sites

Everyone is in a group, even if they are alone. Your code already creates groups for them.

Share this post


Link to post
Share on other sites
C 1-1-B is a group, C 1-1-B:1 is the first member of that group.

Anyway, I don't really understand if you are trying to add groups or units to the civArray, and how many. I assumed you wanted units.

_unit = _currentGroup createUnit [_civSelect select _rand, [(getMarkerPos _spwn) select 0, (getMarkerPos _spwn) select 1, 0], [], 0, "NONE"];
_unit setVehicleVarName format ["civ%1",_i];
civArray = civArray + [_unit];

That will give you an array named civArray with 3 units, named civ0, civ1 and civ2.

Great! That did the trick. Thanks for fixing the code. :yay:

I couldn't get that sidechat to work though but I'll try more combinations of trial and error. :)

---------- Post added at 19:59 ---------- Previous post was at 18:51 ----------

Fixing one problem creates a new one - Now this code no longer works. The AI civs spawn but don't move. The loop doesn't process at all. Now they are named, how do I move them?

_busStopArray = ["busStopA0", "busStopA1", "busStopA2", "busStopA3","busStopA4", "busStopA5","busStopA6", "busStopA7","busStopA8", "busStopA9","busStopA10", "busStopA11", "busStopA12"];

for [{_i = 0},{_i <= 10},{_i = (_i + 1)}] do {
civArray select _i addWaypoint [getMarkerPos (_busStopArray select _i), 0];

[civArray select _i, 1] setWaypointBehaviour "CARELESS";
[civArray select _i, 1] setWaypointSpeed "LIMITED";
[civArray select _i, 1] setWaypointtype "GETIN";
};

Share this post


Link to post
Share on other sites

You are trying to add a waypoint to a unit, while the syntax asks for a group.

(group (civArray select _i)) addWaypoint

Share this post


Link to post
Share on other sites
You are trying to add a waypoint to a unit, while the syntax asks for a group.

(group (civArray select _i)) addWaypoint

Thanks shk!

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  

×