OFPEC Forum

Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: SilentHunter_764 on 05 Dec 2005, 09:26:58

Title: Selecting Unit Problem?
Post by: SilentHunter_764 on 05 Dec 2005, 09:26:58
Hello all,

Firstly i appoligse if this is in the wrong thread. I havent been on OFPEC in a while, so.. ;D
I've been working on a script lately:

Code: [Select]
_unit = _this select 0

#loop
_unit addaction ["Engage at will!","engage.sqs"]
_unit addaction ["Forward!","forward.sqs"]
_unit addaction ["Halt!","halt.sqs"]

goto "loop"

Now, the problem lys within the unit selection. Ive made the corresponding scripts for this script (Engage.sqs etc) like this:

Code: [Select]
_unit = _this select 0

_unit switchmove "CommandEngageAtWill"
~1
_Unit GroupChat "Engage at will"

exit

However when i get in, i get the error: _unit = _this select 0 | type array expected object | or something like that.

Can anyone help me?

Cheers,
Kannon ;D
Title: Re:Selecting Unit Problem?
Post by: LoTekK on 05 Dec 2005, 09:48:27
I don't quite get the first script snippet. Why are you sticking the addactions in an endless loop? Within about 2 seconds you'll likely have about a million of each action added to the action list.

As for the rest of it, it works without a hitch.

Or rather, I don't get any error messages. You might want to look into the switchmoves, though, since there'll be no tweening between the unit's current stance/animation and the hand signal animation. Also, as it currently stands, the unit will get stuck in the handsignal animation, unable to move.
Title: Re:Selecting Unit Problem?
Post by: Trapper on 05 Dec 2005, 14:23:12
The errormessage will be caused by the script call.

Correct are:

soldier1 exec "script.sqs"
Code: [Select]
_unit = _this
[soldier1] exec "script.sqs"
Code: [Select]
_unit = _this select 0
Title: Re:Selecting Unit Problem?
Post by: Baddo on 05 Dec 2005, 18:06:39
The errormessage will be caused by the script call.

Correct are:

soldier1 exec "script.sqs"
Code: [Select]
_unit = _this

Use this form if you only have one argument to pass, which looks like the case here. Don't make an array out of one argument. Even better would be to just use _this in your script instead of _unit, because creating another variable in addition to _this is unnecessary. This of course changes when you have multiple arguments.
Title: Re:Selecting Unit Problem?
Post by: SilentHunter_764 on 06 Dec 2005, 04:36:05
Cheers for the help, gents.

Looks like ive solved the problem, but now ive got the problem of the actions on the menu. I dont want to have half a million actions, so am i going to need to put

Code: [Select]
_unit addaction <whatever action was just used> on the end of each script? So, after youve chosen an action it will pop back up?

Thanks in advance,
Kannon
Title: Re:Selecting Unit Problem?
Post by: Triggerhappy on 06 Dec 2005, 22:17:33
no, just give them the action once, at the beginning
as long as you don't remove the action, it will stay there forever, and is reuseable
Title: Re:Selecting Unit Problem?
Post by: Sui on 07 Dec 2005, 01:31:39
You can also name the action, thereby making it removeable via script.

eg.
Quote
action1 = _unit addaction ["Engage at will!","engage.sqs"]

...

_unit removeacton action1

But as Triggerhappy pointed out, the action will only be removed if you physically remove it via removeaction. The player clicking on it won't remove it.
Title: Re:Selecting Unit Problem?
Post by: SilentHunter_764 on 07 Dec 2005, 04:08:36
Yep, Ive got it down-pat now.

The scripts now read:

Code: [Select]
_unit = _this select 0

_unit switchmove "fxangel"
~2
exit

etc.

Ive also got the animation for returning to regular stance;

Code: [Select]
_unit = _this select 0

_unit switchmove " "

But now ive got the problem that when you return to the standard animation - your stuck (cant move).

Thankyou SO MUCH for the help so far!

Cheers,
Kannon

EDIT: Ah, yes. I tested not having the addaction after the script and it does remain on the menu. Cheers Triggerhappy.