AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Shield entitiy detection doesn't work while player is using it? (https://forums.alliedmods.net/showthread.php?t=337884)

GasmoN 05-23-2022 08:09

Shield entitiy detection doesn't work while player is using it?
 
Situation: Player is holding a shield, some some custom named entity touch that shield, and in FM_Touch forward doesn't recognize it. It registers that touch as if that custom named entity touched player, not a shield entity. How to fix this?

HamletEagle 05-23-2022 08:22

Re: Shield entitiy detection doesn't work while player is using it?
 
The shield is not an entity, just a model. If you need to detect shield touch you can likely use register_touch(custom entity, player) and check if the player currently has the shield deployed.
However, you may need to add more checks to filter cases when the entity touches the back of the player, depending on your needs.

GasmoN 05-23-2022 08:58

Re: Shield entitiy detection doesn't work while player is using it?
 
I know that, it really do works that way but I can't achive what I really need that way (or can I?).
So when custom entity touches player's shield, I need to check If player is actually using shield (sequence 98 ), if he is using it, I can call some function there.


Custom Entity touches player's shield > check if player is using that shield (sequence 98 ) > Call custom function

And by the method u mentioned, I am not really sure how to check if custom entity is touching player's shield. I do know to check if player is using shield tho.

PS: I don't need anyone to write me a code, I just need explanation how to actually achive this since I ran out of ideas.

StanGilbertlandria 05-25-2022 07:07

Re: Shield entitiy detection doesn't work while player is using it?
 
I'm trying to detect if a player is holding up a shield, either in the main hand or offhand, for a stamina system. When they drop the shield, the stamina should start regenerating. Any suggestions?

I've tried using armour stands and villagers, but neither really work. With armour stands, I can't use the offhand. With villagers, it won't detect when I've stopped holding it up (also it means I can't interact with other blocks while the shield is in the offhand

EFFx 05-25-2022 21:31

Re: Shield entitiy detection doesn't work while player is using it?
 
I had the same problem with detecting shield hits with my Realistic Bullet Physics plugin. The first realization was that there's no entity detection alone but another body part of the player, we can call it HIT_SHIELD, defined as 8 inside the amxconst.inc file.

This may help you, I guess.

Quote:

Originally Posted by StanGilbertlandria (Post 2780127)
I'm trying to detect if a player is holding up a shield, either in the main hand or offhand, for a stamina system. When they drop the shield, the stamina should start regenerating. Any suggestions?

I've tried using armour stands and villagers, but neither really work. With armour stands, I can't use the offhand. With villagers, it won't detect when I've stopped holding it up (also it means I can't interact with other blocks while the shield is in the offhand

PHP Code:

#define OFFSET_HASSHIELD            2043

get_pdata_bool(iPlayerOFFSET_HASSHIELD

Not sure if this is what you asked, but detects whether the user has the shield.

GasmoN 05-26-2022 10:41

Re: Shield entitiy detection doesn't work while player is using it?
 
Is there any solution for my issue tho?

GasmoN 05-28-2022 08:37

Re: Shield entitiy detection doesn't work while player is using it?
 
SOLUTION:

It's maybe not the best solution out there, but it does works.
So, instead of detecting the shield, I thought about detecting if entity is touching player from behind, sides, or front. Since player is fully covered in front when using shield, this way of detecting is helping me achive what I wanted. (If entity is touching player in front, it means it's touching the shield too).

And that's where I remembered about this plugin that prevents players from back stabbing.
https://forums.alliedmods.net/showpo...66&postcount=4 So after some small changes I made it work.

The code I am using in FM_Touch forward after checking if entity is touching player and all other checks:
PHP Code:

        if(is_using_shield(id))
        {    
            static 
Float:fOrigin[3];
            
pev(idpev_originfOrigin);
            
            static 
Float:fViewAngles[3]
            static 
Float:fTViewAngles[3];
            
pev(bulletpev_v_anglefTViewAngles);
            
            static 
Float:fMinAngleFloat:fMaxAngle;
            
fMinAngle fViewAngles[1] - CHECK_ANGLE;
            
fMaxAngle fViewAngles[1] + CHECK_ANGLE;
            
            if(
fMinAngle <= fTViewAngles[1] <= fMaxAngle)
            {
                
// Entity is touching player's back
            
}
            else
            {
                
// Entity is touching player's front (shield)
            
}
        } 

Define and stock used
PHP Code:

#define CHECK_ANGLE 100.0

bool:is_using_shield(id)
{
    if(
entity_get_int(id EV_INT_sequence) == 98)
    return 
true;

    return 
false;


If there is a better way of doing this, I am always up for suggestions.

Natsheh 05-28-2022 11:54

Re: Shield entitiy detection doesn't work while player is using it?
 
You can give it a try with ( engfunc(EngFunc_TraceModel, const Float:start[3], const Float:end[3], hull, ent_to_hit, ptr) )

ent_to_hit is the victim player shield.


All times are GMT -4. The time now is 20:20.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.