-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathInteriorFallFix.inc
109 lines (93 loc) · 3.26 KB
/
InteriorFallFix.inc
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
/*
- This include helps fix the annoying issue where a player, after teleporting to an interior,
- falls through the floor due to connection problems.
- The script will teleport the player back to their last teleportation location if it detects that the player is falling.
- This include works on a Plug and Play principle.
- In other words, to make it work, you just need to include it as an include right after the main includes (a_samp or open.mp and anti-cheat).
- You can customize the script’s settings using a set of defines.
- For a complete fix of the issue, it’s recommended to either freeze players during teleportation or use static platforms in interiors (CreateObject).
- Version: 1.2.
- Date: 08.10.2024.
- GitHub Repo: https://github.com/timmylich/interiorfallfix
- Connect with author:
- VKontake: https://vk.com/timmylich
- Telegram: https://t.me/timmylich
*/
/*
[EN] The time that after teleportation will be checked whether the player falls in milliseconds.
[RU] Âðåìÿ, êîòîðîå ïîñëå òåëåïîðòàöèè áóäåò ïðîâåðÿòüñÿ ïàäàåò ëè èãðîê â ìèëëèñåêóíäàõ.
*/
#if !defined ifx_FixTime
#define ifx_FixTime 7000
#endif
/*
[EN] Function for getting the player's interior.
[RU] Ôóíêöèÿ äëÿ ïîëó÷åíèÿ èíòåðüåðà èãðîêà.
- %0 - playerid
*/
#if !defined ifx_GetPlayerInterior
#define ifx_GetPlayerInterior(%0) GetPlayerInterior(%0)
#endif
/*
[EN] Timing between checks in OnPlayerUpdate (ms).
[RU] Òàéìèíã ìåæäó ñðàáàòûâàíèÿìè ïðîâåðîê â OnPlayerUpdate (â ìèëëèñåêóíäàõ).
*/
#if !defined ifx_PlayerUpdateCD
#define ifx_PlayerUpdateCD 250
#endif
/*
[EN] The player's falling speed required for the script to trigger.
[RU] Ñêîðîñòü ïàäåíèÿ èãðîêà, íåîáõîäèìàÿ äëÿ ñðàáàòûâàíèÿ ñêðèïòà.
*/
#if !defined ifx_FallVelocity
#define ifx_FallVelocity 0.3
#endif
static Float:LastTP[MAX_PLAYERS][3];
static LastTPTime[MAX_PLAYERS];
static LastPlayerUpdate[MAX_PLAYERS];
// SetPlayerPos hook
stock ifx_SetPlayerPos(playerid, Float:x, Float:y, Float:z)
{
LastTPTime[playerid] = GetTickCount();
LastTP[playerid][0] = x;
LastTP[playerid][1] = y;
LastTP[playerid][2] = z;
return SetPlayerPos(playerid, x, y, z);
}
#if defined _ALS_SetPlayerPos
#undef SetPlayerPos
#else
#define _ALS_SetPlayerPos
#endif
#define SetPlayerPos ifx_SetPlayerPos
// OnPlayerUpdate hook
public OnPlayerUpdate(playerid)
{
if(GetTickCount()-ifx_PlayerUpdateCD > LastPlayerUpdate[playerid])
{
LastPlayerUpdate[playerid] = GetTickCount();
if(LastTPTime[playerid]+ifx_FixTime > GetTickCount() && ifx_GetPlayerInterior(playerid))
{
static Float:FallVelocity;
GetPlayerVelocity(playerid, FallVelocity, FallVelocity, FallVelocity);
if(FallVelocity < -ifx_FallVelocity)
{
SetPlayerPos(playerid, LastTP[playerid][0], LastTP[playerid][1], LastTP[playerid][2]);
}
}
}
#if defined ifx_OnPlayerUpdate
return ifx_OnPlayerUpdate(playerid);
#else
return 1;
#endif
}
#if defined _ALS_OnPlayerUpdate
#undef OnPlayerUpdate
#else
#define _ALS_OnPlayerUpdate
#endif
#define OnPlayerUpdate ifx_OnPlayerUpdate
#if defined ifx_OnPlayerUpdate
forward ifx_OnPlayerUpdate(playerid);
#endif