


Moderator: Inkwizytor
Kod: Zaznacz cały
; opengate.sqs by THobson - October 2004
; This script was inspired by macguba's Un-Impossible Mission. In that mission macguba has a gate that opens.
; That implementation worked well but was specific to the particular layout of the objects used in that mission.
; This script is more general and does not depend on the original direction of the objects involved.
; It also will rotate the object through a specified angle about one end as if it were attached by a hinge
; to the object next to it. The ability to close the gate is also provided.
; The only requirement of this script is that there be an object of the same type
; as the 'gate' object. That object should be placed to the right of, and facing in
; the same direction as, the 'gate' object. This object will be the 'hinge' object
; and the point where this object and the gate touch will be the hinge point of the rotation.
; If you want the hinge on the left of the gate in the mission then simply turn the objects through
; 180 degrees in the editor (and still put the hinge in the right - looking in the direction of the gate).
; In the mission the hinge will now be on the other side of the gate.
;This script is called by:
; [gate,hinge,clockwise,openangle] exec "opengate.sqs"
; where:
; gate is the name of the object to be moved
; hinge is the name of an object of the same type placed to the right of gate
; clockwise is a boolean = true for a clockwise rotation of the gate; = false for anti-clockwise rotation
; openangle is the number of degrees that the gate object will be rotated by
; NB:
; Negative input angles will be converted to positive angles. Whole rotations will be ignored.
; and the opening rotation angle will be limited to 170 degrees.
; NB NB:
; If you plan to implement the closegate action then you should limit the angle of opening to
; a maximum of 140 degrees (less if possible). Any more than that will result in some inaccuracies
; in the real arithmetic calculation of the initial conditions for the closegate script. Those
; inaccuracies will result in the gate not returning to where it started.
_gate = _this select 0
_hinge = _this select 1
_clockwise = _this select 2
_openangle = _this select 3
; OK let's not be silly
_openangle = abs(_openangle) % 360
if (_openangle > 170) then {_openangle = 170}
;For some reason the variable _alphainc needs to be created before initialisation in the 'if' statement below
_alphainc = 0
if (_clockwise) then {_alphainc = 1} else {_alphainc = -1}
_dir = getDir _gate
_x1 = getPos _gate select 0
_y1 = getPos _gate select 1
_z1 = getPos _gate select 2
_x2 = getPos _hinge select 0
_y2 = getPos _hinge select 1
_halfgatelength = (_hinge distance _gate)/2
; the next line seems to be necessary
_halfgatelength = _halfgatelength - 0.3
; (_xh,_yh) is the hinge point around which the gate will rotate
_xh = (_x1 + _x2)/2
_yh = (_y1 + _y2)/2
_alpha = 0
#loop
~0.01
_alpha = _alpha + _alphainc
_newdir = _dir + _alpha
_gate setDir _newdir
_gate setPos [_xh - _halfgatelength *cos(_newdir),_yh + _halfgatelength *sin(_newdir), _z1]
if ((abs _alpha) < abs(_openangle)) then {goto "loop"}
exit
Kod: Zaznacz cały
; closegate.sqs by THobson - October 2004
;This script closes the gate opened by opengate.sqs.
;It is called by:
; [gate,hinge,clockwise] exec "closegate.sqs"
; where:
; gate is the name of the object to be moved
; hinge is the name of an object of the same type placed to the right of gate
; clockwise is a boolean = true for a clockwise rotation of the gate; = false for anti-clockwise rotation
; NB it would be normal for clockwise when closing the gate to be the inverse of when opening the gate
_gate = _this select 0
_hinge = _this select 1
_clockwise = _this select 2
_theta = getDir _hinge
_thetaPlusalpha = getDir _gate
_startalpha = abs((360 + _thetaPlusalpha - _theta)) % 360
_dist = (_hinge distance _gate)
_halfgatelength = abs(_dist/(2*cos(_startalpha/2)))
;The next line seems to be necessary
_halfgatelength = _halfgatelength - 0.3
_z1 = getPos _gate select 2
_x2 = getPos _hinge select 0
_y2 = getPos _hinge select 1
; (_xh,_yh) is the hinge point around which the gate will rotate
_xh = _x2 - _halfgatelength * cos(_theta)
_yh = _y2 + _halfgatelength * sin(_theta)
;For some reason the variable _alphainc needs to be created before initialisation in the 'if' statement below
_alphainc = 0
if (_clockwise) then {_alphainc = 1} else {_alphainc = -1}
_dir = _theta
_alpha = _startalpha
#loop
~0.01
_alpha = _alpha + _alphainc
_newdir = _dir + _alpha
_gate setDir _newdir
_gate setPos [_xh - _halfgatelength *cos(_newdir),_yh + _halfgatelength *sin(_newdir), _z1]
if (((abs (_newdir - _theta)) % 360) > abs(0.75*_alphainc)) then {goto "loop"}
exit
Kod: Zaznacz cały
"opengateAction = this addAction [""Open gate"",{opengate0.sqs}] ";
Kod: Zaznacz cały
this animate ["Bargate", 0];
Kod: Zaznacz cały
this animate ["Bargate", 1];