Jump to content

Recommended Posts

Hi all, i'm creating a scenario in which I'd need some (a lot actually) groups of AIs to spawn in certain markers and follow a waypoint assigned after their creation. Since I need to do that a lot of times, i tried to create an Inline function inside of the .sqf file I use to control all the processes and spawns during the mission.

 

spawngroup = {
	params ["groupname", "marker"];

 	"Terrorista1" createUnit [getMarkerPos "marker",groupname,"this allowFleeing 0",random 1, "Private"];
	"Terrorista2" createUnit [getMarkerPos "marker",groupname,"this allowFleeing 0",random 1, "Private"];
	"Terrorista3" createUnit [getMarkerPos "marker",groupname,"this allowFleeing 0",random 1, "Private"];
	"Terrorista4" createUnit [getMarkerPos "marker",groupname,"this allowFleeing 0",random 1, "Private"];
	"Terrorista5" createUnit [getMarkerPos "marker",groupname,"this allowFleeing 0",random 1, "Private"];


	wp = groupname addWaypoint [position attack,0,0];
	wp setWaypointType "DESTROY";


	groupname setCurrentWaypoint [groupname, 0];

};

gruppo1 = createGroup EAST;
[gruppo1,"spawn1"] call spawngroup;

gruppo2 = createGroup EAST;
[gruppo2,"spawn2"] call spawngroup;

etc...

 Obviously (because I suck) this does not work, inside the missions it returns an error like local variable in global space..

Anyone can make this work properly? I just want a func that given a groupname and a marker, create those AI and send them to destroy anything on marker "attack"
 

Share this post


Link to post
Share on other sites

Where are you actually calling this function at? Surely not a trigger of sorts right?

Otherwise, wouldn't make sense if it was being executed in scheduled. 

Share this post


Link to post
Share on other sites
3 minutes ago, Midnighters said:

Where are you actually calling this function at? Surely not a trigger of sorts right?

Otherwise, wouldn't make sense if it was being executed in scheduled. 

it's called inside the .sqf in which it is declared

Share this post


Link to post
Share on other sites
13 minutes ago, 2RGT Niko said:

params [groupname, "marker"];

groupname has to be "groupname" 

 

in quotations. 

Share this post


Link to post
Share on other sites
3 minutes ago, Midnighters said:

groupname has to be "group name" 

 

in quotations. 

with the space too? I mean, group name, not groupname?

Share this post


Link to post
Share on other sites
1 minute ago, 2RGT Niko said:

with the space too? I mean, group name, not groupname?

group name without the space.

Share this post


Link to post
Share on other sites

Ok I did it, but there still is an Error Local variable in global space at line 2

Share this post


Link to post
Share on other sites

Why do you create the group outside of the fnc? Do you need it for something specifically?
Is TerroristaN a cfg entry?
You need to use local variable inside fnc in this case (e.g. _marker and not marker)

Share this post


Link to post
Share on other sites
2 minutes ago, giallustio said:

Why did you create the group outside of the fnc? Do you need it for something specifically?
TerroristaN is a cfg entry?
You need to use local variable inside fnc in this case (e.g. _marker and not marker)

but wouldn't it still be local wether or not it was "marker" or "_marker"

especially since it's enclosed in the  brackets, and the variable couldn't be used anywhere else? 

 

Share this post


Link to post
Share on other sites
4 minutes ago, giallustio said:

Is TerroristaN a cfg entry?


TerroristaN are unit's class names

 

5 minutes ago, giallustio said:

Why do you create the group outside of the fnc? Do you need it for something specifically?
 

Because I need to do that with a lot of new groups during the mission, that's why I wanted a func, or I'd need to copy paste the block of code one time for every group, and it'd be an huge amount of code

 

Share this post


Link to post
Share on other sites
2 minutes ago, 2RGT Niko said:


TerroristaN are unit's class names

 

Because I need to do that with a lot of new groups during the mission, that's why I wanted a func, or I'd need to copy paste the block of code one time for every group, and it'd be an huge amount of code

 

why not just create the group inside the function? That way, regardless of what groups exist: you'd be able to assign the units to the group and execute the waypoint without having to create more and more groups if you decide to make any more units. 

Share this post


Link to post
Share on other sites
gruppo1 = createGroup EAST;
[gruppo1,"spawn1"] call spawngroup;

-------
 

["spawn1"] call spawngroup;

spawngroup = {
	params ["_marker"];
	_gruppo = createGroup EAST;
 	"Terrorista1" createUnit [getMarkerPos _marker,_gruppo,"this allowFleeing 0",random 1, "Private"];
	etc....

 

  • Like 2

Share this post


Link to post
Share on other sites
2 minutes ago, Midnighters said:

why not just create the group inside the function? That way, regardless of what groups exist: you'd be able to assign the units to the group and execute the waypoint without having to create more and more groups if you decide to make any more units. 


In that case, ArmA create each time a new group? Or overwrite the current one?

Share this post


Link to post
Share on other sites

@giallustio still need clarification on why you think _marker and marker would make a difference in locality. 

Share this post


Link to post
Share on other sites
1 minute ago, 2RGT Niko said:


In that case, ArmA create each time a new group? Or overwrite the current one?

Not necessarily, once you create the unit you either assign a group or it's its own group. 

 

Share this post


Link to post
Share on other sites

I don't know if that change anything, but this should work on a dedicated MP server

Share this post


Link to post
Share on other sites
4 minutes ago, giallustio said:

I'm talking about the usage within the brackets. Not the params, because that is totally separate from where it's being used.

I totally agree with it not being local within params. But inside? 

 

Share this post


Link to post
Share on other sites
"spawn1" is the marker name.
If you pass it to the fnc, you need to use a local var. 
_marker = _this select whatever;
If you use "marker", it will look for the marker called "marker" which doesn't exist in this context
  • Like 1

Share this post


Link to post
Share on other sites
spawngroup = {
	params ["_marker"];

	_groupname = createGroup EAST;

 	"Terrorista1" createUnit [getMarkerPos "_marker",_groupname,"this allowFleeing 0",random 1, "Private"];
	"Terrorista2" createUnit [getMarkerPos "_marker",_groupname,"this allowFleeing 0",random 1, "Private"];
	"Terrorista3" createUnit [getMarkerPos "_marker",_groupname,"this allowFleeing 0",random 1, "Private"];
	"Terrorista4" createUnit [getMarkerPos "_marker",_groupname,"this allowFleeing 0",random 1, "Private"];
	"Terrorista5" createUnit [getMarkerPos "_marker",_groupname,"this allowFleeing 0",random 1, "Private"];


	_wp = _groupname addWaypoint [position attack,0,0];
	_wp setWaypointType "DESTROY";


	_groupname setCurrentWaypoint [_groupname, 0];

};

["spawn1"] call spawngroup;

That's the actual code, and it WORKS, thanks a lot guys <3

Share this post


Link to post
Share on other sites

Well not, it doesn't totally work, AI spawns correctly but they're totally not going on marker "attack", they move somewhere on southeast, probably to coordinates 0,0, or the map's center, maybe. The problem is here i guess


	_wp = _groupname addWaypoint [position attack,0,0];

how can i fix it?

P.S. actually attack is a folding chair, not a marker :huh2:

Share this post


Link to post
Share on other sites

_wp = _groupname addWaypoint [getPos attack, 0];

And remove 

_groupname setCurrentWaypoint [_groupname, 0];

Give it a try.

Or:
_groupname setCurrentWaypoint [_groupname, _wp];

Share this post


Link to post
Share on other sites
6 minutes ago, giallustio said:

_wp = _groupname addWaypoint [getPos attack, 0];


Only changing this gives no errors but AI just spawn without moving

I added your setCurrent but there's an error in the syntax, because he wants an index not a waypoint

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

×