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

When i throw a grenade my secondary weapon dissapear


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Elitcky
AlliedModders Donor
Join Date: Jun 2016
Location: Antofagasta, Chile
Old 10-21-2017 , 02:02   When i throw a grenade my secondary weapon dissapear
Reply With Quote #1

Just that in the title bros.

PHP Code:
public void OnWeaponFire(Event hEvent, const char[] namebool dontBroadcast)
{
    
int iClient GetClientOfUserId(hEvent.GetInt("userid"));
    
int iWeapon GetEntPropEnt(iClientProp_Data"m_hActiveWeapon");
    if (
IsValidEntity(iWeapon)) {
        
char sWeaponName[64];
        
GetEntityClassname(iWeaponsWeaponNamesizeof(sWeaponName));
        if (
IsWeaponGrenade(sWeaponName)) {
            
int i;
            for (
0sizeof(g_saGrenadeWeaponNames) && !StrEqual(sWeaponNameg_saGrenadeWeaponNames[i]); i++) {  }
            
int iCount GetEntProp(iClientProp_Send"m_iAmmo"_g_iaGrenadeOffsets[i]) - 1;
            
DataPack hPack = new DataPack();
            if (
g_haInvisible[iClient] != INVALID_HANDLE)
                
BreakInvisibility(iClientREASON_GRENADE);
            
CreateDataTimer(0.2SwapToNadehPack);
            
hPack.WriteCell(iClient);
            
hPack.WriteCell(iWeapon);
            
hPack.WriteCell(iCount);
        }
    }
}

public 
Action SwapToNade(Handle hTimerDataPack hPack)
{
    
hPack.Reset();
    
int iClient hPack.ReadCell();
    
int iWeaponThrown hPack.ReadCell();
    
int count hPack.ReadCell();
    if (!
IsClientInGame(iClient))
        return 
Plugin_Continue;
    
int iWeaponTemp = -1;
    if (!
count) {
        if (
IsValidEntity(iWeaponThrown)) {
            
RemovePlayerItem(iClientiWeaponThrown);
            
RemoveEdict(iWeaponThrown);
        }
        
iWeaponTemp GetPlayerWeaponSlot(iClient3);
    }
    if (
iWeaponThrown == iWeaponTemp)
        return 
Plugin_Continue//won't even get here but eh, you nevah know
    
if (count)
        
iWeaponTemp iWeaponThrown;
    if (!
IsValidEntity(iWeaponTemp))
        return 
Plugin_Continue;
    
char weapon_name[64];
    
GetEntityClassname(iWeaponTempweapon_namesizeof(weapon_name));
    
int i;
    for (
0sizeof(g_saGrenadeWeaponNames) && !StrEqual(weapon_nameg_saGrenadeWeaponNames[i]); i++) {  }
    
SetEntProp(iClientProp_Send"m_iAmmo"GetEntProp(iClientProp_Send"m_iAmmo"_g_iaGrenadeOffsets[i]) - 1_g_iaGrenadeOffsets[i]);
    
RemovePlayerItem(iClientiWeaponTemp);
    
RemoveEdict(iWeaponTemp);
    
iWeaponTemp GivePlayerItem(iClientweapon_name);
    
SetEntPropEnt(iClientProp_Send"m_hActiveWeapon"iWeaponTemp);
    
SetEntPropFloat(iWeaponTempProp_Send"m_flNextPrimaryAttack"GetGameTime() + 1.1);
    
SetEntPropFloat(iWeaponTempProp_Send"m_flNextSecondaryAttack"GetGameTime() + 1.1);
    return 
Plugin_Continue;

I think there is a problem but i can't see it :/ When i have a deagle and i dont want to use it, and i change my weapon to a grenade, the deagle dissapear :/

Halp and Thanks for answering
__________________

Last edited by Elitcky; 10-21-2017 at 02:02.
Elitcky is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 10-21-2017 , 05:34   Re: When i throw a grenade my secondary weapon dissapear
Reply With Quote #2

you surely use RemoveEdict a lot... and that is not very wise to use, could crash server.

Anyway, could you tell what should happen in your code, player shoot and swap to grenade ?
__________________
Do not Private Message @me
Bacardi is offline
Elitcky
AlliedModders Donor
Join Date: Jun 2016
Location: Antofagasta, Chile
Old 10-21-2017 , 06:28   Re: When i throw a grenade my secondary weapon dissapear
Reply With Quote #3

it should have the 2 items at the time. The Deagle in my "pocket" if i throw a grenade, it shouldn't dissapear :/

If i buy a deagle in a menu, and i throw a grenade after i bought the deagle, the deagle dissapears xD.
__________________
Elitcky is offline
Elitcky
AlliedModders Donor
Join Date: Jun 2016
Location: Antofagasta, Chile
Old 10-23-2017 , 16:39   Re: When i throw a grenade my secondary weapon dissapear
Reply With Quote #4

welp

EDIT: i fixed it but just when is a CT i tried searching in the entire code if there was an exception for ct or a block in the T but no results...

Just removed the "Removeedict"
PHP Code:
public void OnWeaponFire(Event hEvent, const char[] namebool dontBroadcast)
{
    
int iClient GetClientOfUserId(hEvent.GetInt("userid"));
    
int iWeapon GetEntPropEnt(iClientProp_Data"m_hActiveWeapon");
    if (
IsValidEntity(iWeapon)) {
        
char sWeaponName[64];
        
GetEntityClassname(iWeaponsWeaponNamesizeof(sWeaponName));
        if (
IsWeaponGrenade(sWeaponName)) {
            
int i;
            for (
0sizeof(g_saGrenadeWeaponNames) && !StrEqual(sWeaponNameg_saGrenadeWeaponNames[i]); i++) {  }
            
int iCount GetEntProp(iClientProp_Send"m_iAmmo"_g_iaGrenadeOffsets[i]) - 1;
            
DataPack hPack = new DataPack();
            if (
g_haInvisible[iClient] != INVALID_HANDLE)
                
BreakInvisibility(iClientREASON_GRENADE);
            
CreateDataTimer(0.2SwapToNadehPack);
            
hPack.WriteCell(iClient);
            
hPack.WriteCell(iWeapon);
            
hPack.WriteCell(iCount);
        }
    }
}

public 
Action SwapToNade(Handle hTimerDataPack hPack)
{
    
hPack.Reset();
    
int iClient hPack.ReadCell();
    
int iWeaponThrown hPack.ReadCell();
    
int count hPack.ReadCell();
    if (!
IsClientInGame(iClient))
        return 
Plugin_Continue;
    
int iWeaponTemp = -1;
    if (!
count) {
        if (
IsValidEntity(iWeaponThrown)) {
            
RemovePlayerItem(iClientiWeaponThrown);
            
RemoveEdict(iWeaponThrown);
        }
        
iWeaponTemp GetPlayerWeaponSlot(iClient3);
    }
    if (
iWeaponThrown == iWeaponTemp)
        return 
Plugin_Continue//won't even get here but eh, you nevah know
    
if (count)
        
iWeaponTemp iWeaponThrown;
    if (!
IsValidEntity(iWeaponTemp))
        return 
Plugin_Continue;
    
char weapon_name[64];
    
GetEntityClassname(iWeaponTempweapon_namesizeof(weapon_name));
    
int i;
    for (
0sizeof(g_saGrenadeWeaponNames) && !StrEqual(weapon_nameg_saGrenadeWeaponNames[i]); i++) {  }
    
SetEntProp(iClientProp_Send"m_iAmmo"GetEntProp(iClientProp_Send"m_iAmmo"_g_iaGrenadeOffsets[i]) - 1_g_iaGrenadeOffsets[i]);
    
RemovePlayerItem(iClientiWeaponTemp);
    
//RemoveEdict(iWeaponTemp);
    
iWeaponTemp GivePlayerItem(iClientweapon_name);
    
SetEntPropEnt(iClientProp_Send"m_hActiveWeapon"iWeaponTemp);
    
SetEntPropFloat(iWeaponTempProp_Send"m_flNextPrimaryAttack"GetGameTime() + 1.1);
    
SetEntPropFloat(iWeaponTempProp_Send"m_flNextSecondaryAttack"GetGameTime() + 1.1);
    return 
Plugin_Continue;

Any ideas ?
__________________

Last edited by Elitcky; 10-24-2017 at 03:45. Reason: more
Elitcky 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 10:54.


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