AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Refill Clip On Kill (https://forums.alliedmods.net/showthread.php?t=257033)

MsNs7 01-29-2015 03:30

Refill Clip On Kill
 
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.

Neuro Toxin 01-30-2015 03:46

Re: Refill Clip On Kill
 
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

Michalplyoutube 01-30-2015 03:50

Re: Refill Clip On Kill
 
Quote:

Originally Posted by MsNs7 (Post 2255780)
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

MsNs7 01-30-2015 05:26

Re: Refill Clip On Kill
 
Quote:

Originally Posted by Neuro Toxin (Post 2256205)
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?

MsNs7 01-30-2015 06:47

Re: Refill Clip On Kill
 
@ 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?

Neuro Toxin 02-01-2015 18:21

Re: Refill Clip On Kill
 
It returns the entity index for the weapon the player has in their hands.


All times are GMT -4. The time now is 23:59.

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