Raised This Month: $51 Target: $400
 12% 

Solved [L4D2]Exclude projectiles that have been thrown


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
sorallll
Senior Member
Join Date: Oct 2018
Old 01-12-2022 , 12:52   [L4D2]Exclude projectiles that have been thrown
Reply With Quote #1

Is there a better way to get the player's weapon without throwing projectiles?

The method currently in use
PHP Code:
int g_iGrenadeThrower[MAXPLAYERS 1];
public 
void OnEntityCreated(int entity, const char[] classname)
{
    if(
classname[0] != 'm' && classname[0] != 'p' && classname[0] != 'v')
        return;

    if(
strncmp(classname"molotov_projectile"19) == || strncmp(classname"pipe_bomb_projectile"21) == || strncmp(classname"vomitjar_projectile"20) == 0)
        
SDKHook(entitySDKHook_SpawnPostHook_SpawnPost);
}

void Hook_SpawnPost(int entity)
{
    
SDKUnhook(entitySDKHook_SpawnPostHook_SpawnPost);
    if(
entity <= MaxClients || !IsValidEntity(entity))
        return;

    
int iOwner GetEntPropEnt(entityProp_Data"m_hOwnerEntity");
    if(
iOwner <= MaxClients && IsClientInGame(iOwner) && GetClientTeam(iOwner) == 2)
    {
        
int iSlot GetPlayerWeaponSlot(iOwner2);
        if(
iSlot MaxClients)
            
g_iGrenadeThrower[iOwner] = EntIndexToEntRef(iSlot);
    }
}

char sWeapon [32];
int iSlot GetPlayerWeaponSlot(client2);
if(
iSlot MaxClients)
{
    if(
EntIndexToEntRef(iSlot) != g_iGrenadeThrower[client])
    {
        
GetEntityClassname(iSlotsWeaponsizeof(sWeapon));
    }


Last edited by sorallll; 01-21-2022 at 13:16.
sorallll is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 01-12-2022 , 14:24   Re: [L4D2]Exclude projectiles that have been thrown
Reply With Quote #2

Didn't understand what you mean.

Anyway check: [L4D1 & L4D2] Throwable Announcer, maybe helps
__________________
Marttt is offline
sorallll
Senior Member
Join Date: Oct 2018
Old 01-12-2022 , 14:26   Re: [L4D2]Exclude projectiles that have been thrown
Reply With Quote #3

Quote:
Originally Posted by Marttt View Post
Didn't understand what you mean.

Anyway check: [L4D1 & L4D2] Throwable Announcer, maybe helps
I have a function where I want to save the player's weapon and restore it sometime later. But I want to exclude throws already thrown when saving throws
sorallll is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 01-13-2022 , 23:05   Re: [L4D2]Exclude projectiles that have been thrown
Reply With Quote #4

...awful code.
Anyway, you do know, projectiles are "used" grenades or missiles?
Example, player carry weapon_smokegrenade.
Player throw weapon_smokegrenade, weapon_smokegrenade get destroyed and smokegrenade_projectile appear, flying object in world. Then projectile get destroyed after few secongs after that throw.

If you want look player weapons, there few way:
-Loop to look all player weapon slots.
- Look player array, "m_hMyWeapons" and perhaps current weapon in hands "m_hMyWeapons"
My favourite.
- Or harder way, loop all weapon entities from world by FindEntityByClassName, look m_hOwner...

Then look ammo and clip amount.
From client "m_iAmmo" array, from weapon "m_iClip1"


Here example plugin about auto reload weapon, if you like check.
https://forums.alliedmods.net/showpo...38&postcount=3
__________________
Do not Private Message @me

Last edited by Bacardi; 01-13-2022 at 23:12.
Bacardi is offline
HarryPotter
Veteran Member
Join Date: Sep 2017
Location: Taiwan, Asia
Old 01-14-2022 , 12:03   Re: [L4D2]Exclude projectiles that have been thrown
Reply With Quote #5

Detect projectiles that have been thrown.
PHP Code:
    int weapon GetPlayerWeaponSlot(client2);
    if (
weapon && 
        
GetEntPropEnt(clientProp_Data"m_hActiveWeapon") == weapon && 
        
GetEntPropFloat(weaponProp_Data"m_flNextPrimaryAttack") >= GetGameTime())
    {
        
// slot 2 is throwable
        
    

or

use Exploit Fix - Unlimited Grenades by Silvers.
Silvers instantly removes player's slot 2 throwable item when player throws a projectile

PHP Code:
            int weapon GetPlayerWeaponSlot(client2);
            if( 
weapon != -)
            {
                
// PrintToChatAll("Exploit Blocked: %N", client);
                
RemovePlayerItem(clientweapon);
                
RemoveEntity(weapon);
            } 
__________________

Last edited by HarryPotter; 01-14-2022 at 12:09.
HarryPotter is offline
sorallll
Senior Member
Join Date: Oct 2018
Old 01-14-2022 , 12:47   Re: [L4D2]Exclude projectiles that have been thrown
Reply With Quote #6

Quote:
Originally Posted by HarryPotter View Post
Detect projectiles that have been thrown.
PHP Code:
    int weapon GetPlayerWeaponSlot(client2);
    if (
weapon && 
        
GetEntPropEnt(clientProp_Data"m_hActiveWeapon") == weapon && 
        
GetEntPropFloat(weaponProp_Data"m_flNextPrimaryAttack") >= GetGameTime())
    {
        
// slot 2 is throwable
        
    

or

use Exploit Fix - Unlimited Grenades by Silvers.
Silvers instantly removes player's slot 2 throwable item when player throws a projectile

PHP Code:
            int weapon GetPlayerWeaponSlot(client2);
            if( 
weapon != -)
            {
                
// PrintToChatAll("Exploit Blocked: %N", client);
                
RemovePlayerItem(clientweapon);
                
RemoveEntity(weapon);
            } 
Thanks, Harry Potter. Your first method should be what I need and will be much more efficient
sorallll is offline
HarryPotter
Veteran Member
Join Date: Sep 2017
Location: Taiwan, Asia
Old 03-29-2024 , 19:30   Re: [L4D2]Exclude projectiles that have been thrown
Reply With Quote #7

Found more efficient way today, thanks to Forgetest

PHP Code:
    int grenade GetPlayerWeaponSlot(client2);
    
int iPrimaryAmmoType GetEntProp(grenadeProp_Send"m_iPrimaryAmmoType");
    
int iAmmo GetEntData(clientFindSendPropInfo("CCSPlayer""m_iAmmo") + iPrimaryAmmoType*4);
    
PrintToChatAll("m_iAmmo %d"iAmmo);
    if(
iAmmo == 0)
    {
        
PrintToChatAll("%d has been thrown"grenade);
    } 
__________________
HarryPotter is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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