Moving gate

From GTAMods Wiki
Jump to navigation Jump to search

This is a code snippet of a moving gate in Sanny Builder's format and should work in GTA III, Vice City, and San Andreas. This code is based on the moving gates, including the sound it makes, in GTA III. Remember to read the tutorial on how to create a thread before proceeding to implement this code.

 1 // set constants
 2 const
 3 OBJECT = #ELECTRICGATE // you can use any object you want but make sure it's valid
 4                        //  use object's IDE number in CLEO instead
 5 INITI_X = 298.0        // initial x position
 6 INITI_Y = -313.6       // initial y position
 7 INITI_Z = 11.0         // initial z position
 8 ANGLE = 0.0            // angle of your gate
 9 FINAL_X = 304.0        // final x position
10 FINAL_Y = -313.6       // final y position
11 FINAL_Z = 11.0         // final z position
12 
13 gate_sfx1 = 1@
14 not_clunked_yet = 2@
15 gate_sfx2 = 3@
16 objectx = 4@
17 objecty = 5@
18 objectz = 6@
19 end
20 
21 // create gate object
22 029B: 0@ = init_object OBJECT at INITI_X INITI_Y INITI_Z
23 01C7: remove_object_from_mission_cleanup_list 0@
24 0177: set_object 0@ z_angle_to ANGLE
25 
26 while true
27     wait 250 ms
28     if
29         0256:   player $PLAYER_CHAR defined
30     then
31         if
32             // use other area check opcodes for more precision and options
33             00FE:   actor $PLAYER_ACTOR in_sphere 0 near_point INITI_X INITI_Y INITI_Z radius 5.0 5.0 5.0
34         then
35             if
36                 gate_sfx1 == 0
37             then
38                 //018C: play_sound 92 at INITI_X INITI_Y INITI_Z // uncomment for III
39                 //018C: play_sound 3 at INITI_X INITI_Y INITI_Z  // uncomment for VC
40                 //097B: play_audio_at_object 0@ event 1100       // uncomment for SA
41                 gate_sfx1 = 1
42             end
43             while if 834E:   not move_object 0@ to FINAL_X FINAL_Y FINAL_Z speed 0.1 0.1 0.0 flag 0
44                 wait 0 ms
45             end
46             if
47                 not_clunked_yet == 1
48             then
49                 gate_sfx2 = 0
50                 not_clunked_yet = 0
51             end
52             if
53                 gate_sfx2 == 0
54             then
55                 //018C: play_sound 93 at FINAL_X FINAL_Y FINAL_Z // uncomment for III
56                 //018C: play_sound 3 at FINAL_X FINAL_Y FINAL_Z  // uncomment for VC
57                 //097B: play_audio_at_object 0@ event 1101       // uncomment for SA
58                 gate_sfx2 = 1
59             end
60         else
61             if
62                 gate_sfx1 == 1
63             then
64                 //018C: play_sound 92 at FINAL_X FINAL_Y FINAL_Z // uncomment for III
65                 //018C: play_sound 3 at FINAL_X FINAL_Y FINAL_Z  // uncomment for VC
66                 //097B: play_audio_at_object 0@ event 1100       // uncomment for SA
67             end
68             while if 834E:   not move_object 0@ to INITI_X INITI_Y INITI_Z speed 0.1 0.1 0.0 flag 1
69                 wait 0 ms
70             end
71             01BB: store_object 0@ position_to objectx objecty objectz
72             if
73                 gate_sfx2 == 1
74             then
75                 not_clunked_yet = 1
76                 if and
77                     objectx == INITI_X
78                     objecty == INITI_Y
79                     objectz == INITI_Z
80                 then
81                     //018C: play_sound 93 at INITI_X INITI_Y INITI_Z // uncomment for III
82                     //018C: play_sound 3 at INITI_X INITI_Y INITI_Z  // uncomment for VC
83                     //097B: play_audio_at_object 0@ event 1101       // uncomment for SA
84                     gate_sfx2 = 0
85                     not_clunked_yet = 0
86                 end
87                 gate_sfx1 = 0
88             end
89         end
90     end
91 end