Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New version #1

Open
wants to merge 231 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 152 commits
Commits
Show all changes
231 commits
Select commit Hold shift + click to select a range
1d1519f
new custom entities api
Hedgefog Jul 22, 2023
9f16803
add player dizziness api
Hedgefog Jul 22, 2023
8316048
update log message
Hedgefog Jul 23, 2023
4d5ff38
add custome animations system
Hedgefog Jul 23, 2023
5c2bb6b
fix PlayerModel_Get native args
Hedgefog Jul 23, 2023
da3d8ac
move allocated classname string to global var
Hedgefog Jul 23, 2023
1190e82
update player model api
Hedgefog Jul 24, 2023
0439bd6
improve model reset
Hedgefog Jul 24, 2023
7558ae7
fix corpse model
Hedgefog Jul 24, 2023
e509948
improve player model api
Hedgefog Jul 24, 2023
f277b98
update player model api
Hedgefog Jul 24, 2023
05ddcd6
update natives error
Hedgefog Jul 24, 2023
dba0d6a
update custom entities api
Hedgefog Jul 25, 2023
af8c12a
fix memory leaks
Hedgefog Jul 25, 2023
5b37eb2
fix model update
Hedgefog Jul 25, 2023
eb2d042
fix naming
Hedgefog Jul 25, 2023
99c0c6b
add init function
Hedgefog Jul 26, 2023
b35e9ea
add think function
Hedgefog Jul 27, 2023
e538944
update CheckWinConditions forward
Hedgefog Jul 27, 2023
93f686d
add touch function
Hedgefog Jul 27, 2023
09398ff
add default value for origin
Hedgefog Jul 27, 2023
25eda8d
fix get pdata
Hedgefog Jul 27, 2023
183e8e5
fix init function
Hedgefog Jul 27, 2023
c329d9f
fix next kill handle
Hedgefog Jul 27, 2023
54ef28a
fix temp flag
Hedgefog Jul 27, 2023
c02a904
add CE_DeleteMember native
Hedgefog Jul 27, 2023
f8a601e
add restart function
Hedgefog Jul 29, 2023
45af9ff
add navsystem api (alpha)
Hedgefog Aug 3, 2023
ed291e7
fix callback logic
Hedgefog Aug 6, 2023
8e8b2f5
add sync job termination
Hedgefog Aug 7, 2023
d0c0ee1
fix SetString method
Hedgefog Aug 9, 2023
8f6bbaf
add inventory api
Hedgefog Aug 9, 2023
12cf015
add cosmetics api
Hedgefog Aug 9, 2023
1bb5272
fix api headers
Hedgefog Aug 9, 2023
7bccbe1
fix think
Hedgefog Aug 9, 2023
bb044e4
fix inventory slots saving
Hedgefog Aug 9, 2023
ce2670a
add blood color
Hedgefog Aug 10, 2023
dd8f327
add fire entity
Hedgefog Aug 11, 2023
16ff7d8
update custom entities api
Hedgefog Aug 11, 2023
6533348
update repo structure
Hedgefog Aug 11, 2023
f3988f0
update player inventory api
Hedgefog Aug 12, 2023
41d7858
fire scale now depends on the burning object size
Hedgefog Aug 12, 2023
a2e930f
fix rounds api dir structure
Hedgefog Sep 16, 2023
76e502a
fix followed fire kill logic
Hedgefog Sep 25, 2023
814152e
update custom entities api
Hedgefog Oct 30, 2023
be11622
improve fire entity logic
Hedgefog Oct 30, 2023
69d2263
disabled spread by default
Hedgefog Oct 30, 2023
b89de4a
remove unused util
Hedgefog Oct 31, 2023
6c7ac81
fix fire think rate
Hedgefog Oct 31, 2023
a2b37c6
update custom entities api
Hedgefog Oct 31, 2023
3ee6376
remove unused include
Hedgefog Oct 31, 2023
7da44ea
update fire entity code
Hedgefog Oct 31, 2023
af15932
disable solid check for damage
Hedgefog Nov 1, 2023
f531f83
fix get string member native
Hedgefog Nov 1, 2023
e191aee
fix plugin name
Hedgefog Nov 1, 2023
6ac6674
fix return for get vector and string member natives
Hedgefog Nov 1, 2023
07308c4
add pushing system api
Hedgefog Nov 1, 2023
d1d2879
fix include
Hedgefog Nov 1, 2023
a246995
fix native params order
Hedgefog Nov 1, 2023
1f9843f
update rounds api
Hedgefog Nov 2, 2023
66df476
add forwards
Hedgefog Nov 3, 2023
04e179a
add waypoint marker api
Hedgefog Nov 5, 2023
aebe4de
fix hidden markers
Hedgefog Nov 5, 2023
a4469f7
rename advanced pushing library
Hedgefog Nov 5, 2023
cd9d072
fix params order
Hedgefog Nov 5, 2023
22d7711
fix command util
Hedgefog Nov 5, 2023
a7a62ec
rework initialization for custom entities
Hedgefog Nov 6, 2023
5847d86
add tag for custom entites handler
Hedgefog Nov 6, 2023
e57d51b
small fixes
Hedgefog Nov 6, 2023
3594c9d
update command util
Hedgefog Nov 6, 2023
148a743
update command util
Hedgefog Nov 6, 2023
869c733
update commands
Hedgefog Nov 7, 2023
54f2e08
fix auto precaching
Hedgefog Nov 7, 2023
68eb206
add datapack stocks
Hedgefog Nov 8, 2023
c7e9c51
add custom events api
Hedgefog Nov 8, 2023
81e1860
better error handler
Hedgefog Nov 8, 2023
767a59f
rework custom events
Hedgefog Nov 8, 2023
d6c2697
fix forward name
Hedgefog Nov 8, 2023
9fa850b
add custom_events_handler entity
Hedgefog Nov 8, 2023
289cc2e
fix forward params
Hedgefog Nov 8, 2023
c708007
fix marker visibility
Hedgefog Nov 8, 2023
aa5834a
fix memory leaks
Hedgefog Nov 8, 2023
5531a1a
fix semicolons
Hedgefog Nov 8, 2023
878d304
fix semicolons
Hedgefog Nov 8, 2023
70c1f96
add custom events api documentation
Hedgefog Nov 9, 2023
759d795
move MAX_CUSTOM_EVENT_KEY_LENGTH constant to header file
Hedgefog Nov 9, 2023
6a13cbe
add documentation
Hedgefog Nov 9, 2023
1cec196
fix indentation
Hedgefog Nov 9, 2023
5fa7c99
add custom weapon example
Hedgefog Nov 9, 2023
afcc091
codestyle update
Hedgefog Nov 9, 2023
cd44c67
fix plugin name
Hedgefog Nov 9, 2023
387bc19
Update README.md
Hedgefog Nov 9, 2023
5152e3a
Update README.md
Hedgefog Nov 9, 2023
5b5132a
Update README.md
Hedgefog Nov 9, 2023
469002f
Update README.md
Hedgefog Nov 9, 2023
c81cb22
add camera target
Hedgefog Nov 12, 2023
4ce12ab
update custom entities api
Hedgefog Nov 12, 2023
a4c6113
add particle system
Hedgefog Nov 14, 2023
aa1f080
remove useless params
Hedgefog Nov 14, 2023
fb36a9d
add readme
Hedgefog Nov 14, 2023
bf62252
update particles api
Hedgefog Nov 14, 2023
f411c30
Update entity_fire.sma
Hedgefog Nov 15, 2023
aee0f08
fix movetype
Hedgefog Nov 16, 2023
7b3d624
fix marker destroy
Hedgefog Nov 16, 2023
ccdee4c
fix sprite check
Hedgefog Nov 17, 2023
5f275ab
add custom rounds api for Half-Life
Hedgefog Nov 19, 2023
eaf3c2f
add axis lock option
Hedgefog Nov 19, 2023
96fb3ec
add hl support
Hedgefog Nov 19, 2023
a604c44
improve custom rounds
Hedgefog Nov 19, 2023
2e1b517
add some natives
Hedgefog Nov 19, 2023
fa49252
fix round termination
Hedgefog Nov 20, 2023
caf2589
fix hl crashes
Hedgefog Nov 21, 2023
4e80e88
fix custom rounds system
Hedgefog Nov 21, 2023
53991bc
update round messages
Hedgefog Nov 21, 2023
798245b
fix frozen flag set
Hedgefog Nov 21, 2023
8c05802
better hl support
Hedgefog Nov 21, 2023
3cb72fc
add start time native
Hedgefog Nov 22, 2023
652c4d1
fix round restart
Hedgefog Nov 22, 2023
32b2bad
fix scale calculation
Hedgefog Nov 22, 2023
698a9a3
fix visibility check for Half-Life
Hedgefog Nov 22, 2023
2f48a94
fix round system
Hedgefog Nov 22, 2023
385df40
improve custom rounds api
Hedgefog Nov 22, 2023
2e3950a
add CEFunction_Invalid constant
Hedgefog Nov 22, 2023
ce5ae4f
update readme
Hedgefog Nov 22, 2023
53675e9
fix return value
Hedgefog Nov 26, 2023
852f5c6
fix cstrike variables
Hedgefog Feb 4, 2024
f1ca040
fix touched hook
Hedgefog Feb 6, 2024
c780048
add traverse type getter for area and segment
Hedgefog Feb 26, 2024
580dfdc
add navsystem api example example
Hedgefog Feb 26, 2024
0417111
add StructCopy function
Hedgefog Feb 26, 2024
1e7e1e8
fix custom events api
Hedgefog Feb 27, 2024
1e54641
add custom methods functionality
Hedgefog Feb 27, 2024
51acf21
make datapack library optional
Hedgefog Feb 27, 2024
0af3529
fix member name
Hedgefog Feb 27, 2024
d12cfa9
fix update timer forward
Hedgefog Feb 27, 2024
05c14bd
fix for regamedll
Hedgefog Feb 27, 2024
07e1a8f
add player effects api
Hedgefog Feb 28, 2024
078d6d4
update api
Hedgefog Feb 28, 2024
86486d6
update entities
Hedgefog Feb 28, 2024
3ae950c
update player effects constants
Hedgefog Mar 1, 2024
1df9c98
add inheritance
Hedgefog Mar 1, 2024
fd564ba
particles api update
Hedgefog Mar 2, 2024
5a87509
add images
Hedgefog Mar 2, 2024
70bc080
add links
Hedgefog Mar 2, 2024
62639ac
update docs
Hedgefog Mar 2, 2024
56ca0d5
fix lang
Hedgefog Mar 2, 2024
3118360
fix initialization
Hedgefog Mar 2, 2024
481ab11
fix Nav_Area_GetClosestPointOnArea native
Hedgefog Mar 2, 2024
027110d
add Nav_Path_Segment_GetArea method
Hedgefog Mar 2, 2024
88339bb
add ladders support
Hedgefog Mar 3, 2024
b6153f4
update docs
Hedgefog Mar 3, 2024
3a159d2
fix virtual methods
Hedgefog Mar 3, 2024
e0a4755
fix camera activation pvs
Hedgefog Mar 10, 2024
21cf9f5
fix round end forward params
Hedgefog Mar 10, 2024
16ba4b9
fix system cleaning
Hedgefog Mar 10, 2024
14201e3
fix particle init
Hedgefog Mar 10, 2024
1cf689e
add cellclass util
Hedgefog Mar 10, 2024
886de02
update custom entities api
Hedgefog Mar 10, 2024
b9bf7da
optimizations
Hedgefog Mar 10, 2024
9390084
update fire entity
Hedgefog Mar 10, 2024
03481b1
fix const include
Hedgefog Mar 10, 2024
eb5c1dd
small fixes
Hedgefog Mar 10, 2024
7bffa84
fix model update
Hedgefog Mar 10, 2024
dc62542
fix fire bounding box
Hedgefog Mar 11, 2024
09e0f57
fix path positions compute
Hedgefog Mar 12, 2024
b10fccf
add entity selection api
Hedgefog Mar 13, 2024
97eae5a
add readme
Hedgefog Mar 13, 2024
ab1d04a
add animated demonstration
Hedgefog Mar 13, 2024
9d7f6b0
update selection api
Hedgefog Mar 13, 2024
7b4ed83
update readme
Hedgefog Mar 13, 2024
c9023c5
add cursor entity support
Hedgefog Mar 14, 2024
9306acb
add SetCursorPos native
Hedgefog Mar 16, 2024
f63edec
optimize cellclass performance
Hedgefog Mar 18, 2024
ea2d496
add setters and getters
Hedgefog Mar 18, 2024
29eec3a
add abstract entities
Hedgefog Mar 19, 2024
0971ba5
add base npc entity
Hedgefog Mar 19, 2024
9ce3f7c
fix priority
Hedgefog Mar 19, 2024
cc0f142
fix cursor pos native
Hedgefog Mar 19, 2024
ac0524e
improve npc logic
Hedgefog Mar 19, 2024
c97cd77
improve attack logic
Hedgefog Mar 19, 2024
d191d44
fix movement
Hedgefog Mar 20, 2024
0a578e7
update custom entities api
Hedgefog Apr 5, 2024
706ca16
add debug logging
Hedgefog Apr 5, 2024
708487d
add Nav_Path_FindTask_Await native
Hedgefog Apr 5, 2024
9f7e9d0
add WIP base monster entity
Hedgefog Apr 5, 2024
5626e1a
improve cellclass performance
Hedgefog Apr 6, 2024
e8e2fa4
add cache
Hedgefog Apr 6, 2024
06f528c
remove debug line
Hedgefog Apr 6, 2024
007c846
update for new cellclass version
Hedgefog Apr 6, 2024
f214600
improve await
Hedgefog Apr 7, 2024
df2cb25
migration to function pointers
Hedgefog Apr 9, 2024
51eefc3
fix check for function id
Hedgefog Apr 9, 2024
9c9ea75
update is_pfunc_local stock
Hedgefog Apr 9, 2024
ddfccba
fix return
Hedgefog Apr 9, 2024
dc88a49
fix buffer position
Hedgefog Apr 9, 2024
7388d94
optimizations
Hedgefog Apr 9, 2024
39bace7
small optimizations
Hedgefog Apr 10, 2024
d2e5e14
fix pointers range
Hedgefog Apr 10, 2024
1698891
update navsystem
Hedgefog Apr 12, 2024
081a5e5
fix native params
Hedgefog Apr 16, 2024
1227501
add example for monster_base entity
Hedgefog Apr 17, 2024
43dd927
add readme
Hedgefog Apr 18, 2024
4df22c7
update readme
Hedgefog Apr 18, 2024
738c7ea
update readme
Hedgefog Apr 18, 2024
d88c8ed
update readme
Hedgefog Apr 18, 2024
90b74b7
add PlayerModel_UpdateAnimation native
Hedgefog Apr 18, 2024
d334f5d
update readme
Hedgefog Apr 23, 2024
f4d5846
add future version
Hedgefog Apr 23, 2024
ba61323
update future readme
Hedgefog Apr 23, 2024
7e063df
update future doc
Hedgefog Apr 23, 2024
badace8
add doc for custom methods
Hedgefog Apr 23, 2024
72a3053
update cautions
Hedgefog Apr 23, 2024
d10d908
fix title
Hedgefog Apr 23, 2024
153d601
update syntax highlight
Hedgefog Apr 23, 2024
b515261
update methods example
Hedgefog Apr 23, 2024
cf38cca
update file names for future
Hedgefog Apr 23, 2024
9e487de
update util
Hedgefog Apr 23, 2024
eadc489
optimizations
Hedgefog Apr 24, 2024
c82c94a
fix allocate params + strict calls
Hedgefog Apr 24, 2024
058e22e
optimizations
Hedgefog Apr 24, 2024
7bfaacd
fix natives
Hedgefog Apr 24, 2024
5d63377
add ref types + fix setters/getters
Hedgefog Apr 24, 2024
3369ab8
add push forward
Hedgefog Aug 6, 2024
3e39e72
fix model user info exploit
Hedgefog Aug 14, 2024
4fda53e
add states api
Hedgefog Aug 20, 2024
0be3c3f
fix eol
Hedgefog Aug 20, 2024
3b7b0c4
add State_Manager_GetTransitionProgress native
Hedgefog Aug 20, 2024
fe14de2
add guards
Hedgefog Aug 20, 2024
e509ac9
Update README.md
Hedgefog Aug 20, 2024
402baaa
fix context id
Hedgefog Sep 14, 2024
581d976
fix state change processing during hooks call
Hedgefog Oct 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## 🛠️ Modding Kit 🇺🇦

### 📄 About
__CS Modding Kit__ is a powerful solutions for Amx Mod X modding that can be used to create complex mods for a short time with flexible solutions using a unified development approach. I continue working on this repository and plan many new solutions in the future as well as move my mods to this solution to create examples and a good code base. Focus on game logic instead of crutches for native stuff.

### ❔Why Modding Kit?
- Powerful, rasy to use and flexible game systems
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

easy*

- Unified system easy to maintain
- Cross-game development (you can create mods that will work with both **Counter-Strike** and **Half-Life**)

### 🔽 Download latest:
- [Releases](./releases)

### 🔄 Requirements
- Amx Mod X 1.9+
- RegameDLL + ReAPI (for some APIs)

### ⚙️ Available APIs
- [🫸 Advanced Pushing](./api/advanced-pushing)
- [🧸 Custom Entities](./api/custom-entities)
- [🔄 Custom Events](./api/custom-events)
- [🔫 Custom Weapons](./api/custom-weapons)
- [🎯 NavSystem](./api/navsystem)
- [💫 Particles](./api/particles)
- [🎥 Player Camera](./api/player-camera)
- [🎩 Player Cosmetics](./api/player-cosmetics)
- [🥴 Player Dizziness](./api/player-dizziness)
- [🏃‍♂️ Player Effects](./api/player-effects)
- [🎒 Player Inventory](./api/player-inventory)
- [🦸 Player Model](./api/player-model)
- [👁️ Player Viewrange](./api/player-viewrange)
- [⏱️ Rounds](./api/rounds)
- [❓ Waypoint Markers](./api/waypoint-markers)
229 changes: 229 additions & 0 deletions api/advanced-pushing/api_advanced_pushing.sma
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
#pragma semicolon 1

#include <amxmodx>
#include <hamsandwich>
#include <fakemeta>
#include <xs>

#include <api_advanced_pushing>

#define PLAYER_PREVENT_CLIMB (1<<5)

#define IS_PLAYER(%1) (%1 >= 1 && %1 <= MaxClients)

new Float:g_flPlayerReleaseClimbBlock[MAX_PLAYERS + 1];

public plugin_init() {
register_plugin("[API] Advanced Pushing", "1.0.0", "Hedgehog Fog");

RegisterHamPlayer(Ham_Spawn, "HamHook_Player_Spawn_Post", .Post = 1);
RegisterHamPlayer(Ham_Player_PostThink, "HamHook_Player_PostThink_Post", .Post = 1);
}

public plugin_natives() {
register_library("api_advanced_pushing");
register_native("APS_Push", "Native_Push");
register_native("APS_PushFromOrigin", "Native_PushFromOrigin");
register_native("APS_PushFromBBox", "Native_PushFromBBox");
}

public Native_Push(iPluginId, iArgc) {
new pEntity = get_param(1);
new Float:vecForce[3]; get_array_f(2, vecForce, sizeof(vecForce));
new APS_Flags:iFlags = APS_Flags:get_param(3);
@Base_Push(pEntity, vecForce, iFlags);
}

public Native_PushFromOrigin(iPluginId, iArgc) {
new pEntity = get_param(1);
new Float:flForce = get_param_f(2);
new Float:vecPushOrigin[3]; get_array_f(3, vecPushOrigin, sizeof(vecPushOrigin));
new APS_Flags:iFlags = APS_Flags:get_param(4);

@Base_PushFromOrigin(pEntity, flForce, vecPushOrigin, iFlags);
}

public Native_PushFromBBox(iPluginId, iArgc) {
new pEntity = get_param(1);
new Float:flForce = get_param_f(2);
new Float:vecAbsMin[3]; get_array_f(3, vecAbsMin, sizeof(vecAbsMin));
new Float:vecAbsMax[3]; get_array_f(4, vecAbsMax, sizeof(vecAbsMax));
new Float:flMinDepthRatio = get_param_f(5);
new Float:flMaxDepthRatio = get_param_f(6);
new Float:flDepthInfluenceMin = get_param_f(7);
new Float:flDepthInfluenceMax = get_param_f(8);
new APS_Flags:iFlags = APS_Flags:get_param(9);

@Base_PushFromBBox(pEntity, flForce, vecAbsMin, vecAbsMax, flMinDepthRatio, flMaxDepthRatio, flDepthInfluenceMin, flDepthInfluenceMax, iFlags);
}

public HamHook_Player_Spawn_Post(pPlayer) {
@Player_ReleaseClimbPrevention(pPlayer);
}

public HamHook_Player_PostThink_Post(pPlayer) {
if (g_flPlayerReleaseClimbBlock[pPlayer] && g_flPlayerReleaseClimbBlock[pPlayer] <= get_gametime()) {
@Player_ReleaseClimbPrevention(pPlayer);
}
}

@Player_SetClimbPrevention(pPlayer, bool:bValue) {
new iPlayerFlags = pev(pPlayer, pev_iuser3);

if (bValue) {
iPlayerFlags |= PLAYER_PREVENT_CLIMB;
} else {
iPlayerFlags &= ~PLAYER_PREVENT_CLIMB;
}

set_pev(pPlayer, pev_iuser3, iPlayerFlags);
}

@Player_ReleaseClimbPrevention(this) {
if (g_flPlayerReleaseClimbBlock[this]) {
@Player_SetClimbPrevention(this, false);
g_flPlayerReleaseClimbBlock[this] = 0.0;
}
}

@Base_Push(this, const Float:vecForce[3], APS_Flags:iFlags) {
static Float:vecVelocity[3]; pev(this, pev_velocity, vecVelocity);

if (iFlags & APS_Flag_AddForce) {
xs_vec_add(vecVelocity, vecForce, vecVelocity);
} else {
for (new i = 0; i < 3; ++i) {
if (iFlags & APS_Flag_OverlapMode) {
vecVelocity[i] = vecForce[i] ? vecForce[i] : vecVelocity[i];
} else {
vecVelocity[i] = vecForce[i];
}
}
}

set_pev(this, pev_velocity, vecVelocity);

if (IS_PLAYER(this) && ~pev(this, pev_iuser3) & PLAYER_PREVENT_CLIMB) {
@Player_SetClimbPrevention(this, true);
g_flPlayerReleaseClimbBlock[this] = get_gametime() + 0.1;
}
}

@Base_PushFromOrigin(this, Float:flForce, Float:vecPushOrigin[3], APS_Flags:iFlags) {
static Float:vecOrigin[3]; pev(this, pev_origin, vecOrigin);

static Float:vecForce[3];
xs_vec_sub(vecOrigin, vecPushOrigin, vecForce);
xs_vec_normalize(vecForce, vecForce);
xs_vec_mul_scalar(vecForce, flForce, vecForce);

@Base_Push(this, vecForce, iFlags);
}

@Base_PushFromBBox(
this,
Float:flForce,
const Float:vecAbsMin[3],
const Float:vecAbsMax[3],
Float:flMinDepthRatio,
Float:flMaxDepthRatio,
Float:flDepthInfluenceMin,
Float:flDepthInfluenceMax,
APS_Flags:iFlags
) {
static Float:vecOrigin[3]; pev(this, pev_origin, vecOrigin);
static Float:vecToucherAbsMin[3]; pev(this, pev_absmin, vecToucherAbsMin);
static Float:vecToucherAbsMax[3]; pev(this, pev_absmax, vecToucherAbsMax);

// Find and check intersection point
for (new iAxis = 0; iAxis < 3; ++iAxis) {
if (vecOrigin[iAxis] < vecAbsMin[iAxis]) {
vecOrigin[iAxis] = vecToucherAbsMax[iAxis];
} else if (vecOrigin[iAxis] > vecAbsMax[iAxis]) {
vecOrigin[iAxis] = vecToucherAbsMin[iAxis];
}

if (vecAbsMin[iAxis] >= vecOrigin[iAxis]) return;
if (vecAbsMax[iAxis] <= vecOrigin[iAxis]) return;
}

new iClosestAxis = -1;
new pTrace = create_tr2();
static Float:vecOffset[3]; xs_vec_copy(Float:{0.0, 0.0, 0.0}, vecOffset);

for (new iAxis = 0; iAxis < 3; ++iAxis) {
// Calculates the toucher's offset relative to the current axis
static Float:flSideOffsets[2];
flSideOffsets[0] = vecAbsMin[iAxis] - vecOrigin[iAxis];
flSideOffsets[1] = vecAbsMax[iAxis] - vecOrigin[iAxis];

if (iAxis == 2 && iClosestAxis != -1) {
break;
}

for (new side = 0; side < 2; ++side) {
// Check exit from current side
static Float:vecTarget[3];
xs_vec_copy(vecOrigin, vecTarget);
vecTarget[iAxis] += flSideOffsets[side];
engfunc(EngFunc_TraceMonsterHull, this, vecOrigin, vecTarget, IGNORE_MONSTERS | IGNORE_GLASS, this, pTrace);

static Float:flFraction;
get_tr2(pTrace, TR_flFraction, flFraction);

// No exit, cannot push this way
if (flFraction != 1.0) {
flSideOffsets[side] = 0.0;
}

if (iAxis != 2) {
// Save minimum offset, but ignore zero offsets
if (!vecOffset[iAxis] || (flSideOffsets[side] && floatabs(flSideOffsets[side]) < floatabs(vecOffset[iAxis]))) {
vecOffset[iAxis] = flSideOffsets[side];
}
} else {
// Priority on bottom side
if (flSideOffsets[0]) {
vecOffset[iAxis] = flSideOffsets[0];
}
}

// Find closest axis to push
if (vecOffset[iAxis]) {
if (iClosestAxis == -1 || floatabs(vecOffset[iAxis]) < floatabs(vecOffset[iClosestAxis])) {
iClosestAxis = iAxis;
}
}
}
}

free_tr2(pTrace);

// Push by closest axis
if (iClosestAxis == -1) return;

static iPushDir; iPushDir = vecOffset[iClosestAxis] > 0.0 ? 1 : -1;
static Float:vecSize[3]; xs_vec_sub(vecAbsMax, vecAbsMin, vecSize);
static Float:flDepthRatio; flDepthRatio = floatabs(vecOffset[iClosestAxis]) / (vecSize[iClosestAxis] / 2);

flDepthRatio = floatclamp(flDepthRatio, flMinDepthRatio, flMaxDepthRatio);

static Float:vecForce[3]; xs_vec_copy(Float:{0.0, 0.0, 0.0}, vecForce);

static bool:bInInfluence; bInInfluence = (
flDepthRatio >= flDepthInfluenceMin &&
flDepthRatio <= flDepthInfluenceMax
);

if (bInInfluence) {
vecForce[iClosestAxis] = flForce * flDepthRatio * iPushDir;
} else {
vecForce[iClosestAxis] = flForce * iPushDir;

if (iFlags & APS_Flag_AddForceInfluenceMode) {
iFlags &= ~APS_Flag_AddForce;
}
}

@Base_Push(this, vecForce, iFlags);
}
63 changes: 63 additions & 0 deletions api/advanced-pushing/include/api_advanced_pushing.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#if defined _api_advanced_pushing_included
#endinput
#endif
#define _api_advanced_pushing_included

#pragma reqlib api_advanced_pushing

enum APS_Flags (<<=1) {
APS_Flag_None,
APS_Flag_AddForce = 1,
APS_Flag_AddForceInfluenceMode,
APS_Flag_OverlapMode
};

/**
* Pushes the entity using the given force vector.
*
* @param pEntity The entity to push.
* @param vecForce The force vector to apply.
* @param iFlags The flags for the push operation.
*
* @noreturn
*/
native APS_Push(pEntity, const Float:vecForce[3], APS_Flags:iFlags = APS_Flag_None);

/**
* Pushes the entity from a specified origin with a force magnitude.
*
* @param pEntity The entity to push.
* @param flForce The force magnitude to apply.
* @param vecOrigin The origin point of the push.
* @param iFlags The flags for the push operation.
*
* @noreturn
*/
native APS_PushFromOrigin(pEntity, Float:flForce, Float:vecOrigin[3], APS_Flags:iFlags = APS_Flag_None);

/**
* Pushes the entity using a bounding box as the toucher.
*
* @param pEntity The entity to push.
* @param flForce The force magnitude to apply.
* @param vecAbsMin The absolute minimum point of the bounding box.
* @param vecAbsMax The absolute maximum point of the bounding box.
* @param flMinDepthRatio The minimum depth ratio for depth influence.
* @param flMaxDepthRatio The maximum depth ratio for depth influence.
* @param flDepthInfluenceMin The minimum depth influence.
* @param flDepthInfluenceMax The maximum depth influence.
* @param iFlags The flags for the push operation.
*
* @noreturn
*/
native APS_PushFromBBox(
pEntity,
Float:flForce,
const Float:vecAbsMin[3],
const Float:vecAbsMax[3],
Float:flMinDepthRatio = 0.0,
Float:flMaxDepthRatio = 1.0,
Float:flDepthInfluenceMin = 0.0,
Float:flDepthInfluenceMax = 1.0,
APS_Flags:iFlags = APS_Flag_None
);
Loading