View difference between Paste ID: f2e9ba0f1 and
SHOW:
|
|
- or go back to the newest paste.
1 | - | |
1 | + | -- GTAIV MegaJump Script |
2 | -- by Simon. Based off Alexander Blade's example scripts. | |
3 | ||
4 | -- Global Variables | |
5 | PLAYER_ID, PLAYER_CHAR = 0, PLAYER_INDEX | |
6 | ||
7 | function SetCharVelocity(char, velocity_x, velocity_y, velocity_z) | |
8 | -- Wrapper for: SET_CHAR_VELOCITY=4, False | |
9 | ||
10 | PushInt(char) | |
11 | PushFloat(velocity_x) | |
12 | PushFloat(velocity_y) | |
13 | PushFloat(velocity_z) | |
14 | CallNative("SET_CHAR_VELOCITY") | |
15 | end | |
16 | ||
17 | function GetCharVelocity(char, velocity_x, velocity_y, velocity_z) | |
18 | -- Wrapper for: GET_CHAR_VELOCITY=4, False | |
19 | ||
20 | PushInt(char) | |
21 | PushVarPtr() | |
22 | PushVarPtr() | |
23 | PushVarPtr() | |
24 | ||
25 | velocity_x = GetFloatParam(1) | |
26 | velocity_y = GetFloatParam(2) | |
27 | velocity_z = GetFloatParam(3) | |
28 | ||
29 | CallNative("GET_CHAR_VELOCITY") | |
30 | end | |
31 | ||
32 | function GetCharHeading(char, z_angle) | |
33 | ||
34 | -- Wrapper for: GET_CHAR_HEADING=2, False | |
35 | PushInt(char) | |
36 | PushVarPtr() | |
37 | ||
38 | z_angle = GetFloatParam(1) | |
39 | end | |
40 | ||
41 | -- | |
42 | ||
43 | function InitScript() | |
44 | -- blah-blah-blah | |
45 | Wait(10000) | |
46 | end | |
47 | ||
48 | function WaitForPlayerPoolCreation() | |
49 | while (IsPlayerPoolCreated() == 0) do | |
50 | Wait(2000) | |
51 | end | |
52 | end | |
53 | ||
54 | function WaitForValidPlayer() | |
55 | PLAYER_CHAR = 0 | |
56 | repeat | |
57 | CallNative("GET_PLAYER_ID") | |
58 | PLAYER_ID = GetIntResult() | |
59 | if (PLAYER_ID >= 0) then | |
60 | PushInt(PLAYER_ID) | |
61 | CallNative("CONVERT_INT_TO_PLAYERINDEX") | |
62 | PLAYER_INDEX = GetIntResult() | |
63 | PushInt(PLAYER_INDEX) | |
64 | PushVarPtr() | |
65 | CallNative("GET_PLAYER_CHAR") | |
66 | PLAYER_CHAR = GetIntParam(1) | |
67 | if (PLAYER_CHAR <= 0) then | |
68 | Wait(1000) | |
69 | end | |
70 | end | |
71 | until (PLAYER_CHAR > 0) | |
72 | end | |
73 | ||
74 | function main() | |
75 | InitScript() | |
76 | ||
77 | while true do | |
78 | WaitForPlayerPoolCreation() | |
79 | WaitForValidPlayer() | |
80 | ||
81 | if (IsKeyPressed(9) == 1) then | |
82 | if (IsKeyPressed(16) == 1) then -- shift (default: sprint) | |
83 | local velocity_x, velocity_y, velocity_z | |
84 | ||
85 | PushInt(PLAYER_INDEX) | |
86 | PushInt(1) | |
87 | ||
88 | CallNative("SET_PLAYER_INVINCIBLE") | |
89 | ||
90 | PushInt(PLAYER_CHAR) | |
91 | PushVarPtr() | |
92 | PushVarPtr() | |
93 | PushVarPtr() | |
94 | ||
95 | CallNative("GET_CHAR_VELOCITY") | |
96 | ||
97 | velocity_x = (GetFloatParam(1) * 3.0) | |
98 | velocity_y = (GetFloatParam(2) * 3.0) | |
99 | velocity_z = GetFloatParam(3) | |
100 | ||
101 | if ( velocity_z > -1.5 and velocity_z < 1.5 ) then -- just gonna assume a player is falling/jumping if z velocity is not between -1.5 and 1.5 | |
102 | SetCharVelocity(PLAYER_CHAR, velocity_x, velocity_y, velocity_z) | |
103 | end | |
104 | ||
105 | ||
106 | end | |
107 | ||
108 | if (IsKeyPressed(32) == 1) then -- space (default: jump) | |
109 | local velocity_x, velocity_y, velocity_z | |
110 | ||
111 | PushInt(PLAYER_INDEX) | |
112 | PushInt(1) | |
113 | ||
114 | CallNative("SET_PLAYER_INVINCIBLE") | |
115 | ||
116 | PushInt(PLAYER_CHAR) | |
117 | PushVarPtr() | |
118 | PushVarPtr() | |
119 | PushVarPtr() | |
120 | ||
121 | CallNative("GET_CHAR_VELOCITY") | |
122 | ||
123 | velocity_x = (GetFloatParam(1) * 20.0) | |
124 | velocity_y = (GetFloatParam(2) * 20.0) | |
125 | velocity_z = GetFloatParam(3) | |
126 | ||
127 | if ( velocity_z > -1.5 and velocity_z < 1.5 ) then -- just gonna assume a player is falling/jumping if z velocity is not between -1.5 and 1.5 | |
128 | SetCharVelocity(PLAYER_CHAR, velocity_x, velocity_y, 20.0) | |
129 | end | |
130 | end | |
131 | end | |
132 | ||
133 | Wait(50) | |
134 | end | |
135 | end | |
136 | ||
137 | -- start | |
138 | main(); |