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

Refill Clip On Kill


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
MsNs7
Member
Join Date: Oct 2012
Location: Greece
Old 01-29-2015 , 03:30   Refill Clip On Kill
Reply With Quote #1

Hi.

There is already a nice plugin for that made by Root_, but unfortunately it doesn't do what i exactly want. His plugin obtains the clip's value of a gun from a file. What i want is a plugin which obtains it directly from CS:S/CS:GO.

I want that because i want the clip to be refilled to its default by the game value. As we all know, in recent CS:GO updates VALVe changed the clip's value of some guns. In my opinion it's uncomfortable every time VALVe does that, i have to change the values in the file.

I have wrote some code so far, but i'm not really sure if it correct.
Code:
#pragma semicolon 1
#include <sourcemod>

public Plugin:myinfo =
{
     name = "Refill Clip",
     author = "Silent Sniper",
     description = "Refills primary/secondary weapon's clip on kill. Works on CS:S/CS:GO.",
     version = "1.0",
     url = "http://www.css.setti.info/"
};

new primaryWeaponClip;
new secondaryWeaponClip;

public OnPluginStart()
{
     HookEvent("item_pickup", OnItemPickup);
     HookEvent("player_death", OnPlayerDeath);
}

public Action:OnItemPickup(Handle:event, const String:name[], bool:dontBroadcast)
{
     new player = GetClientOfUserId(GetEventInt(event, "userid"));
     new equippedWeapon;
     if (player != 0 && IsClientInGame(player) && IsPlayerAlive(player))
     {
          for (new i = 0; i <= 1; i++)
          {
               equippedWeapon = GetPlayerWeaponSlot(player, i);
               if (equippedWeapon == -1)
               {
                    continue;
               }
               if (i == 0)
               {
                    primaryWeaponClip = GetEntProp(equippedWeapon, Prop_Data, "m_iClip1");
               }
               else
               {
                    secondaryWeaponClip = GetEntProp(equippedWeapon, Prop_Data, "m_iClip1");
               }
          }
     }
}

public Action:OnPlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
     new attackerID = GetClientOfUserId(GetEventInt(event, "attacker"));
     if (attackerID != 0 && IsClientInGame(attackerID) && IsPlayerAlive(attackerID))
     {
          new primaryWeapon = GetPlayerWeaponSlot(attackerID, 0);
          new secondaryWeapon = GetPlayerWeaponSlot(attackerID, 1);
          new activeWeapon = GetEntPropEnt(attackerID, Prop_Data, "m_hActiveWeapon");
          if (activeWeapon != -1 && activeWeapon == primaryWeapon)
          {
               SetEntProp(activeWeapon, Prop_Send, "m_iClip1", primaryWeaponClip);
          }
          else if (activeWeapon != -1 && activeWeapon == secondaryWeapon)
          {
               SetEntProp(activeWeapon, Prop_Send, "m_iClip1", secondaryWeaponClip);
          }
     }
}
Thanks in advance.
__________________
Setti Steam Group
...you can achieve immortality, simply by doing one great thing...
MsNs7 is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 01-30-2015 , 03:46   Re: Refill Clip On Kill
Reply With Quote #2

Valve doesn't change clip size very often.

If you want to read from the server configs you need to read clip sizes from csgo/scripts/weapon_<classname>.txt

You could also store clip sizes on weapon spawn into a trie to avoid reading the script files like you code appears to be doing
__________________
Neuro Toxin is offline
Michalplyoutube
Veteran Member
Join Date: Jan 2013
Location: Tank Carrier in Mannhatt
Old 01-30-2015 , 03:50   Re: Refill Clip On Kill
Reply With Quote #3

Quote:
Originally Posted by MsNs7 View Post
Hi.

There is already a nice plugin for that made by Root_, but unfortunately it doesn't do what i exactly want. His plugin obtains the clip's value of a gun from a file. What i want is a plugin which obtains it directly from CS:S/CS:GO.

I want that because i want the clip to be refilled to its default by the game value. As we all know, in recent CS:GO updates VALVe changed the clip's value of some guns. In my opinion it's uncomfortable every time VALVe does that, i have to change the values in the file.

I have wrote some code so far, but i'm not really sure if it correct.
Code:
#pragma semicolon 1
#include <sourcemod>

public Plugin:myinfo =
{
     name = "Refill Clip",
     author = "Silent Sniper",
     description = "Refills primary/secondary weapon's clip on kill. Works on CS:S/CS:GO.",
     version = "1.0",
     url = "http://www.css.setti.info/"
};

new primaryWeaponClip;
new secondaryWeaponClip;

public OnPluginStart()
{
     HookEvent("item_pickup", OnItemPickup);
     HookEvent("player_death", OnPlayerDeath);
}

public Action:OnItemPickup(Handle:event, const String:name[], bool:dontBroadcast)
{
     new player = GetClientOfUserId(GetEventInt(event, "userid"));
     new equippedWeapon;
     if (player != 0 && IsClientInGame(player) && IsPlayerAlive(player))
     {
          for (new i = 0; i <= 1; i++)
          {
               equippedWeapon = GetPlayerWeaponSlot(player, i);
               if (equippedWeapon == -1)
               {
                    continue;
               }
               if (i == 0)
               {
                    primaryWeaponClip = GetEntProp(equippedWeapon, Prop_Data, "m_iClip1");
               }
               else
               {
                    secondaryWeaponClip = GetEntProp(equippedWeapon, Prop_Data, "m_iClip1");
               }
          }
     }
}

public Action:OnPlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
     new attackerID = GetClientOfUserId(GetEventInt(event, "attacker"));
     if (attackerID != 0 && IsClientInGame(attackerID) && IsPlayerAlive(attackerID))
     {
          new primaryWeapon = GetPlayerWeaponSlot(attackerID, 0);
          new secondaryWeapon = GetPlayerWeaponSlot(attackerID, 1);
          new activeWeapon = GetEntPropEnt(attackerID, Prop_Data, "m_hActiveWeapon");
          if (activeWeapon != -1 && activeWeapon == primaryWeapon)
          {
               SetEntProp(activeWeapon, Prop_Send, "m_iClip1", primaryWeaponClip);
          }
          else if (activeWeapon != -1 && activeWeapon == secondaryWeapon)
          {
               SetEntProp(activeWeapon, Prop_Send, "m_iClip1", secondaryWeaponClip);
          }
     }
}
Thanks in advance.
Hello there try instead of SetEnProp

SetEntProp(primaryWeapon, Prop_Send, "m_iClip1", primaryWeaponClip);
SetEntProp(secondaryWeapon, Prop_Send, "m_iClip1", secondaryWeaponClip);

new activeWeapon = GetEntPropEnt(attackerID, Prop_Data, "m_hActiveWeapon"); returns slot id

new CurrentWeaponAttacker = GetPlayerWeaponSlot(attackerID, activeWeapon);

0 primary
1 secondary
2 melee

If I m correct
__________________
The plugin developer of TF2BWR Reborn
And a TF2 Player
Michalplyoutube is offline
MsNs7
Member
Join Date: Oct 2012
Location: Greece
Old 01-30-2015 , 05:26   Re: Refill Clip On Kill
Reply With Quote #4

Quote:
Originally Posted by Neuro Toxin View Post
You could also store clip sizes on weapon spawn into a trie to avoid reading the script files like you code appears to be doing
That's what i was trying to do by hooking the item_pickup event. Well, not exactly what you recommended but i was saving the clip in a variable. But what you recommended seems to be better. I will reply as soon as i implement it so you check it.

Btw, is the item_pickup event what i need to hook? Or do i need to hook something else?
__________________
Setti Steam Group
...you can achieve immortality, simply by doing one great thing...

Last edited by MsNs7; 01-30-2015 at 05:27.
MsNs7 is offline
MsNs7
Member
Join Date: Oct 2012
Location: Greece
Old 01-30-2015 , 06:47   Re: Refill Clip On Kill
Reply With Quote #5

@ Michalplyoutube
Doesn't GetEntPropEnt(attackerID, Prop_Data, "m_hActiveWeapon"); return the entity index of a gun? Does it really return the id of a slot?
__________________
Setti Steam Group
...you can achieve immortality, simply by doing one great thing...

Last edited by MsNs7; 01-30-2015 at 08:25.
MsNs7 is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 02-01-2015 , 18:21   Re: Refill Clip On Kill
Reply With Quote #6

It returns the entity index for the weapon the player has in their hands.
__________________
Neuro Toxin is offline
Reply


Thread Tools
Display Modes

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 04:18.


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