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

Add SV_AllowPhysent hook #951

Merged
merged 2 commits into from
Feb 11, 2023
Merged

Add SV_AllowPhysent hook #951

merged 2 commits into from
Feb 11, 2023

Conversation

justgo97
Copy link

@justgo97 justgo97 commented Feb 9, 2023

Can be used to create a custom semiclip without needing a module

Ex:

#include <amxmodx>
#include <cstrike>
#include <fakemeta>
#include <reapi>

public plugin_init() {
    register_plugin("Semiclip", "0.0.1", "JustGo")
    
    register_forward(FM_AddToFullPack,"fw_AddToFullPack_Post",1)

    RegisterHookChain(RH_SV_AllowPhysent, "SV_AllowPhysent")
}

public SV_AllowPhysent(ent, sv_player) {
    if(!is_user_alive(ent) || !is_user_alive(sv_player)) return HC_CONTINUE

    if(!isSameTeam(ent, sv_player)) return HC_CONTINUE

    SetHookChainReturn(ATYPE_BOOL, false)
    return HC_SUPERCEDE
}

public fw_AddToFullPack_Post(es_handle,e,ent,host,hostflags,player,pSet)
{
    if(!is_user_alive(host) || !is_user_alive(ent)) return FMRES_IGNORED

    if(isSameTeam(host, ent))
    {
        set_es(es_handle, ES_Solid, SOLID_NOT);
        return FMRES_HANDLED;
    }
    return FMRES_IGNORED;
}

stock isSameTeam(id1, id2) {
    return (cs_get_user_team(id1) == cs_get_user_team(id2))
}

@s1lentq s1lentq merged commit 1796459 into rehlds:master Feb 11, 2023
@RauliTop
Copy link
Contributor

RauliTop commented Feb 12, 2023

@s1lentq time to push a rehlds release?

@StevenKal
Copy link
Contributor

StevenKal commented Feb 16, 2023

@s1lentq time to push a rehlds release?

s1lentq was in his usual process of hibernation but a strike from Ukraine near his city woke him up!
Now he is gone back to his usual deep sleep! Hehehehehe!

PS: He should also merge all the +1 year pending hooks in ReGameDLL_CS & cie! Almost seems like only the hooks related to functions the approvers "got a personal interest" are merged! I am wondering why some (like API stuff) are so long to be merged, there are modified files section, a control (approvers know that files should be modified for a new hook addition as example), all O.K., a check on "Actions" if this compile fine, all O.K., at the best, use a testing Metamod module with the new hook, and, with debug print/log inside the new hook (tested with the compiled bin from "Actions"), then if works, direct merge...

@RauliTop
Copy link
Contributor

RauliTop commented Feb 21, 2023

edit: it's called, working well. Ignore this comment

@justgo97
Tested the hook with a entity created by a plugin and it seems never called.
How to solve it? entity with create_entity("info_target")

@justgo97
Copy link
Author

@justgo97 Tested the hook with a entity created by a plugin and it seems never called. How to solve it? entity with create_entity("info_target")

What are you trying to achieve? This hook is mostly used for collision between players, for player - entity stuff you can use FM_ShouldCollide

@RauliTop
Copy link
Contributor

RauliTop commented Feb 22, 2023

What are you trying to achieve? This hook is mostly used for collision between players, for player - entity stuff you can use FM_ShouldCollide

Well, the entity is SOLID_TRIGGER. That's why RH_SV_AllowPhysent not called.

I'm trying to be the entity fully semiclip with other players.
Now is trespassing them, but it seems to have a type of physic, because when touching is changing direction.
Movetype MOVETYPE_BOUNCEMISSILE

See on: https://imgur.com/iDzh5ar

When you are closer to the player, more reflection.

@justgo97
Copy link
Author

justgo97 commented Feb 22, 2023

What are you trying to achieve? This hook is mostly used for collision between players, for player - entity stuff you can use FM_ShouldCollide

Well, the entity is SOLID_TRIGGER. That's why RH_SV_AllowPhysent not called.

I'm trying to be the entity fully semiclip with other players. Now is trespassing them, but it seems to have a type of physic, because when touching is changing direction. Movetype MOVETYPE_BOUNCEMISSILE

See on: https://imgur.com/iDzh5ar

When you are closer to the player, more reflection.

Hooking FM_ShouldCollide might help, something like this:

public plugin_init() {
    register_forward(FM_ShouldCollide, "ShouldCollide")
}

public ShouldCollide(entTouched, entOther) {
    if(!is_user_alive(entTouched)) return FMRES_IGNORED;

    if(!pev_valid(entOther)) return FMRES_IGNORED;

    if(isCustomEntity(entOther)) {
        forward_return(FMV_CELL, 0)
        return FMRES_SUPERCEDE
    }

    return FMRES_IGNORED;
}

stock bool:isCustomEntity(ent) {
    // Add your custom entity checks here
    if()
        return true;

    return false;
}

@RauliTop
Copy link
Contributor

After a few days testing.

The problem was using get_user_origin with mode 3 to get the end of the trace.
That causes when you hit a player, the end of the trace changes and the bullet direction too.

Solved by using Traceline with IGNORE_MONSTERS parameter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants