Home   Help Search Login Register  

Author Topic: Take cover command?  (Read 805 times)

0 Members and 1 Guest are viewing this topic.

Offline DMarkwick

  • Contributing Member
  • **
  • I'm a llama!
Take cover command?
« on: 12 Jun 2005, 20:11:23 »
Hi all. I'm trying to get units to find/take cover, similar to the one under the Move submenu ingame.

At the moment I got a go to nearest object followed by a set behaviour to Stealth but I don't know whether its the best solution. Sometimes they just lie about where they are.

Does anyone know how to emulate this behaviour either through an official command (I can't find one) or through other methods?

DBR_ONIX

  • Guest
Re:Take cover command?
« Reply #1 on: 12 Jun 2005, 22:03:20 »
Theres a script posted in Scripting Beta Test board :)
The Take Cover command for AI is kinda of.. no, totaly.. usless :P
They wander about for 2 mins, then stand about 3m from a tree.. :hmm:
- Ben

Offline DMarkwick

  • Contributing Member
  • **
  • I'm a llama!
Re:Take cover command?
« Reply #2 on: 14 Jun 2005, 16:37:10 »
Ah, thanks for the reply :) I looked at that script, but its really too complex for my immediate needs, I just need them to move to their nearest object really.

My current oneliner is (something like):

this move getpos nearestobject getpos this

(I tried it with explicit names instead of "this" as well, also tried other move commands like domove, commandmove etc)
hoping that the unit it's applied to will simply move to it's nearest object. However it isn't doing anything. There's no error messages of any kind so at least the sytax should be OK.

DBR_ONIX

  • Guest
Re:Take cover command?
« Reply #3 on: 14 Jun 2005, 17:09:40 »
nearestobject command needs a classname to go to :(
Code (at simplest) would be something like :
Code: [Select]
this move getpos (nearestobject "bush1")

But that's limited to one type of bush/tree etc, so it'd be something like this..
Code: [Select]
; [this
_unit=_this select 0

;arrayOfClassNames]
_type=_this select 1

;Counter
_i=0
;Ammount of class names suplied
_e=count _type

#loop
;Get nearest object of the current classname in array
_current = nearestobject (_type select _i)

;Find distance to nearest object
_dis = _unit distance _current

;If the unit is under 20m, go there, and quit script
?(_dis < 20):_unit move getpos _current;exit

;Prod counter up
_i=_i+1

;If done for each classname, exit
?(_i > _e):exit

; Still not done all array things, do next
goto "loop"

;if no cover found, unit does the following
; unit goes prone
_unit setUnitPos "DOWN"
exit

Run like : [this,[bush1,bush2,bush3,tree1,tree2]] exec "script.sqs"

I've not used nearestobject command much, but I think that should work..
Nearestobject is limited to 50m remeber. If the unit is over 20m away, he wont go to it.

I've commented the code, hopefully you can follow it

- Ben

Offline 456820

  • Contributing Member
  • **
Re:Take cover command?
« Reply #4 on: 14 Jun 2005, 17:29:06 »
Quote
Nearestobject is limited to 50m remeber. If the unit is over 20m away, he wont go to it.
why 20m is less than 50m so its with in the limit
also i wanted a script just like that not long ago

DBR_ONIX

  • Guest
Re:Take cover command?
« Reply #5 on: 14 Jun 2005, 19:15:59 »
I mean if there's no cover within 50m, it wont find anything (He'll just go prone where he is)
Then the 20m thing was there so he wouldn't run over big open gap to get to a single bush, just run 20m to hide

Suppose I should test this :P
- Ben

Offline DMarkwick

  • Contributing Member
  • **
  • I'm a llama!
Re:Take cover command?
« Reply #6 on: 14 Jun 2005, 23:45:10 »
nearestobject command needs a classname to go to :(
Code (at simplest) would be something like :
Code: [Select]
this move getpos (nearestobject "bush1")

But that's limited to one type of bush/tree etc, so it'd be something like this..
Code: [Select]
; [this
_unit=_this select 0

;arrayOfClassNames]
_type=_this select 1

;Counter
_i=0
;Ammount of class names suplied
_e=count _type

#loop
;Get nearest object of the current classname in array
_current = nearestobject (_type select _i)

;Find distance to nearest object
_dis = _unit distance _current

;If the unit is under 20m, go there, and quit script
?(_dis < 20):_unit move getpos _current;exit

;Prod counter up
_i=_i+1

;If done for each classname, exit
?(_i > _e):exit

; Still not done all array things, do next
goto "loop"

;if no cover found, unit does the following
; unit goes prone
_unit setUnitPos "DOWN"
exit

Run like : [this,[bush1,bush2,bush3,tree1,tree2]] exec "script.sqs"

I've not used nearestobject command much, but I think that should work..
Nearestobject is limited to 50m remeber. If the unit is over 20m away, he wont go to it.

I've commented the code, hopefully you can follow it

- Ben

Oooh, thanks very much :) with a little massaging, I think I could use some of that (assuming you don't mind ;)). I just need enemy units to roughly hide on mission start, nothing outrageously clever, I need to find them :D

Looks like the type name is key then, pity it can't return literally the nearest object, but then I suppose they'd be returning each other in the group. :P