-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvehicle-parasol.pwn
218 lines (154 loc) · 5.11 KB
/
vehicle-parasol.pwn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* The original code is copyright (c) 2024, shierru (Nikita).
*/
#define STRONG_TAGS
#include <open.mp>
/* YSI */
#define YSI_NO_HEAP_MALLOC
// Coding
#include <YSI_Coding\y_timers>
// Data
#include <YSI_Data\y_iterate>
/* MapAndreas */
#include <mapandreas>
/* Macros */
#define GRAVITY_DEFAULT 0.008
#define GRAVITY_JUMP 0.004
#define VEHICLE_MODEL 411
#define VEHICLE_OBJECT_MODELID 18849
#define INACCURACY_VALUE 1.000
#define VELOCITY_VALUE RandomFloat(0.400, 0.750)
#define TIMER_INTERVAL 500
/* Variables */
new Float:g_Gravity = 0.0;
// Vehicle
new Timer:g_VehicleTimer[MAX_VEHICLES] = {Timer:-1, ...};
new g_VehicleObjectID[MAX_VEHICLES] = {INVALID_OBJECT_ID, ...};
/* Functions */
stock Float:GetVehicleSpeed(const vehicleid)
{
if(!IsValidVehicle(vehicleid))
return 0.0;
new Float:velocityX = 0.0,
Float:velocityY = 0.0,
Float:velocityZ = 0.0;
new Float:velocitySqroot = 0.0;
GetVehicleVelocity(vehicleid, velocityX, velocityY, velocityZ);
velocitySqroot = floatsqroot((velocityX * velocityX) + (velocityY * velocityY) + (velocityZ * velocityZ));
return floatround(velocitySqroot * 100);
}
stock void:VehicleObject(const vehicleid)
{
if(!IsValidVehicle(vehicleid))
return;
g_VehicleObjectID[vehicleid] = CreateObject(VEHICLE_OBJECT_MODELID, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
SetObjectMaterial(g_VehicleObjectID[vehicleid], 2, 0, "none", "none", 0x00000000);
AttachObjectToVehicle(g_VehicleObjectID[vehicleid], vehicleid, 0.0, 0.0, 6.62000, 0.0, 0.0, 0.0);
}
stock void:VehicleObjectDestroy(const vehicleid)
{
if(!IsValidObject(g_VehicleObjectID[vehicleid]))
return;
DestroyObject(g_VehicleObjectID[vehicleid]);
g_VehicleObjectID[vehicleid] = INVALID_OBJECT_ID;
}
stock void:VehicleTimerStop(const vehicleid)
{
if(g_VehicleTimer[vehicleid] == Timer:-1)
return;
stop g_VehicleTimer[vehicleid];
g_VehicleTimer[vehicleid] = Timer:-1;
}
stock bool:VehicleJump(const vehicleid)
{
if(!IsValidVehicle(vehicleid))
return false;
new Float:speed = (GetVehicleSpeed(vehicleid) + 25);
new Float:posX = 0.0,
Float:posY = 0.0,
Float:posZ = 0.0,
Float:angle = 0.0;
new Float:velocityX = 0.0,
Float:velocityY = 0.0,
Float:velocityZ = 0.0;
GetVehiclePos(vehicleid, posX, posY, posZ);
GetVehicleZAngle(vehicleid, angle);
GetVehicleVelocity(vehicleid, velocityX, velocityY, velocityZ);
angle = 360 - angle;
new Float:sine = floatsin(angle, degrees),
Float:cosine = floatcos(angle, degrees);
velocityX = ((sine * (speed / 100)) + ((cosine * 0) + posX)) - posX;
velocityY = ((cosine * (speed / 100)) + ((sine * 0) + posY)) - posY;
return SetVehicleVelocity(vehicleid, velocityX, velocityY, VELOCITY_VALUE);
}
/* Callbacks */
timer CheckLandingTimer[TIMER_INTERVAL](vehicleid)
{
new Float:posX = 0.0,
Float:posY = 0.0,
Float:posZ = 0.0;
new Float:averageZ = 0.0;
GetVehiclePos(vehicleid, posX, posY, posZ);
MapAndreas_FindAverageZ(posX, posY, averageZ);
if((posZ - averageZ) < INACCURACY_VALUE)
{
foreach(new i: Player)
{
if(GetPlayerVehicleID(i) != vehicleid)
continue;
if(GetPlayerState(i) != PLAYER_STATE_DRIVER)
continue;
SetPlayerGravity(i, g_Gravity);
break;
}
VehicleObjectDestroy(vehicleid);
VehicleTimerStop(vehicleid);
}
}
public OnFilterScriptInit()
{
g_Gravity = GetConsoleVarAsFloat("game.gravity");
if(!g_Gravity)
g_Gravity = GRAVITY_DEFAULT;
MapAndreas_Init(MAP_ANDREAS_MODE_FULL);
}
public OnPlayerKeyStateChange(playerid, KEY:newkeys, KEY:oldkeys)
{
new PLAYER_STATE:player_state = GetPlayerState(playerid);
if(player_state != PLAYER_STATE_DRIVER)
return true;
new vehicleid = GetPlayerVehicleID(playerid);
if(!IsValidVehicle(vehicleid))
return true;
new modelid = GetVehicleModel(vehicleid);
if(modelid != VEHICLE_MODEL)
return true;
if(newkeys != KEY_CROUCH)
return true;
if(g_VehicleTimer[vehicleid] != Timer:-1 && g_VehicleObjectID[vehicleid] != INVALID_OBJECT_ID)
return true;
VehicleObject(vehicleid);
new bool:ret = VehicleJump(vehicleid);
if(ret)
{
SetPlayerGravity(playerid, GRAVITY_JUMP);
g_VehicleTimer[vehicleid] = repeat CheckLandingTimer(vehicleid);
}
return true;
}
public OnVehicleDeath(vehicleid, killerid)
{
VehicleObjectDestroy(vehicleid);
VehicleTimerStop(vehicleid);
return true;
}
public OnVehicleSpawn(vehicleid)
{
VehicleObjectDestroy(vehicleid);
VehicleTimerStop(vehicleid);
return true;
}