OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting Multiplayer => Topic started by: BrAinOfJ on 19 Jan 2006, 15:04:01
-
How do i get a unit a unique name while using the creatunit command ?
-
as far as i know they'll be given one automatically. if you mean assign one as the designer, you need to create an identity in the description.ext, then use
this setidentity name_of_unit
as normal. untested, but i don't see why it wouldn't work as normal.
-
How will that know what unit to name ? There will be multiple units named, and they all need to be specified by me so if necessary, they can be deleted
-
he might want to do it in sidechat , maybe Pilots tute?
going for a look now!!!!!!!!!!!!!!!!
EDIT; oh wow thats diff! sorry!
-
ah right, i thought you meant name as in "David Armstrong"... ;)
i encountered a few difficulties with this issue, and i found the key is in pausing... here's how i did it:
you create your unit as normal, assigning a group and so on. in the 'script' part of the createunit command, you tell it to execute a separate script. this is the only way i got flashpoint to reliably perform commands on the unit as it's being created. it looks something like this...
_loontype createUnit [[x,y,z],group_name, {this exec "setup_spawn.sqs"}]
then in "setup_spawn.sqs"....
;establish loon
_who = _this
;set loon's attributes
_who setskill 1
_who setspeedmode "full"
_who setcombatmode "red"
_who allowfleeing 0
etc....
i suppose at the end there you could put
variable = _who
but that variable will be the same for every unit created. so you need a separate global counter, which you increment every time a unit is created. add something like this to "setup_spawn.sqs" -
call format ["unit_name%1 = _who", global_unitcounter]
global_unitcounter = global_unitcounter + 1
don't forget to declare the global variable in your init file - global_unitcounter = 0. your units will be called unit_name1, unit_name2, unit_name3, etc...
this is totally untested, but give it a go. i think it may work ;)
-
did post about the use of format, but bedges beat me to it
Another way is to refer to the unit by using select X from an array that you place a unit in after it has been created
eg
#INIT
tx_UNITS = []
_count = 1
#START
~1
_unit = "classname" createUnit [[x,y,z],group_name, {this exec "setup_spawn.sqs"}]
tx_UNITS = tx_UNITS + [_Unit]
_count = _count + 1
if(_count == 5)then{exit}else{goto "START"}
and then refer to ALL the units as
{_x docommandwhatever } foreach tx_UNITS
or individually as
(tx_Units select 0) docommandwhatever
tx_Units select 1
tx_Units select 2
tx_Units select 3
tx_Units select 4
-
_unit = "classname" createUnit [[x,y,z],group_name, {this exec "setup_spawn.sqs"}]
tx_UNITS = tx_UNITS + [_Unit]
IIRC, the createunit command doesn't actually return anything (unlike camcreate/createvehicle, which returns the vehicle created). Hence the reason why BrAinOfJ is running into trouble: he can't easily assign the unit to a variable.
My suggestion:
"classname" createUnit [[x,y,z],group_name, {TMP = this}]
_createdUnit = TMP
TMP = nil
This lets you assign the unit to a local variable within the script you are creating him in. "TMP = this" gets run as though it were in the unit's init field, giving him the "name" TMP (that is, it stores him in the global variable TMP). Then you immediately copy this global variable to a local one, and delete it (so that it doesn't interfere with other scripts that might be using this same technique at the moment).
Another possibility is to use this function, which works on a different premise (but might be better for MP):
http://www.ofpec.com/editors/funcref.php?filter_func=28