Home   Help Search Login Register  

Author Topic: Naming units in createunit  (Read 2188 times)

0 Members and 1 Guest are viewing this topic.

BrAinOfJ

  • Guest
Naming units in createunit
« on: 19 Jan 2006, 15:04:01 »
How do i get a unit a unique name while using the creatunit command ?

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:Naming units in createunit
« Reply #1 on: 19 Jan 2006, 15:08:53 »
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

Code: [Select]
this setidentity name_of_unit
as normal. untested, but i don't see why it wouldn't work as normal.
« Last Edit: 19 Jan 2006, 15:09:17 by bedges »

BrAinOfJ

  • Guest
Re:Naming units in createunit
« Reply #2 on: 19 Jan 2006, 15:51:19 »
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

yankme

  • Guest
Re:Naming units in createunit
« Reply #3 on: 19 Jan 2006, 16:07:55 »
he might want to do it in sidechat , maybe Pilots tute?  

going for a look now!!!!!!!!!!!!!!!!

 EDIT; oh wow thats diff! sorry!
« Last Edit: 19 Jan 2006, 16:15:21 by yankme »

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:Naming units in createunit
« Reply #4 on: 19 Jan 2006, 16:10:23 »
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...

Code: [Select]
_loontype createUnit [[x,y,z],group_name, {this exec "setup_spawn.sqs"}]
then in "setup_spawn.sqs"....

Code: [Select]
;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

Code: [Select]
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" -

Code: [Select]
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 ;)
« Last Edit: 19 Jan 2006, 16:11:32 by bedges »

Offline Terox

  • Former Staff
  • ****
  • Follow the Sappers!
    • zeus-community.net
Re:Naming units in createunit
« Reply #5 on: 19 Jan 2006, 16:31:39 »
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

« Last Edit: 19 Jan 2006, 16:35:24 by Terox »
Zeus ARMA2 server IP = 77.74.193.124 :2302
Teamspeak IP = 77.74.193.123

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:Naming units in createunit
« Reply #6 on: 20 Jan 2006, 02:02:48 »
_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
HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!