Member
Join Date: Mar 2020
Location: Street (Homeless)
|
02-21-2023
, 19:49
Re: [CSGO] how to fix this?
|
#13
|
Quote:
Originally Posted by Bacardi
I may missunderstood 1st post, I'm not sure did you want infinite ammo ?
...or only fast reload?
*edit
I added reload part, this code is experiment.
It check client reload button, check ammo count from clip how fill it is,
then take reserve ammo into clip until reserve ammo are no left.
But again, this not speed up reload animation, when you empty your clip to zero.
PHP Code:
// "items" -> "2" -> "prefab" "weapon_elite_prefab"
// "prefabs" -> "weapon_awp_prefab" -> "attributes" -> "primary clip size" "30"
#define ITEMSGAMEFILE "scripts/items/items_game.txt"
#define ADMCOMMAND "access_infinite_ammo" // admin access
#include <cstrike>
enum struct WpnInfo
{
ArrayList data;
int GetPrimaryClipSize(int itemdefinition)
{
if(this.data == null)
return -1;
int index = this.data.FindValue(itemdefinition, 0);
if(index == -1)
return -1;
return this.data.Get(index, 1);
}
void StorePrimaryClipSize(int itemdefinition, int size)
{
int tmp[2];
tmp[0] = itemdefinition;
tmp[1] = size;
if(this.data != null)
this.data.PushArray(tmp, sizeof(tmp));
}
void CreateData()
{
if(this.data == null)
this.data = new ArrayList(2);
this.data.Clear();
}
}
WpnInfo wpninfo;
ConVar cvar;
public void OnPluginStart()
{
KeyValues items_game = new KeyValues("items_game");
if(!items_game.ImportFromFile(ITEMSGAMEFILE))
SetFailState("Couldn't import file %s", ITEMSGAMEFILE);
wpninfo.CreateData();
char key[250], value[100];
int itemdefinition = -1;
int clip = -1;
for(CSWeaponID id = CSWeapon_NONE; id < CSWeapon_MAX_WEAPONS; id++)
{
itemdefinition = -1;
clip = -1;
if(!CS_IsValidWeaponID(id))
continue;
itemdefinition = CS_WeaponIDToItemDefIndex(id);
Format(key, sizeof(key), "items/%i/prefab", itemdefinition);
if(items_game.JumpToKey(key))
{
items_game.GetString(NULL_STRING, value, sizeof(value), "-1");
items_game.GoBack();
}
Format(key, sizeof(key), "prefabs/%s/attributes/primary clip size", value);
if(items_game.JumpToKey(key))
{
items_game.GetString(NULL_STRING, value, sizeof(value), "-1");
items_game.GoBack();
clip = StringToInt(value);
}
if(clip == -1)
continue;
//PrintToServer("itemdefinition %i, clip %i", itemdefinition, clip);
wpninfo.StorePrimaryClipSize(itemdefinition, clip);
}
delete items_game;
cvar = CreateConVar("sm_instant_reload", "0", "Should VIP get unlimited ammo?");
//HookEvent("weapon_fire", weapon_fire);
//HookEvent("weapon_fire_on_empty", weapon_fire);
}
public void OnPlayerRunCmdPre(int client, int buttons, int impulse, const float vel[3], const float angles[3], int weapon, int subtype, int cmdnum, int tickcount, int seed, const int mouse[2])
{
if(!(buttons & IN_RELOAD))
{
return;
}
int m_iPlayerState = GetEntProp(client, Prop_Send, "m_iPlayerState");
if(m_iPlayerState)
return;
if(wpninfo.data == null)
return;
int activeweapon = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
if(activeweapon == -1)
return;
int AmmoIndex = GetEntProp(activeweapon, Prop_Send, "m_iPrimaryAmmoType");
if(AmmoIndex == -1)
return;
if(!HasEntProp(activeweapon, Prop_Send, "m_iPrimaryReserveAmmoCount"))
return;
int AmmoCount = GetEntProp(activeweapon, Prop_Send, "m_iPrimaryReserveAmmoCount");
if(AmmoCount <= 0)
return;
PrintToServer("\n%i", AmmoCount);
if(!HasEntProp(activeweapon, Prop_Send, "m_iItemDefinitionIndex"))
return;
int itemdefinition = GetEntProp(activeweapon, Prop_Send, "m_iItemDefinitionIndex");
int m_iClip1 = GetEntProp(activeweapon, Prop_Send, "m_iClip1");
int DefaultClipSize = wpninfo.GetPrimaryClipSize(itemdefinition);
if(DefaultClipSize == -1 || DefaultClipSize == m_iClip1)
return;
int ClipAmmo = DefaultClipSize - m_iClip1;
if(ClipAmmo <= 0) // error ?
return;
int Count = AmmoCount - ClipAmmo;
if(Count > 0)
{
SetEntProp(activeweapon, Prop_Send, "m_iClip1", m_iClip1 + ClipAmmo);
SetEntProp(activeweapon, Prop_Send, "m_iPrimaryReserveAmmoCount", Count);
}
else
{
SetEntProp(activeweapon, Prop_Send, "m_iClip1", m_iClip1 + AmmoCount);
SetEntProp(activeweapon, Prop_Send, "m_iPrimaryReserveAmmoCount", 0);
}
SetEntProp(activeweapon, Prop_Send, "m_bReloadVisuallyComplete", true); // maybe not supported, server side
SetEntPropFloat(activeweapon, Prop_Send, "m_flNextPrimaryAttack", GetGameTime() + 0.1);
SetEntPropFloat(activeweapon, Prop_Send, "m_flNextSecondaryAttack", GetGameTime() + 0.1);
//m_bReloadVisuallyComplete
}
public void weapon_fire(Event event, const char[] name, bool dontBroadcast)
{
if(!cvar.BoolValue)
return;
int userid = event.GetInt("userid");
int client = GetClientOfUserId(userid);
if(IsFakeClient(client) || !CheckCommandAccess(client, ADMCOMMAND, 0, true))
return;
int m_hActiveWeapon = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
if(!HasEntProp(m_hActiveWeapon, Prop_Send, "m_iItemDefinitionIndex"))
return;
if(wpninfo.data == null)
return;
int itemdefinition = GetEntProp(m_hActiveWeapon, Prop_Send, "m_iItemDefinitionIndex");
int m_iClip1 = wpninfo.GetPrimaryClipSize(itemdefinition);
//PrintToServer("Client %N weapon %i GetPrimaryClipSize %i itemdefinition %i", client, m_hActiveWeapon, m_iClip1, itemdefinition);
if(m_iClip1 != -1)
SetEntProp(m_hActiveWeapon, Prop_Send, "m_iClip1", m_iClip1+1);
}
|
yes i only want just fast reload plugin ... if its possible to help me with this its ok.. if not that's it
|
|