Zamknięty szlaban

Moderator: Inkwizytor

ODPOWIEDZ
Awatar użytkownika
Artek3333
Posty: 578
Rejestracja: 29 czerwca 2007, 20:02
ID Steam:
ID gracza: 0
Lokalizacja: Żywiec

Zamknięty szlaban

Post autor: Artek3333 »

Jaka Komeda jest aby szlaban był w dolnej pozycji, czyli zamknięty i jaką Komedą powodujemy otwarcie szlabanu. Grałem kiedyś w jakąś misje gdzie był ten trik zastosowany, :? ale nie mogę tej misji odnaleść. :roll: Z góry dziękuje za pomoc. :coffee
Awatar użytkownika
aszek
Posty: 133
Rejestracja: 11 lipca 2008, 06:17
ID Steam:
Numer GG: 8568774
ID gracza: 0

Re: Zamknięty szlaban

Post autor: aszek »

a = position this nearestObject 3195;
a animate ["Dvere1", 1];

jakoś tak, albo "Dvere2".
"True glory consists in doing what deserves to be written, in writing what deserves to be read." - Pliny The Elder
Awatar użytkownika
Artek3333
Posty: 578
Rejestracja: 29 czerwca 2007, 20:02
ID Steam:
ID gracza: 0
Lokalizacja: Żywiec

Re: Zamknięty szlaban

Post autor: Artek3333 »

Nie działa :no
Awatar użytkownika
aszek
Posty: 133
Rejestracja: 11 lipca 2008, 06:17
ID Steam:
Numer GG: 8568774
ID gracza: 0

Re: Zamknięty szlaban

Post autor: aszek »

Swojej misji z odzwiernym nie mogę znaleść. Przyplątało za to mi się coś takiego, nie gwarantuje że zadziała, ale może pomoże:

opengate.sqs and closegate.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.

opengate.sqs 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:
A negative input rotational angle will be converted to a positive angle. 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 exactly to where it started.



closegate.sqs 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




Sample mission:
You start within a stockade. Each wall of the stockade has a gate. Open, and close, each of the gates making sure you exit the stockade before closing the last gate. All of these gates open in a clockwise direction. Then go to the adjacent stockade. That stockade is set at an angle to the first to show that the script is not dependant on the orientation of the wall in anyway. This second stockade also has a gate in each of its four walls. These gates open anti-clockwise.


Note that there is a 'feature' of OFP that makes such movements not very precise. (Try: gate setPos getPos gate where gate is a wire object to see what I mean). I have corrected this for a wire object - but bear in mind that repeated opening and closing of the same gate could result in a gap appearing at one side or another of the gate due to cumulative small inaccuracies. Using objects that are not 'wire' objects may need to have a different correction applied in the script. If you are using 'wire' objects and only opening the gate a couple of times all will be well.

I would be very grateful for any comments.


Please let me know what you think.


THobson


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
z .sqm.a:

Kod: Zaznacz cały

"opengateAction = this addAction [""Open gate"",{opengate0.sqs}] ";
"True glory consists in doing what deserves to be written, in writing what deserves to be read." - Pliny The Elder
Awatar użytkownika
Artek3333
Posty: 578
Rejestracja: 29 czerwca 2007, 20:02
ID Steam:
ID gracza: 0
Lokalizacja: Żywiec

Re: Zamknięty szlaban

Post autor: Artek3333 »

Próbowałem różnych kombinacji. Bez rezultatu same ”error” :?:
Awatar użytkownika
aszek
Posty: 133
Rejestracja: 11 lipca 2008, 06:17
ID Steam:
Numer GG: 8568774
ID gracza: 0

Re: Zamknięty szlaban

Post autor: aszek »

Ten skrypt co wkleiłem wcześniej to było lekkie nieporozumienie. A ten "Dvere1" to też była pomyłka, ostatnio bawiłem się z polem naftowym w okolicy Cayo i jakoś mi tak się skojarzyło. To powinno działać:

zamykanie z animacją:

Kod: Zaznacz cały

this animate ["Bargate", 0];
otwieranie:

Kod: Zaznacz cały

this animate ["Bargate", 1];
Można samemu pogrzebać w configu 'buildings', jest tam defiicja klasy (wejścia do baru ;p), dla jasności kawałek tutaj:

class ZavoraAnim: NonStrategic
{
{
class BarGate
{
animPeriod=6;
};
};
class UserActions
{
class OpenGate
{
displayNameDefault="$STR_DN_OUT_O_DOOR_DEFAULT";
displayName="$STR_DN_OUT_O_GATE";
position="osa_zavora";
radius=3;
onlyForPlayer=1;
condition="this animationPhase ""Bargate"" >= 0.5";
statement="this animate [""Bargate"", 0]";
};
class CloseGate
{
displayNameDefault="$STR_DN_OUT_C_DOOR_DEFAULT";
displayName="$STR_DN_OUT_C_GATE";
position="osa_zavora";
radius=3;
onlyForPlayer=1;
condition="this animationPhase ""Bargate"" < 0.5";
statement="this animate [""Bargate"", 1]";
};
};
actionBegin1="OpenGate";
actionEnd1="OpenGate";
};


z tąd wiadomo co wpisać danemu obiektowi.
"True glory consists in doing what deserves to be written, in writing what deserves to be read." - Pliny The Elder
Awatar użytkownika
Artek3333
Posty: 578
Rejestracja: 29 czerwca 2007, 20:02
ID Steam:
ID gracza: 0
Lokalizacja: Żywiec

Re: Zamknięty szlaban

Post autor: Artek3333 »

Dziękuje aszek, jesteś wielki. Dałeś mi wyczerpującą lekcje. Obserwuje twoje posty cały czas i twierdze ” dobrze, że jest ktoś tak pomocny na tym forum” Pozdrawiam. :hapy
ODPOWIEDZ

Wróć do „Edytor - tworzenie misji, skrypty oraz programowanie”