OFPEC Forum

Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: bigdave003 on 27 Jun 2006, 20:41:44

Title: Compass
Post by: bigdave003 on 27 Jun 2006, 20:41:44
Is there a way to enable and disable the compass during a mission? With addAction or radio triggers?
Title: Re: Compass
Post by: bedges on 27 Jun 2006, 20:54:20
always check the comref (http://www.ofpec.com/COMREF/index.php?action=list&letter=s#showCompass) first.
Title: Re: Compass
Post by: bigdave003 on 27 Jun 2006, 21:05:55
Probably should have said, but I checked the comref, and that command only works when used in description.ext - i.e the compas status can be defined this way at the start of the mission, but can't be changed this way.
Title: Re: Compass
Post by: bedges on 27 Jun 2006, 21:57:12
really?

check attached missionette.

[attachment deleted by admin]
Title: Re: Compass
Post by: bigdave003 on 27 Jun 2006, 22:10:10
I stand corrected! In that case, the problem could well be in my scripts - I wanted to script it so that one player has the action to enable or disable the compass (while others do not), so I cobbled these together:

cenable.sqs:
Code: [Select]
_this = _this select 0

showCompass True

~2

_this addAction ["Disable Compass","cdisable.sqs"]

~1

exit

cdisable.sqs:
Code: [Select]
_this = _this select 0

showCompass False

~2

_this addAction ["Enable Compass","cenable.sqs"]

~1

exit

Then in the units init line, I put:

Code: [Select]
[this] exec "cenable.sqs"
And when I previewed, I got the black line at the top of the screen with the # after the
Code: [Select]
_this addAction ["Enable Compass","cenable.sqs"]part of the script.
I'm not great at scripting, so could anyone help?
Title: Re: Compass
Post by: bedges on 27 Jun 2006, 22:20:04
don't use _this as a variable, as it is reserved.

cenable.sqs
Code: [Select]
_unit = _this select 0

showCompass True
_unit removeaction encomp
discomp = _unit addAction ["Disable Compass","cdisable.sqs"]

exit

cdisable.sqs
Code: [Select]
_unit = _this select 0

showCompass false
_unit removeaction discomp
encomp = _unit addAction ["Enable Compass","cenable.sqs"]

exit

note the assigning of the action to a global variable. this enables the removal of actions so you don't get multiple actions piling up in the action menu.

in the unit's init line, use

Code: [Select]
encomp = this addAction ["Enable Compass","cenable.sqs"]
Title: Re: Compass
Post by: bigdave003 on 27 Jun 2006, 22:37:38
Works a treat, cheers bedges!
Title: Re: Compass
Post by: h- on 27 Jun 2006, 22:40:18
Quote
note the assigning of the action to a global variable.
You can (and should) disable the actions and avoid multiple ones without assigning them as global variables...

Code: [Select]
_unit = _this select 0
_id = _this select 2

showCompass True
_unit removeaction _id
_unit addAction ["Disable Compass","cdisable.sqs"]

Code: [Select]
_unit = _this select 0
_id = _this select 2

showCompass false
_unit removeaction _id
_unit addAction ["Enable Compass","cenable.sqs"]

When you use addAction it automatically 'feeds' an array 'into' the script:
Code: [Select]
[unit the action is attached to, unit using the action, action id]
Title: Re: Compass
Post by: bedges on 27 Jun 2006, 23:10:35
we teach and learn at the same time ;)

excellent method there, go with the above. much more elegant.