Jump to content
Sign in to follow this  
smacker909

help finding class name and/or location name in string

Recommended Posts

I'm trying to generate civilians on Altis based on a mission location.. based on type of houses or location type. I'm trying to use 'find' command to search a string, but not sure I understand how to use it.

I was thinking this should prevent my script from running , only when "PowerPlant" isn't found in the location class name;


_locations = nearestLocations [position player, ["NameVillage","NameCityCapital","NameCity","CityCenter","NameLocal","Hill"], _maxRange]; 
_loc = _locations call BIS_fnc_selectRandom;
_locNameType = classname _loc; 
_string = format ["%1",_locNameType];
//hint format ["String: %1",_string]; sleep 4;

// below I tried both '==0'  and '< 0'
if (_string find "PowerPlant" < 0) then {
   null = [getPos _hvt] execVM "scripts\civGen.sqf";
};

Also tried using search for "house" or "House" in object name;

_houseList = nearestObjects [_pos, ["house"], 200];
{
_houseName = format ["%1",typeOf _x];
if ((_houseName find "house" >= 0) && (_houseName find "House" >= 0)) then {
	_houseList = _houseList - [_x];
};
} forEach _houseList;

But... i'm getting civ spawns in areas where I don't think the class names have house in the string. Of course.. I'm probably going about this all wrong :)

From wiki ;

FIND:

Syntax:

array find x

Parameters:

array: Array - array to search in

x: Anything - array element to find

Return Value:

Number - 0 based position of the first array element that matches x, -1 if not found

Alternative Syntax

Syntax:

string find x (since ["Arma 3","Arma3",127,126674,"Development"])

Parameters:

string: String - string to search in

x: String - string to find

Return Value:

Number - 0 based position of the first sequence of characters that matches x, -1 if not found

\\\\

---EDIT---

okay,, this seems to be working for finding 'house' in object name---

_houseList = nearestObjects [_pos, ["house"], 200];

{

_houseName = format ["%1",typeOf _x];

if ((_houseName find "house" < 0) && (_houseName find "House" < 0)) then {

_houseList = _houseList - [_x];

};

} forEach _houseList;

Edited by smacker909

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  

×