OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started 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?
-
always check the comref (http://www.ofpec.com/COMREF/index.php?action=list&letter=s#showCompass) first.
-
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.
-
really?
check attached missionette.
[attachment deleted by admin]
-
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:
_this = _this select 0
showCompass True
~2
_this addAction ["Disable Compass","cdisable.sqs"]
~1
exit
cdisable.sqs:
_this = _this select 0
showCompass False
~2
_this addAction ["Enable Compass","cenable.sqs"]
~1
exit
Then in the units init line, I put:
[this] exec "cenable.sqs"
And when I previewed, I got the black line at the top of the screen with the # after the
_this addAction ["Enable Compass","cenable.sqs"]part of the script.
I'm not great at scripting, so could anyone help?
-
don't use _this as a variable, as it is reserved.
cenable.sqs
_unit = _this select 0
showCompass True
_unit removeaction encomp
discomp = _unit addAction ["Disable Compass","cdisable.sqs"]
exit
cdisable.sqs
_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
encomp = this addAction ["Enable Compass","cenable.sqs"]
-
Works a treat, cheers bedges!
-
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...
_unit = _this select 0
_id = _this select 2
showCompass True
_unit removeaction _id
_unit addAction ["Disable Compass","cdisable.sqs"]
_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:
[unit the action is attached to, unit using the action, action id]
-
we teach and learn at the same time ;)
excellent method there, go with the above. much more elegant.