Home   Help Search Login Register  

Author Topic: createUnit  (Read 1036 times)

0 Members and 1 Guest are viewing this topic.

Uldics

  • Guest
createUnit
« on: 12 Dec 2004, 06:04:27 »
I have some strange behaviour (or no behaviour at all :( ) with a soldier created vith command "createUnit". It is not responding to any scripted orders. If I add him by "createUnit" command to a player group, I can give him orders and he will do that. But I don't want him to be in player group. I tried join GrpNull, moveindriver (with assignasdriver), ordergetin, changing soldiers class, making a pause after creation like ~20 ; nothing helps. My script looks like that:

Code: [Select]
? !(local server) : exit
_tank = "T80" createVehicle getmarkerpos "tankscomeout_1"
_tank setpos getmarkerpos "tankscomeout_1"
_tank setdir 180
_driver = "SoldierE" createUnit [getMarkerPos "tankscomeout_1", crewgroup]
_driver join GrpNull
_driver assignAsDriver _tank
_driver moveInDriver _tank

I have of course a soldier on my map with initline:
crewgroup = group this; deletevehicle this

How can I make him obey scripted orders?


Quote
1. edit

I found the problem, but that spawned another problem. I had mistaken the return value of createvehicle and createunit. They are unfortunately not in same way: createunit doesn't return anything.

The new problem is that I don't have a name for the unit, which I could use in my script. I can use the init string, but then I can not create more than one unit without retyping everything for every soldier I create. Any suggestions?
« Last Edit: 12 Dec 2004, 07:21:39 by Uldics »

Offline Sui

  • Former Staff
  • ****
    • OFPEC
Re:createUnit
« Reply #1 on: 12 Dec 2004, 07:05:59 »
The problem is this line right here:
_driver = "SoldierE" createUnit [getMarkerPos "tankscomeout_1", crewgroup]

Createunit won't let you assign the unit a name like that...
It works fine on createvehicle, but for createunit you have to do this:

Code: [Select]
"SoldierE" createUnit [getMarkerPos "tankscomeout_1", crewgroup, "_driver = this"]
Just note, I'm not sure if you can give your unit a local variable name either... it may have to be global.

Uldics

  • Guest
Re:createUnit
« Reply #2 on: 12 Dec 2004, 07:22:47 »
No, thats the new problem, the local variable is then inside only that init field.

Uldics

  • Guest
Re:createUnit
« Reply #3 on: 12 Dec 2004, 10:43:14 »
It is some kind of evil circle. Impossible to make 20 units with 20 vehicles.
I see two possibilities:
A) give a global name to a created unit. The result is creation of only first unit.
B) use "[this] join GrpNull" in created soldiers init field. The join never happens.

The join thing never happens when I make it for unit or his vehicle or both. The only thing I have achieved is crash to desktop eksperimenting with the stuff. Should I go kill myself or what?  >:( ???

Offline Sui

  • Former Staff
  • ****
    • OFPEC
Re:createUnit
« Reply #4 on: 13 Dec 2004, 02:12:37 »
So does the unit have to be named?

What are you looking to do with it exactly?

Offline Sentinel

  • Contributing Member
  • **
  • World is tough and I'm tougher!!
Re:createUnit
« Reply #5 on: 13 Dec 2004, 15:06:13 »
If you need to name unit you could make float running index with the name. Not sure if this works. I ripped part of it from Blancos blanks script.

Name = call format ["Unit%1",index]

index is a global variable, starting from 0 and groving when ever you want, so it should be in the script after every unit

index = index + 1

That dummy group, i found that it can be joined once but after that, the group does not exist after creating a unit in it and then joining the unit to grpnull or to other group. So you need to create that dummy group again and again.

Offline Artak

  • The old beanbag shaker
  • Former Staff
  • ****
  • You want to talk about it, yes?
    • OFP Team Finlanders
Re:createUnit
« Reply #6 on: 13 Dec 2004, 16:47:56 »
Umm.. hold on a minute. I think you're making this more difficult than it is.

Uldics, you're trying to create 20 vehicles with drivers at a marker? This is all it should take:

Code: [Select]
?!(local server) : exit
_drivers = [driver1, driver2, driver3, ..., driver20]
_tanks = [_tank1, _tank2, _tank3, ..., _tank20]
_counter = -1

#loop
_counter = _counter +1
?_counter > 19: goto "end"

(_tanks select _counter) = "T80" createVehicle getmarkerpos "tankscomeout_1"
(_tanks select _counter) setdir 180

"SoldierE" createUnit [getMarkerPos "tankscomeout_1", crewgroup, "(_drivers select _counter) = this",0.5,"private"]
(_drivers select _counter) join GrpNull
(_drivers select _counter) assignAsDriver (_tanks select _counter)
(_drivers select _counter) moveInDriver (_tanks select _counter)
goto "loop"

#end
"_x move getpos player" foreach _drivers
exit

 
???
« Last Edit: 13 Dec 2004, 16:48:40 by Artak »
Not all is lost.

Offline OFPfreak

  • Members
  • *
  • Who is da operation flashpoint freak now, freak?!
    • OFP NFS mod
Re:createUnit
« Reply #7 on: 16 Dec 2004, 02:03:02 »
Erm this post is helpfull actually but I want to know how I can spawn a helicopter with no-one in it. Im making a role-playing map, a small 1 and a large 1.. And with an addaction command I buy a car.. I dont really get it.. I suck in scripting.. But Im getting it alright!
ofp nfs REBORN! All new nitro, neon, customized cars, off-road, on-road, rally, bikes, racer models and more!
ofp nfs's homepage

Offline Triggerhappy

  • Contributing Member
  • **
  • Llama, it's what's for dinner.
Re:createUnit
« Reply #8 on: 16 Dec 2004, 02:57:58 »
read the rules, mate. only ask your question in one place, no need to spam the forums  ;D you've gotten some answers on the thread you posted, don't worry, most of your questions will be answered in less than a day, so you don't need to ask a lot

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re:createUnit
« Reply #9 on: 16 Dec 2004, 02:58:07 »
You mean create an empty chopper?

Try this as an example

"cobra" createvehicle getpos player

Just replace the "cobra" with the name of the chopper of your choice.

If you don't want the chopper almost sitting on top of you, you can specify the coordinates [x,y,z], where you wish it placed.


Planck
I know a little about a lot, and a lot about a little.

Offline OFPfreak

  • Members
  • *
  • Who is da operation flashpoint freak now, freak?!
    • OFP NFS mod
Re:createUnit
« Reply #10 on: 16 Dec 2004, 07:39:47 »
ok sorry for spamming... I get it now.. but while somone already replied to me, I wanted to ask him how you can know the exat co-ordinates! By ordering your team to move there??
ofp nfs REBORN! All new nitro, neon, customized cars, off-road, on-road, rally, bikes, racer models and more!
ofp nfs's homepage

Uldics

  • Guest
Re:createUnit
« Reply #11 on: 16 Dec 2004, 17:03:56 »
Artak, that array assignment is not working, it says:

'(_tanks select _counter) #= "T80" createVehicle getmarkerpos "tankscomeout_1" ' : Error Unknown operator.

And I can't find it in reference, there is only operations with whole arrays, lists and so on, not with changing one element of the array. How do I then assign an element of an array? I mean write, not read. Ok there is a command for that:

_tanks set [counter, "T80" createVehicle getmarkerpos "tankscomeout"]

But there still is the problem with the created units init line. Look at my script (changed a bit):

Code: [Select]
?!(local server) : exit
drivers = [driver0, driver1, driver2, driver3, driver4]
_tanks = [_tank0, _tank1, _tank2, _tank3, _tank4]
counter = 0

#loop
~0.1
         ;? ([getmarkerpos "tankscomeout", getpos (_tanks select (_counter-1))] call distancePos < 15) : goto "loop"
_tanks set [counter, "T80" createVehicle getmarkerpos "tankscomeout"]
(_tanks select counter) setdir 180


"SoldierE" createUnit [getMarkerPos "tankscomeout", tankisti, "drivers set [counter, this]",1,"private"]
[(drivers select counter)] join GrpNull
(drivers select counter) assignAsDriver (_tanks select counter)
(drivers select counter) moveInDriver (_tanks select counter)
(drivers select counter) move position object 101440


counter = counter +1
? counter < 3 : goto "loop"


hint "Exit"
exit


I made variables global, or else there was no soldiers getting in tanks. Just getting in formation on foot. Now it looks like there is only created one driver. All other tanks are empty. How do I get a proper information exchange with that init line, so I can get my tanks rolling to a point? Or is there not init line problem?
« Last Edit: 16 Dec 2004, 23:40:06 by Uldics »

Uldics

  • Guest
Re:createUnit
« Reply #12 on: 17 Dec 2004, 09:13:48 »
Yes, I made it!!! I looked at Sentinels post and tried to think (!!!!!!!) about what he means. And there is something like that going on. And I let my first guy (to define an existing group) stay alive om map in editor, with init line just to define group and without deletevehicle this. The result is now - I have tanks with drivers more than 12, all roling independently to the point where I need them to gather up. Exactly what I needed!

So, the problem was not in script, not in init line. But strange that with that guy deleted, I still got the drivers created - but only 12. I hope the createunit command in OFP2 will have same syntax as createvehicle. And without need for an existing group. Just of curiosity: anybody knows about that stuff in VBS?