AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Plugin/Gameplay Ideas and Requests (https://forums.alliedmods.net/forumdisplay.php?f=60)
-   -   Solved [L4D2]Exclude projectiles that have been thrown (https://forums.alliedmods.net/showthread.php?t=335912)

sorallll 01-12-2022 12:52

[L4D2]Exclude projectiles that have been thrown
 
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));
    }



Marttt 01-12-2022 14:24

Re: [L4D2]Exclude projectiles that have been thrown
 
Didn't understand what you mean.

Anyway check: [L4D1 & L4D2] Throwable Announcer, maybe helps

sorallll 01-12-2022 14:26

Re: [L4D2]Exclude projectiles that have been thrown
 
Quote:

Originally Posted by Marttt (Post 2768322)
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

Bacardi 01-13-2022 23:05

Re: [L4D2]Exclude projectiles that have been thrown
 
...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

HarryPotter 01-14-2022 12:03

Re: [L4D2]Exclude projectiles that have been thrown
 
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);
            } 


sorallll 01-14-2022 12:47

Re: [L4D2]Exclude projectiles that have been thrown
 
Quote:

Originally Posted by HarryPotter (Post 2768411)
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

HarryPotter 03-29-2024 19:30

Re: [L4D2]Exclude projectiles that have been thrown
 
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);
    } 



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

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