Raised This Month: $32 Target: $400
 8% 

[CSGO] Change clip/ammo size


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Lord_SAmMY
Junior Member
Join Date: Jun 2017
Old 06-21-2017 , 04:06   [CSGO] Change clip/ammo size
Reply With Quote #1

Hey everyone!
I tried to change weapons ammo.

Setting clip:
PHP Code:
SetEntProp(wpidProp_Send"m_iClip1"clipAmmo); 
Setting reserve:
PHP Code:
SetEntProp(wpidProp_Send"m_iPrimaryReserveAmmoCount"reserveAmmo); 
Question 1:
This works well, until reserve ammo is exceeding the default max size.
If my P90 got 200 bullets reserve and i am reloading an empty clip, it should end up in 150 bullets reserve. But after reload, the reserve ammo is resetting to 100 (default max size).
Anybody know how to fix this in a nice way? (Posted my dirty solution below)

Question 2:
How can i modify max clip size on shotguns after reloading?
Is it possible to extend the amount of shots reloaded into weapon while animating?

This code is not able to change shotguns clip size on reload.
(I know its old syntax, but this gamemode is far too big to change it quickly.)
PHP Code:
public OnEntityCreated(entity, const String:classname[])
{
    
PrintAsDebug(STATE_FREQ"OnEntityCreated");
    if(
StrEqual(classname"hegrenade_projectile"))
        
SDKHook(entitySDKHook_SpawnPostOnThrownGrenadeSpawned);
    if(
StrContains(classname"weapon_") != -1)
        
SDKHook(entitySDKHook_SpawnPostOnWeaponSpawn);
}

stock OnWeaponSpawn(entity)
{
    
PrintAsDebug(STATE_INFO"OnWeaponSpawn");
    
SDKHook(entitySDKHook_ReloadOnWeaponReload);
    
SDKHook(entitySDKHook_ReloadPostOnWeaponReloadPost);
    
    
decl String:wpname[64];
    
GetEdictClassname(entitywpname64);
    new 
clip GetConstWeaponClip(wpname);
    if(
clip != -1)
        
SetWeaponAmmo(entityclip0);
}

new 
g_PlayerTempAmmo[MAXPLAYERS+1][4];

public 
Action:OnWeaponReload(weapon)
{
    
PrintAsDebug(STATE_INFO"OnWeaponReload");
    
decl String:wpname[64];
    
GetEdictClassname(weaponwpname64);
    new 
currClip GetWeaponClipAmmo(weapon);
    new 
client GetEntDataEnt2(weaponm_hOwner);
    if(
client 0)
    {
        if(
g_DBEntries[client][dUpgradeAmmo] != && currClip == GetConstWeaponClip(wpname)) // Force weapon reload
            
SetWeaponAmmo(weaponcurrClip 1GetWeaponReserveAmmo(weapon) + 1);
        else if(
g_DBEntries[client][dUpgradeAmmo] != && currClip == GetUpgradedIntValue(clientGetConstWeaponClip(wpname), UPGRADE_AMMO))
            return 
Plugin_Handled;
    }
    return 
Plugin_Continue;
}

public 
OnWeaponReloadPost(weaponbool:success)
{
    
PrintAsDebug(STATE_INFO"OnWeaponReloadPost");
    if(!
success) return;
    new 
client GetEntDataEnt2(weaponm_hOwner);
    if(
client && (GetPlayerWeaponSlot(client0) == weapon || GetPlayerWeaponSlot(client1) == weapon))
    {
        
decl String:wpname[64];
        
GetEdictClassname(weaponwpname64);
        
g_PlayerTempAmmo[client][0] = EntIndexToEntRef(weapon);
        
g_PlayerTempAmmo[client][1] = GetWeaponClipAmmo(weapon);
        
g_PlayerTempAmmo[client][2] = GetWeaponReserveAmmo(weapon);
        
g_PlayerTempAmmo[client][3] = (StrEqual(wpname"weapon_nova") || StrEqual(wpname"weapon_xm1014") || StrEqual(wpname"weapon_sawedoff")) ? 0;
        
CreateTimer(0.1OnWeaponReloadedCheckGetClientSerial(client), TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
    }
}

public 
Action:OnWeaponReloadedCheck(Handle:timerclient)
{
    
PrintAsDebug(STATE_FREQ"OnWeaponReloadedCheck");
    
client GetClientFromSerial(client);
    if(
client == 0) return Plugin_Stop;
    new 
weapon EntRefToEntIndex(g_PlayerTempAmmo[client][0]);
    if(
weapon == INVALID_ENT_REFERENCE) return Plugin_Stop;
    
    if(!
g_PlayerTempAmmo[client][3] && GetEntProp(weaponProp_Data"m_bInReload")
    || 
g_PlayerTempAmmo[client][3] && GetEntProp(weaponProp_Send"m_reloadState") > 0)
    {
        return 
Plugin_Continue;
    }
    new 
currClip g_PlayerTempAmmo[client][1];
    new 
currReserve g_PlayerTempAmmo[client][2];
    if(
GetWeaponClipAmmo(weapon) > currClip)
    {
        
decl String:wpname[64];
        
GetEdictClassname(weaponwpname64);
        new 
maxClip GetUpgradedIntValue(clientGetConstWeaponClip(wpname), UPGRADE_AMMO);
        new 
clip currReserve;
        new 
reserve currReserve maxClip currClip;
        if(
clip maxClipclip maxClip;
        if(
reserve 0reserve 0;
        
SetWeaponAmmo(weaponclipreserve);
    }
    return 
Plugin_Stop;


Last edited by Lord_SAmMY; 06-28-2017 at 04:25. Reason: Better phrasing
Lord_SAmMY is offline
BraveFox
AlliedModders Donor
Join Date: May 2015
Location: Israel
Old 06-21-2017 , 05:30   Re: CSGO modifying ammo
Reply With Quote #2

This works on TF2 try using it(should work):
PHP Code:
stock SetClip(clientwepslotnewAmmo)
{
    
int weapon GetPlayerWeaponSlot(clientwepslot);
    if (!
IsValidEntity(weapon))
    {
    }
    if (
IsValidEntity(weapon))
    {
        
int iAmmoTable FindSendPropInfo("CTFWeaponBase""m_iClip1");
        
SetEntData(weaponiAmmoTablenewAmmo4true);
    }
}


stock SetAmmo(clientwepslotnewAmmo)
{
    
int weapon GetPlayerWeaponSlot(clientwepslot);
    if (!
IsValidEntity(weapon))
    {
    }
    if (
IsValidEntity(weapon))
    {
        
int iOffset GetEntProp(weaponProp_Send"m_iPrimaryAmmoType"1) * 4;
        
int iAmmoTable FindSendPropInfo("CTFPlayer""m_iAmmo");
        
SetEntData(clientiAmmoTable iOffsetnewAmmo4true);
    }

__________________
Contact Me:
Steam: NoyB
Discord: Noy#9999
Taking Private Requests
BraveFox is offline
Lord_SAmMY
Junior Member
Join Date: Jun 2017
Old 06-21-2017 , 05:41   Re: CSGO modifying ammo
Reply With Quote #3

Quote:
Originally Posted by BraveFox View Post
This works on TF2 try using it(should work):
PHP Code:
stock SetClip(clientwepslotnewAmmo)
{
    
int weapon GetPlayerWeaponSlot(clientwepslot);
    if (!
IsValidEntity(weapon))
    {
    }
    if (
IsValidEntity(weapon))
    {
        
int iAmmoTable FindSendPropInfo("CTFWeaponBase""m_iClip1");
        
SetEntData(weaponiAmmoTablenewAmmo4true);
    }
}


stock SetAmmo(clientwepslotnewAmmo)
{
    
int weapon GetPlayerWeaponSlot(clientwepslot);
    if (!
IsValidEntity(weapon))
    {
    }
    if (
IsValidEntity(weapon))
    {
        
int iOffset GetEntProp(weaponProp_Send"m_iPrimaryAmmoType"1) * 4;
        
int iAmmoTable FindSendPropInfo("CTFPlayer""m_iAmmo");
        
SetEntData(clientiAmmoTable iOffsetnewAmmo4true);
    }

This is not working in csgo since 2015.
They updated their reserve ammo handling.
Lord_SAmMY is offline
Lord_SAmMY
Junior Member
Join Date: Jun 2017
Old 06-28-2017 , 04:29   Re: [CSGO] Change clip/ammo size
Reply With Quote #4

Nobody an idea?
Lord_SAmMY is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 06-28-2017 , 18:00   Re: [CSGO] Change clip/ammo size
Reply With Quote #5

Question 1:

The default max reserve is displayed while the actual reserve count is accurate. Keep emptying the clips and you'll notice it's a visual bug.
__________________
Neuro Toxin is offline
Lord_SAmMY
Junior Member
Join Date: Jun 2017
Old 06-29-2017 , 03:51   Re: [CSGO] Change clip/ammo size
Reply With Quote #6

Quote:
Originally Posted by Neuro Toxin View Post
Question 1:

The default max reserve is displayed while the actual reserve count is accurate. Keep emptying the clips and you'll notice it's a visual bug.
I already tested and its not only a visual bug. If i am reloading again, its subtracted from resetted default max size. Also m_iPrimaryReserveAmmoCount contains the new resetted amount.
My included workaround does its job (not on shotguns) but its confusing players, since ammo count jumping around while reloading.
There seems to be another value does affect ammo handling as well.
I also tried combining ammo handling since 2015 with old one on client (m_iPrimaryAmmoType, m_iAmmo) but it does not work too.
Lord_SAmMY 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 01:01.


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