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

[HELP] Infinite ammo?


Post New Thread Reply   
 
Thread Tools Display Modes
mug1wara
AlliedModders Donor
Join Date: Jun 2018
Old 06-12-2018 , 06:18   Re: [HELP] Infinite ammo?
Reply With Quote #11

*removed* thought wrong, that code won't work

Last edited by mug1wara; 06-12-2018 at 06:20.
mug1wara is offline
akcaliberg
Senior Member
Join Date: Nov 2011
Location: Istanbul
Old 06-14-2018 , 09:34   Re: [HELP] Infinite ammo?
Reply With Quote #12

As someone else said you should check StrContains return value against -1

Also this code may prevent players from having unlimited ammo if there is another weapon in the same slot

PHP Code:
(weapon == GetPlayerWeaponSlot(iClientCS_SLOT_PRIMARY) || weapon == GetPlayerWeaponSlot(iClientCS_SLOT_SECONDARY)) 
Other than those, there should be no problem. Make sure this function is returning true:

PHP Code:
VIP_IsClientFeatureUse(iClientBULLETS
as well as the bIsVIP variable.


This code works without a problem on my CS:GO server:

PHP Code:
public Action ClientWeaponReload(Handle event, const char[] namebool bIsVIP)
{
    
int iClient GetClientOfUserId(GetEventInt(event"userid"));
    
    
int weapon GetEntPropEnt(iClientProp_Data"m_hActiveWeapon");
    
char classname[32];
    
GetEdictClassname(weaponclassnamesizeof(classname));

    if(
IsPlayerAlive(iClient/*&& bIsVIP &&  VIP_IsClientFeatureUse(iClient, BULLETS)*/)
    {
        if(
weapon && (weapon == GetPlayerWeaponSlot(iClientCS_SLOT_PRIMARY) || weapon == GetPlayerWeaponSlot(iClientCS_SLOT_SECONDARY)))
        {
            if (
StrContains(classname"weapon_"false) != -1)
            {
                
SetEntProp(weaponProp_Send"m_iClip1"32);
                
SetEntProp(weaponProp_Send"m_iClip2"32);    
            }
        }
    }


Last edited by akcaliberg; 06-14-2018 at 09:38.
akcaliberg is offline
SM9
Veteran Member
Join Date: Sep 2013
Location: United Kingdom
Old 06-14-2018 , 12:41   Re: [HELP] Infinite ammo?
Reply With Quote #13

Assuming your game is CSGO this plugin should do the trick.

You need the csgoitems.inc to compile, although CSGOItems itself is optional but definitely a personal recommendation as it allows the plugin to automatically determine the correctly ammo to be set dynamically per weapon

Grab CSGOItems here (If you want)

There is currently a known issue which affects some people that have CSGOItems installed, If you get script timeouts then open configs/core.cfg in the sourcemod directory and set "SlowScriptTimeout" to a higher value, something like 30.

PHP Code:
#include <sdktools>
#include <cstrike>
#include <csgoitems>

bool g_bCSGOItems false;

public 
void OnPluginStart() {
    
g_bCSGOItems LibraryExists("CSGO_Items");
}

public 
void OnLibraryAdded(const char[] szName) {
    if (
StrEqual(szName"CSGO_Items")) {
        
g_bCSGOItems true;
    }
}

public 
void OnLibraryRemoved(const char[] szName) {
    if (
StrEqual(szName"CSGO_Items")) {
        
g_bCSGOItems false;
    }
}

public 
void OnPlayerRunCmdPost(int iClient)
{
    
// Is he alive? If not we don't need to go further.
    
if (!IsPlayerAlive(iClient)) {
        return;
    }
    
    
// Here we will make sure we only do logic once per tick, just an optimization.
    
int iGameTick GetGameTickCount();
    
    static 
int iLastTick[MAXPLAYERS 1];
    
    if (
iGameTick == iLastTick[iClient]) {
        return;
    }
    
    
iLastTick[iClient] = iGameTick;
    
    
// Lets grab his active weapon.
    
int iActiveWeapon g_bCSGOItems CSGOItems_GetActiveWeapon(iClient) : GetEntPropEnt(iClientProp_Data"m_hActiveWeapon");
    
    
// Is his weapon valid? If not then lets not do any further logic.
    
if (iActiveWeapon == -1) {
        return;
    }
    
    
// Now lets determine if the weapon is a primary or a secondary, otherwise we ain't interested in any further logic.
    
if (g_bCSGOItems) {
        
int iWeaponSlot CSGOItems_GetWeaponSlotByWeapon(iActiveWeapon);
        
        if (
iWeaponSlot != CS_SLOT_SECONDARY && iWeaponSlot != CS_SLOT_PRIMARY) {
            return;
        }
    } else if (
iActiveWeapon != GetPlayerWeaponSlot(iClientCS_SLOT_SECONDARY) && iActiveWeapon != GetPlayerWeaponSlot(iClientCS_SLOT_PRIMARY)) {
        return;
    }
    
    
// Lets refill his gun.
    
RefillWeapon(iClientiActiveWeapon);
}

void RefillWeapon(int iClientint iWeapon)
{
    
/* // Check if he is a VIP first (Uncomment me.)
    if(!VIP_IsClientFeatureUse(iClient, BULLETS)) {
        /return;
    }*/
    
    
if (!g_bCSGOItems) {  // We don't have CSGOItems plugin installed.
        // Determine what ammo should be set here, these are just examples and should be determined properly per weapon.
        
int iReserveAmmo 32;
        
int iClipAmmo 32;
        
        
SetWeaponAmmo(iWeaponiReserveAmmoiClipAmmo);
        return;
    }
    
    
// We do have CSGO Items, we can dynamically set the correct ammo values for this weapon!
    
CSGOItems_RefillClipAmmo(iWeapon);
    
CSGOItems_RefillReserveAmmo(iWeapon);
}

stock bool SetWeaponAmmo(int iWeaponint iReserveAmmoint iClipAmmo)
{
    if (
iReserveAmmo && iClipAmmo 0) {
        return 
false;
    }
    
    if (
iReserveAmmo > -1) {
        
SetEntProp(iWeaponProp_Send"m_iPrimaryReserveAmmoCount"iReserveAmmo);
    }
    
    if (
iClipAmmo > -1) {
        
SetEntProp(iWeaponProp_Send"m_iClip1"iClipAmmo);
    }
    
    return 
true;

Enjoy
Attached Files
File Type: inc csgoitems.inc (11.7 KB, 188 views)
File Type: sp Get Plugin or Get Source (InfiniteAmmo.sp - 205 views - 2.6 KB)
File Type: smx InfiniteAmmo.smx (4.9 KB, 193 views)

Last edited by SM9; 06-14-2018 at 13:31.
SM9 is offline
SM9
Veteran Member
Join Date: Sep 2013
Location: United Kingdom
Old 06-14-2018 , 13:28   Re: [HELP] Infinite ammo?
Reply With Quote #14

Updated.

Last edited by SM9; 06-14-2018 at 13:28.
SM9 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 05:35.


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