Jump to content
🛡️FORUMS ARE IN READ-ONLY MODE Read more... ×
Sign in to follow this  
Nicolas Eymerich

How to control a created unit

Recommended Posts

Hi!

I need a little help... There's a question still I can get no answer.

When I create a unit (for example: a soldier), is there a way to control him? I mean: how can I give some orders to him (considering that he isn't, and he must not be, in the player group) like, for example, move to player position?

Consider also I'm creating the unit in a script. banghead.gif

Share this post


Link to post
Share on other sites

Hi,

if you want to move such a unit to a certain location you can do this like that: Presuming, the target is at a marker called "marker1" and the created soldiers are in a group called "group"

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">group setSpeedMode "LIMITED"

group setBehaviour "CARELESS"

{_x doMove getpos marker1;} foreach units group

or

group move getpos marker

Hm, I not a good scripter, but I hope that was right huh.gif

cu

Jens

Share this post


Link to post
Share on other sites

Thanks for your reply but I already know that...

In fact, I was wondering if there is a way to continue to control the created unit. For exemple, after the soldier has moved, How Can you tell him to move to another position? banghead.gif

Share this post


Link to post
Share on other sites

Or if you just want to move a single unit that has been camcreated and not the intire group hes been created in you could do somthing like this:

This is the line of code to camcreate the soldier (not sure on the class name Wsoldier)

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

"WSoldier" createunit [getpos SomeWhere,GroupName,"[This,Location] exec {move.sqs}"]

Just replace 'SomeWhere' with an object or gamelogic name where you want to spawn the soldier, 'groupname' replace with a name of a group you want the soldier to be spawned into, and finally replace 'Location' with the name of a object or gamelogic you want the soldier to move to.

Move.sqs

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_Dude=_this select 0

_location=_this select 1

_Dude domove _location

OR

_Dude move _location

OR if you used the name of a marker for 'location' in the code up above:

_dude move (getmarkerpos _location)

The different from Move and Domove is that if a unit is place on Move he will also follow SetSpeedMode and SetBehaviourMode commands but also if the AI commander tells him to do somthing else whiles on route hell do that instead. Where if you use Domove he will ignore SetSpeedMode and SetBehaviourMode commands and ignor any commands from his commander intill he gets to his location. But with iver Domove or Move the soldier will fire upon enemys iver way.

Hope that helps, and i also hope i got all that right tounge2.gif

Edit: Ok in reply to the post you just made whiles i was typing this, try this to get the soldier to move after hes gone to one location:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

"WSoldier" createunit [getpos SomeWhere,GroupName,"[This,Location,location2,location3,etc..] exec {move.sqs}"]

Move.sqs

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_Dude=_this select 0

_location=_this select 1

_location2=_this select 2

_location3=_this select 3

_location3...ect..

;----------------------

_Dude domove _location

#loop1

?_dude distance _location <10:goto "move2"

~1

goto "loop1"

;-------------------------

#move2

_dude domove _location2

#loop2

?_dude distance _location <10:goto "move3"

~1

goto "loop2"

;---------------------------

#move3

_dude domove _location3

#loop3

?_dude distance _location <10:goto "move4"

~1

goto "loop3"

;------------------------

And carry one repeating it for as many locations as you want the soldier to move to.

Share this post


Link to post
Share on other sites

If you want to be able to use mapclicks to tell the guy where to go, try something like this in the trigger's "onActivation" field:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">onMapSingleClick {[_pos] exec "YOUR_SCRIPT_HERE.sqs"}

In your script, try something like:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_pos = _this select 0

onmapsingleclick {}

...

domove, etc

_pos is a location, and can be manipulated so:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_x = _pos select 0

~0.1

_y = _pos select 1

Set the trigger to repeat and you can order the guy around with the radio and mapclicks.

Share this post


Link to post
Share on other sites

Well thanks for your answers...

@ ---> D.murphy man ---> your script is useful but it isn't

suitable for my needs. In fact, you can't truly control the soldier. After he reachs the first position automatically he moves to the second position. Thanks for Move and Domove Explanation, however, I've also thought those commands were very similar wink_o.gif

@ ---> tacrod ---> You've given an intersting suggestion but I'm still far to the solution huh.gif Consider that I create the soldier in a script. How can I control the soldier in a second script (which use the onmapsingleclick command) ? Consider also that, unless it is absolutly necessary, I would like avoid to use a trigger. help.gif

Share this post


Link to post
Share on other sites

So when you spawn your guy, give him a name like so:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">"soldierecrew" createunit [_sp,GROUP_NAME,"MY_DUDE=this",1,"SERGEANT"]

Change "GROUP_NAME" to the name of whatever group you want and "MY_DUDE" to whatever name you want. (In the code above, _sp is the spawn location, 1 is the skill level and sergeant is the rank, you can change these to whatever you want or leave them out). In the script executed by the trigger, put something like:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_pos = _this select 0

onmapsingleclick {}

~0.1

MY_DUDE domove _pos

exit

Another alternative would be the setwppos command.

I haven't tested the exact code I have pasted above, but it is all cut and pasted from missions I am working on, so it should be okay. Try it in the editor and let me know what happens.

@ D.murphy man: Thanks for the move/domove comparison, I didn't know that. Very useful info.

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
Sign in to follow this  

×