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

Weapon skins and stattrak (kill on death)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Dr. Api
BANNED
Join Date: Mar 2015
Location: France
Old 06-12-2015 , 18:07   Weapon skins and stattrak (kill on death)
Reply With Quote #1

I post that here, think is the right place.
This is a ALPHA code/plugin and I will not continue anymore.

The goal of this plugin was not for the weapons skin but more for the kill stattrak updated on player_death.

I think the process is really bad but this is the only way I found for the stattrak update.

PHP Code:
/*     <DR.API PAINTS> (c) by <De Battista Clint - (http://doyou.watch)      */
/*                                                                           */
/*                    <DR.API PAINTS> is licensed under a                    */
/* Creative Commons Attribution-NonCommercial-NoDerivs 4.0 Unported License. */
/*                                                                             */
/*      You should have received a copy of the license along with this       */
/*  work.  If not, see <http://creativecommons.org/licenses/by-nc-nd/4.0/>.  */
//***************************************************************************//
//***************************************************************************//
//******************************DR.API PAINTS********************************//
//***************************************************************************//
//***************************************************************************//

/*
"weapon_usp_silencer",             //61
"weapon_glock",                 //4
"weapon_p250",                     //36
"weapon_fiveseven",             //3
"weapon_deagle",                 //1
"weapon_elite",                 //2
"weapon_hkp2000",                //32
"weapon_tec9"                     //30


"weapon_nova",                     //35
"weapon_xm1014",                 //25
"weapon_mag7",                     //27
"weapon_sawedoff"                 //29

"weapon_mp9",                     //34
"weapon_mac10",                 //17
"weapon_mag7",                     //27
"weapon_mp7",                     //33
"weapon_ump45",                 //24
"weapon_p90",                     //19
"weapon_bizon"                     //26

"weapon_famas",                 //10
"weapon_m4a1",                     //16
"weapon_m4a1_silencer",         //60
"weapon_galilar",                 //13
"weapon_ak47",                     //7
"weapon_ssg08",                 //40
"weapon_aug",                     //8
"weapon_sg556",                 //39
"weapon_awp",                     //9
"weapon_scar20",                 //38
"weapon_g3sg1"                     //11
                                                                    
*/
                                                                    
#pragma semicolon 1 

//***********************************//
//*************DEFINE****************//
//***********************************//
#define PLUGIN_VERSION                     "1.0"
#define CVARS                             FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY
#define DEFAULT_FLAGS                     FCVAR_PLUGIN|FCVAR_NOTIFY
#define TAG_CHAT                        "[PAINTS] -"
#define MAX_WEAPONS                        48
#define MAX_WEAPONS_INDEX                600

//***********************************//
//*************INCLUDE***************//
//***********************************//

#undef REQUIRE_PLUGIN
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <cstrike>
#include <autoexec>

#pragma newdecls required

//***********************************//
//***********PARAMETERS**************//
//***********************************//

//Handle
Handle cvar_active_paints_dev;

//Bool
bool B_cvar_active_paints_dev                                        false;

//Customs
int C_Weapon_kill[MAXPLAYERS 1][MAX_WEAPONS_INDEX];

//Informations plugin
public Plugin myinfo =
{
    
name "DR.API PAINTS",
    
author "Dr. Api",
    
description "DR.API PAINTS by Dr. Api",
    
version PLUGIN_VERSION,
    
url "http://zombie4ever.eu"
}
/***********************************************************/
/*********************** PLUGIN START **********************/
/***********************************************************/
public void OnPluginStart()
{
    
AutoExecConfig_SetFile("drapi_paints""sourcemod/drapi");
    
    
AutoExecConfig_CreateConVar("drapi_paints_version"PLUGIN_VERSION"Version"CVARS);
    
    
cvar_active_paints_dev            AutoExecConfig_CreateConVar("drapi_active_paints_dev",             "0",                     "Enable/Disable Dev Mod",                 DEFAULT_FLAGS,         true0.0,         true1.0);
    
    
HookEvent("player_death",     Event_PlayerDeath);
    
HookEvent("weapon_fire",     Event_WeaponFire);
    
    
HookEvents();
    
    
AutoExecConfig_ExecuteFile();
    
    
int i 1;
    while (
<= MaxClients)
    {
        if (
IsClientInGame(i))
        {
            
SDKHook(iSDKHook_WeaponEquipPostOnPostWeaponEquip);
        }
        
i++;
    }
    
    
RegConsoleCmd("sm_paint",                 Command_Paint,             "");
}

/***********************************************************/
/************************ PLUGIN END ***********************/
/***********************************************************/
public void OnPluginEnd()
{
    
int i 1;
    while (
<= MaxClients)
    {
        if (
IsClientInGame(i))
        {
            
SDKUnhook(iSDKHook_WeaponEquipPostOnPostWeaponEquip);
        }
        
i++;
    }
}

/***********************************************************/
/**************** WHEN CLIENT PUT IN SERVER ****************/
/***********************************************************/
public void OnClientPutInServer(int client)
{
    
SDKHook(clientSDKHook_WeaponEquipPostOnPostWeaponEquip);
}

/***********************************************************/
/***************** WHEN CLIENT DISCONNECT ******************/
/***********************************************************/
public void OnClientDisconnect(int client)
{
    
SDKUnhook(clientSDKHook_WeaponEquipPostOnPostWeaponEquip);
}

/***********************************************************/
/******************** WHEN CVAR CHANGED ********************/
/***********************************************************/
void HookEvents()
{
    
HookConVarChange(cvar_active_paints_dev,                 Event_CvarChange);
}

/***********************************************************/
/******************** WHEN CVARS CHANGE ********************/
/***********************************************************/
public void Event_CvarChange(Handle cvar, const char[] oldValue, const char[] newValue)
{
    
UpdateState();
}

/***********************************************************/
/*********************** UPDATE STATE **********************/
/***********************************************************/
void UpdateState()
{
    
B_cvar_active_paints_dev                     GetConVarBool(cvar_active_paints_dev);
}

/***********************************************************/
/******************* WHEN CONFIG EXECUTED ******************/
/***********************************************************/
public void OnConfigsExecuted()
{
    
//UpdateState();
}

/***********************************************************/
/********************* WHEN MAP START **********************/
/***********************************************************/
public void OnMapStart()
{
    
UpdateState();
}

/***********************************************************/
/********************** WHEN MAP END ***********************/
/***********************************************************/
public void OnMapEnd()
{

}

public 
Action Command_Paint(int clientint args)
{
    
char S_args1[256];
    
GetCmdArg(1S_args1sizeof(S_args1));
    
int weapon GetEntPropEnt(clientProp_Send"m_hActiveWeapon");
    
    
SetSkin(clientweaponStringToInt(S_args1), 0);
}

/***********************************************************/
/******************** WHEN ROUND START *********************/
/***********************************************************/
public void Event_WeaponFire(Handle eventchar[] namebool dontBroadcast)
{
    
int client                     GetClientOfUserId(GetEventInt(event"userid"));
    
int weapon                     GetEntPropEnt(clientProp_Send"m_hActiveWeapon");
    
    
char S_Weaponname[64];
    if(
GetEdictClassname(weaponS_Weaponnamesizeof(S_Weaponname)) && StrEqual(S_Weaponname"weapon_knife") == false)
    {
        
/*
        int ammo                     = GetPrimaryAmmo(client, weapon);
        int clip                     = Weapon_GetPrimaryClip(weapon);
        
        int ammoreserve                = GetEntProp(weapon, Prop_Send, "m_iPrimaryReserveAmmoCount");
        int ammoreserve2            = GetEntProp(weapon, Prop_Send, "m_iSecondaryReserveAmmoCount");
        
        int m_iItemIDHigh            = GetEntProp(weapon, Prop_Send, "m_iItemIDHigh");
        int m_iItemIDLow            = GetEntProp(weapon, Prop_Send, "m_iItemIDLow");
            
        int id                        = GetEntProp(weapon, Prop_Send, "m_OriginalOwnerXuidLow");
        int id2                        = GetEntProp(weapon, Prop_Send, "m_OriginalOwnerXuidHigh");
        
        int paintkit                 = GetEntProp(weapon, Prop_Send, "m_iEntityQuality");
        */    
        
        
int m_zoomLevel     GetEntProp(weaponProp_Send"m_zoomLevel");
        
int m_iFOV             GetEntProp(clientProp_Send"m_iFOV");
        
int m_bIsScoped     GetEntProp(clientProp_Send"m_bIsScoped");
        
int m_bResumeZoom     GetEntProp(clientProp_Send"m_bResumeZoom");
        
        
PrintToChat(client"Zoom: %i, Fov: %i; scope: %i, resume: %i"m_zoomLevelm_iFOVm_bIsScopedm_bResumeZoom);
    }
}

/***********************************************************/
/******************* WHEN PLAYER SPAWN *********************/
/***********************************************************/
public void Event_PlayerDeath(Handle event, const char[] namebool dontBroadcast)
{
    
int attacker             GetClientOfUserId(GetEventInt(event"attacker"));
    
int weapon                 GetEntPropEnt(attackerProp_Send"m_hActiveWeapon");
    
    if(
weapon != -1)
    {
        
int weaponindex     GetEntProp(weaponProp_Send"m_iItemDefinitionIndex");
        
int ammo             GetPrimaryAmmo(attackerweapon);
        
int clip1             Weapon_GetPrimaryClip(weapon) - 1;
        
        
C_Weapon_kill[attacker][weaponindex]++;
        
        
Handle dataPackHandle;
        
CreateDataTimer(0.0TimerData_OnPlayerDeathdataPackHandle);
        
WritePackCell(dataPackHandleEntIndexToEntRef(weapon));
        
WritePackCell(dataPackHandleGetClientUserId(attacker));
        
WritePackCell(dataPackHandleammo);
        
WritePackCell(dataPackHandleclip1);
    }
}

/***********************************************************/
/************ TIMER DATA ON POST WEAPON EQUIP **************/
/***********************************************************/
public Action TimerData_OnPlayerDeath(Handle timerHandle dataPackHandle)
{    

    
ResetPack(dataPackHandle);
    
int weapon         EntRefToEntIndex(ReadPackCell(dataPackHandle));
    
int client         GetClientOfUserId(ReadPackCell(dataPackHandle));
    
int ammo         ReadPackCell(dataPackHandle);
    
int clip1         ReadPackCell(dataPackHandle);
    
int paintkit     GetEntProp(weaponProp_Send"m_nFallbackPaintKit");
    
int kill        GetEntProp(weaponProp_Send"m_nFallbackStatTrak");

    if(
weapon == INVALID_ENT_REFERENCE || !IsClientInGame(client) || !IsPlayerAlive(client)) return;
    
    if(
weapon || !IsValidEdict(weapon) || !IsValidEntity(weapon)) return;
    
    if(
kill == -1)
    {
        
kill 0;
    }
    
    
int weaponindex     GetEntProp(weaponProp_Send"m_iItemDefinitionIndex");
    
SetKill(clientweaponpaintkitC_Weapon_kill[client][weaponindex], ammoclip1);
}

/***********************************************************/
/****************** ON POST WEAPON EQUIP *******************/
/***********************************************************/
public Action OnPostWeaponEquip(int clientint weapon)
{
    if(
weapon != -1)
    {
        
Handle dataPackHandle;
        
CreateDataTimer(0.0TimerData_OnPostWeaponEquipdataPackHandle);
        
WritePackCell(dataPackHandleEntIndexToEntRef(weapon));
        
WritePackCell(dataPackHandleGetClientUserId(client));
    }
}

/***********************************************************/
/************ TIMER DATA ON POST WEAPON EQUIP **************/
/***********************************************************/
public Action TimerData_OnPostWeaponEquip(Handle timerHandle dataPackHandle)
{
    
ResetPack(dataPackHandle);
    
int weapon         EntRefToEntIndex(ReadPackCell(dataPackHandle));
    
int client         GetClientOfUserId(ReadPackCell(dataPackHandle));
    
    if(
weapon == INVALID_ENT_REFERENCE || !IsClientInGame(client) || !IsPlayerAlive(client)) return;
    
    if(
weapon || !IsValidEdict(weapon) || !IsValidEntity(weapon)) return;

    
int weaponindex     GetEntProp(weaponProp_Send"m_iItemDefinitionIndex");

    
SetSkin(clientweapon8C_Weapon_kill[client][weaponindex]);
}

/***********************************************************/
/******************** SET KNIFE SKIN ***********************/
/***********************************************************/
void SetSkin(int clientint weaponint paintkitint kill)
{
    if(
GetEntProp(weaponProp_Send"m_hPrevOwner") > || (GetEntProp(weaponProp_Send"m_iItemIDHigh") == && GetEntProp(weaponProp_Send"m_iItemIDLow") == 2048))
    {
        return;
    }
    
    
int weaponindex GetEntProp(weaponProp_Send"m_iItemDefinitionIndex");
    
    
//31 = Taser - 42 = CT knife default - 59 = T knife default
    
if(weaponindex == 31 || weaponindex == 42 || weaponindex == 59)
    {
        return;
    }
    
    if(
GetPlayerWeaponSlot(clientCS_SLOT_KNIFE) == weapon
    
||GetPlayerWeaponSlot(clientCS_SLOT_PRIMARY) == weapon
    
||GetPlayerWeaponSlot(clientCS_SLOT_SECONDARY) == weapon
    
/*||GetPlayerWeaponSlot(client, CS_SLOT_C4) == weapon*/)
    {
        
int silenceron     GetEntProp(weaponProp_Send"m_bSilencerOn");
        
        
char S_Classname[64];
        if(
GetEdictClassname(weaponS_Classnamesizeof(S_Classname)))
        {
        
            
char S_Weaponname_2[64];
            if(
StrEqual(S_Classname"weapon_hkp2000") == false)
            {
                if(
silenceron)
                {
                    
Format(S_Weaponname_2sizeof(S_Weaponname_2), "%s_silencer"S_Classname);
                }
                else
                {
                    
Format(S_Weaponname_2sizeof(S_Weaponname_2), "%s"S_Classname);
                }
            }
            else
            {
                if(
silenceron)
                {
                    
Format(S_Weaponname_2sizeof(S_Weaponname_2), "weapon_usp_silencer");
                }
                else
                {
                    
Format(S_Weaponname_2sizeof(S_Weaponname_2), "weapon_hkp2000");
                }            
            }
            
            
RemovePlayerItem(clientweapon);
            
AcceptEntityInput(weapon"Kill");
            
            
int new_weapon GivePlayerItem(clientS_Weaponname_2);
            
EquipPlayerWeapon(clientnew_weapon);
            
FakeClientCommand(client"use %s"S_Weaponname_2);
            
            
int m_iItemIDHigh                        GetEntProp(new_weaponProp_Send"m_iItemIDHigh");
            
int m_iItemIDLow                        GetEntProp(new_weaponProp_Send"m_iItemIDLow");

            
SetEntProp(new_weaponProp_Send"m_iItemIDLow"2048);
            
SetEntProp(new_weaponProp_Send"m_iItemIDHigh"0);

            
SetEntProp(new_weaponProp_Send"m_nFallbackPaintKit"paintkit);
            
            
/* 1.0 pattern invisible, 0.5 = 50% visible*/
            
SetEntPropFloat(new_weaponProp_Send"m_flFallbackWear"0.0);
            
            
/* Kill number visible on knife */
            
SetEntProp(new_weaponProp_Send"m_nFallbackStatTrak"kill);
            
            
/* 1 = Authentic, 2 = Retro, 3 = (*) */
            
SetEntProp(new_weaponProp_Send"m_iEntityQuality"3);
            
            
            
Handle dataPackHandle2;
            
CreateDataTimer(0.004TimerData_RestoreItemIDdataPackHandle2);
            
WritePackCell(dataPackHandle2EntIndexToEntRef(new_weapon));
            
WritePackCell(dataPackHandle2m_iItemIDHigh);
            
WritePackCell(dataPackHandle2m_iItemIDLow);
        }
    }
}

/***********************************************************/
/******************** SET KNIFE SKIN ***********************/
/***********************************************************/
void SetKill(int clientint weaponint paintkitint killint ammoint clip1)
{
    if(
GetEntProp(weaponProp_Send"m_OriginalOwnerXuidLow") != 0)
    {
        
int weaponindex GetEntProp(weaponProp_Send"m_iItemDefinitionIndex");
        
        
//31 = Taser - 42 = CT knife default - 59 = T knife default
        
if(weaponindex == 31 || weaponindex == 42 || weaponindex == 59)
        {
            return;
        }
        
        if(
GetPlayerWeaponSlot(clientCS_SLOT_KNIFE) == weapon
        
||GetPlayerWeaponSlot(clientCS_SLOT_PRIMARY) == weapon
        
||GetPlayerWeaponSlot(clientCS_SLOT_SECONDARY) == weapon
        
/*||GetPlayerWeaponSlot(client, CS_SLOT_C4) == weapon*/)
        {
            
char S_Classname[64];
            if(
GetEdictClassname(weaponS_Classnamesizeof(S_Classname)))
            {
                
int silenceron     GetEntProp(weaponProp_Send"m_bSilencerOn");
                
                
char S_Weaponname_2[64];
                if(
StrEqual(S_Classname"weapon_hkp2000") == false)
                {
                    if(
silenceron)
                    {
                        
Format(S_Weaponname_2sizeof(S_Weaponname_2), "%s_silencer"S_Classname);
                    }
                    else
                    {
                        
Format(S_Weaponname_2sizeof(S_Weaponname_2), "%s"S_Classname);
                    }
                }
                else
                {
                    if(
silenceron)
                    {
                        
Format(S_Weaponname_2sizeof(S_Weaponname_2), "weapon_usp_silencer");
                    }
                    else
                    {
                        
Format(S_Weaponname_2sizeof(S_Weaponname_2), "weapon_hkp2000");
                    }            
                }
                
                
int m_zoomLevel     GetEntProp(weaponProp_Send"m_zoomLevel");
                
int m_iFOV             GetEntProp(clientProp_Send"m_iFOV");
                
int m_bIsScoped     GetEntProp(clientProp_Send"m_bIsScoped");
                
int m_bResumeZoom     GetEntProp(clientProp_Send"m_bResumeZoom");
                    
                
RemovePlayerItem(clientweapon);
                
AcceptEntityInput(weapon"Kill");
                
                
int new_weapon GivePlayerItem(clientS_Weaponname_2);
                
EquipPlayerWeapon(clientnew_weapon);
                
FakeClientCommand(client"use %s"S_Weaponname_2);
                
                
float time 0.0;
                
/* AWP and SCOUT need some time when they fire */
                
if(StrEqual(S_Weaponname_2"weapon_awp"false
                || 
StrEqual(S_Weaponname_2"weapon_ssg08"false))
                {
                    
time 1.20;
                }
                
/* Others sniper doesn't need time and should reset the sates */
                
else if(StrEqual(S_Weaponname_2"weapon_scar20"false
                || 
StrEqual(S_Weaponname_2"weapon_aug"false)
                || 
StrEqual(S_Weaponname_2"weapon_g3sg1"false)
                || 
StrEqual(S_Weaponname_2"weapon_sg556"false))
                {
                    
SetEntProp(weaponProp_Send"m_zoomLevel"m_zoomLevel);
                    
SetEntProp(clientProp_Send"m_iFOV"m_iFOV);
                    
SetEntProp(clientProp_Send"m_bIsScoped"m_bIsScoped);
                    
SetEntProp(clientProp_Send"m_bResumeZoom"m_bResumeZoom);
                }    
                
                if(
StrContains(S_Weaponname_2"weapon_knife"false) == -|| StrContains(S_Weaponname_2"weapon_bayonet"false) == -1
                {
                    
Handle dataPackHandle;
                    
CreateDataTimer(0.0TimerData_SetCorrectAmmodataPackHandle);
                    
WritePackCell(dataPackHandleEntIndexToEntRef(new_weapon));
                    
WritePackCell(dataPackHandleGetClientUserId(client));
                    
WritePackCell(dataPackHandleammo);
                    
WritePackCell(dataPackHandleclip1);
                }
                
                
int m_iItemIDHigh    GetEntProp(new_weaponProp_Send"m_iItemIDHigh");
                
int m_iItemIDLow    GetEntProp(new_weaponProp_Send"m_iItemIDLow");

                
SetEntProp(new_weaponProp_Send"m_iItemIDLow"2048);
                
SetEntProp(new_weaponProp_Send"m_iItemIDHigh"0);

                
SetEntProp(new_weaponProp_Send"m_nFallbackPaintKit"paintkit);
                
                
/* 1.0 pattern invisible, 0.5 = 50% visible*/
                
SetEntPropFloat(new_weapon,Prop_Send"m_flFallbackWear"0.0);
                
                
/* Kill number visible on knife */
                
SetEntProp(new_weaponProp_Send"m_nFallbackStatTrak"kill);
                
                
/* 1 = Authentic, 2 = Retro, 3 = (*) */
                
SetEntProp(new_weaponProp_Send"m_iEntityQuality"3);
                
                
/* fast next primary attack for the weapon */
                
SetEntPropFloat(weaponProp_Send"m_flNextPrimaryAttack"time);
                
                
/* fast next attack for the player */
                
SetEntPropFloat(clientProp_Send"m_flNextAttack"GetGameTime() + time);
                
                
/* Shot Fired 1 or 0 does nothing */
                
SetEntProp(clientProp_Send"m_iShotsFired"0);
        
                
Handle dataPackHandle2;
                
CreateDataTimer(0.004 timeTimerData_RestoreItemIDKilldataPackHandle2);
                
WritePackCell(dataPackHandle2EntIndexToEntRef(new_weapon));
                
WritePackCell(dataPackHandle2GetClientUserId(client));
                
WritePackCell(dataPackHandle2m_iItemIDHigh);
                
WritePackCell(dataPackHandle2m_iItemIDLow);
                
WritePackCell(dataPackHandle2m_zoomLevel);
                
WritePackCell(dataPackHandle2m_iFOV);
                
WritePackCell(dataPackHandle2m_bIsScoped);
                
WritePackCell(dataPackHandle2m_bResumeZoom);
            }
        }
    }
}

/***********************************************************/
/************** TIMER DATA SET CORRECT AMMO ****************/
/***********************************************************/
public Action TimerData_SetCorrectAmmo(Handle timerHandle dataPackHandle)
{
    
ResetPack(dataPackHandle);
    
int weapon         EntRefToEntIndex(ReadPackCell(dataPackHandle));
    
int client         GetClientOfUserId(ReadPackCell(dataPackHandle));
    
int ammo         ReadPackCell(dataPackHandle);
    
int clip1         ReadPackCell(dataPackHandle);
    
    
char S_Classname[64];
    if(
GetEdictClassname(weaponS_Classnamesizeof(S_Classname)))
    {
        
SetEntProp(weaponProp_Send"m_iPrimaryReserveAmmoCount"0);
        
Client_SetWeaponAmmo(clientS_Classnameammo_clip1_);
    }
}

/***********************************************************/
/************** TIMER DATA RESTORE ITEM ID *****************/
/***********************************************************/
public Action TimerData_RestoreItemID(Handle timerHandle dataPackHandle)
{
    
ResetPack(dataPackHandle);
    
int weapon                                 EntRefToEntIndex(ReadPackCell(dataPackHandle));
    
int m_iItemIDHigh                         ReadPackCell(dataPackHandle);
    
int m_iItemIDLow                         ReadPackCell(dataPackHandle);

    if(
weapon != INVALID_ENT_REFERENCE)
    {
        
SetEntProp(weaponProp_Send"m_iItemIDHigh"m_iItemIDHigh);
        
SetEntProp(weaponProp_Send"m_iItemIDLow"m_iItemIDLow);
    }
}

/***********************************************************/
/************** TIMER DATA RESTORE ITEM ID *****************/
/***********************************************************/
public Action TimerData_RestoreItemIDKill(Handle timerHandle dataPackHandle)
{
    
ResetPack(dataPackHandle);
    
int weapon                                 EntRefToEntIndex(ReadPackCell(dataPackHandle));
    
int client                                 GetClientOfUserId(ReadPackCell(dataPackHandle));
    
int m_iItemIDHigh                         ReadPackCell(dataPackHandle);
    
int m_iItemIDLow                         ReadPackCell(dataPackHandle);
            
    
int m_zoomLevel                            ReadPackCell(dataPackHandle);
    
int m_iFOV                                ReadPackCell(dataPackHandle);
    
int m_bIsScoped                         ReadPackCell(dataPackHandle);
    
int m_bResumeZoom                         ReadPackCell(dataPackHandle);

    if(
weapon != INVALID_ENT_REFERENCE)
    {
        
SetEntProp(weaponProp_Send"m_iItemIDHigh"m_iItemIDHigh);
        
SetEntProp(weaponProp_Send"m_iItemIDLow"m_iItemIDLow);
        
        
/* This is for sniper weapons */
        
SetEntProp(weaponProp_Send"m_zoomLevel"m_zoomLevel);
        
SetEntProp(clientProp_Send"m_iFOV"m_iFOV);
        
SetEntProp(clientProp_Send"m_bIsScoped"m_bIsScoped);
        
SetEntProp(clientProp_Send"m_bResumeZoom"m_bResumeZoom);
    }
}

/***********************************************************/
/**************** CLIENT SET WEAPON AMMO *******************/
/***********************************************************/
stock bool Client_SetWeaponAmmo(int client, const char[] classNameint primaryAmmo=-1int secondaryAmmo=-1int primaryClip=-1int secondaryClip=-1)
{
    
int weapon Client_GetWeapon(clientclassName);
    
    if (
weapon == INVALID_ENT_REFERENCE
    {
        return 
false;
    }
    
    if (
primaryClip != -1
    {
        
Weapon_SetPrimaryClip(weaponprimaryClip);
    }
    if(
secondaryClip != -1
    {
        
Weapon_SetSecondaryClip(weaponsecondaryClip);
    }
    
Client_SetWeaponPlayerAmmoEx(clientweaponprimaryAmmosecondaryAmmo);
    
    return 
true;
}

/***********************************************************/
/******************* CLIENT GET WEAPON *********************/
/***********************************************************/
stock int Client_GetWeapon(int client, const char[] className)
{
    
int offset Client_GetWeaponsOffset(client) - 4;
    
int weapon INVALID_ENT_REFERENCE;
    for (
int i=0MAX_WEAPONSi++) 
    {
        
offset += 4;
        
        
weapon GetEntDataEnt2(clientoffset);
        
        if (!
Weapon_IsValid(weapon)) 
        {
            continue;
        }
        
        if (
Entity_ClassNameMatches(weaponclassName)) 
        {
            return 
weapon;
        }
    }

    return 
INVALID_ENT_REFERENCE;
}

/***********************************************************/
/*************** ENTITY CLASSNAME MATCHES ******************/
/***********************************************************/
stock bool Entity_ClassNameMatches(int entity, const char[] classNamebool partialMatch=false)
{
    
char entity_className[64];
    
Entity_GetClassName(entityentity_classNamesizeof(entity_className));

    if (
partialMatch
    {
        return (
StrContains(entity_classNameclassName) != -1);
    }

    return 
StrEqual(entity_classNameclassName);
}

/***********************************************************/
/***************** ENTITY GET CLASSNAME ********************/
/***********************************************************/
stock int Entity_GetClassName(int entitychar[] bufferint size)
{
    return 
GetEntPropString(entityProp_Data"m_iClassname"buffersize);    
}

/***********************************************************/
/******************** WEAPON IS VALID **********************/
/***********************************************************/
stock int Weapon_IsValid(int weapon)
{
    if (!
IsValidEdict(weapon)) 
    {
        return 
false;
    }
    
    return 
Entity_ClassNameMatches(weapon"weapon_"true);
}

/***********************************************************/
/*************** GET WEAPON CLIENT OFFSET ******************/
/***********************************************************/
stock int Client_GetWeaponsOffset(int client)
{
    
int offset = -1;

    if (
offset == -1
    {
        
offset FindDataMapOffs(client"m_hMyWeapons");
    }
    
    return 
offset;
}

/***********************************************************/
/**************** GET PRIMARY CLIP WEAPON ******************/
/***********************************************************/
stock int Weapon_GetPrimaryClip(int weapon)
{
    return 
GetEntProp(weaponProp_Data"m_iClip1");
}

/***********************************************************/
/**************** GET PRIMARY CLIP WEAPON ******************/
/***********************************************************/
stock int Weapon_GetSecondaryClip(int weapon)
{
    return 
GetEntProp(weaponProp_Data"m_iClip2");
}

/***********************************************************/
/**************** SET PRIMARY CLIP WEAPON ******************/
/***********************************************************/
stock int Weapon_SetPrimaryClip(int weaponint value)
{
    
SetEntProp(weaponProp_Data"m_iClip1"value);
}

/***********************************************************/
/************** SET SECONDARY CLIP WEAPON ******************/
/***********************************************************/
stock int Weapon_SetSecondaryClip(int weaponint value)
{
    
SetEntProp(weaponProp_Data"m_iClip2"value);
}

/***********************************************************/
/**************** SET AMMO PLAYER WEAPON *******************/
/***********************************************************/
stock void Client_SetWeaponPlayerAmmoEx(int clientint weaponint primaryAmmo=-1int secondaryAmmo=-1)
{
    
int offset_ammo FindDataMapOffs(client"m_iAmmo");

    if (
primaryAmmo != -1
    {
        
int offset offset_ammo + (Weapon_GetPrimaryAmmoType(weapon) * 4);
        
SetEntData(clientoffsetprimaryAmmo4true);
    }

    if (
secondaryAmmo != -1
    {
        
int offset offset_ammo + (Weapon_GetSecondaryAmmoType(weapon) * 4);
        
SetEntData(clientoffsetsecondaryAmmo4true);
    }
}

/***********************************************************/
/***************** GET PRIMARY AMMO TYPE *******************/
/***********************************************************/
stock int Weapon_GetPrimaryAmmoType(int weapon)
{
    return 
GetEntProp(weaponProp_Data"m_iPrimaryAmmoType");
}

/***********************************************************/
/**************** GET SECONDARY AMMO TYPE ******************/
/***********************************************************/
stock int Weapon_GetSecondaryAmmoType(int weapon)
{
    return 
GetEntProp(weaponProp_Data"m_iSecondaryAmmoType");
}

/***********************************************************/
/******************** GET PRIMARY AMMO *********************/
/***********************************************************/
stock int GetPrimaryAmmo(int clientint weapon)
{
    
int ammotype Weapon_GetPrimaryAmmoType(weapon);
    if(
ammotype == -1
    {
        return -
1;
    }
    
    return 
GetEntProp(clientProp_Send"m_iAmmo"_ammotype);
}

/***********************************************************/
/********************* IS VALID CLIENT *********************/
/***********************************************************/
stock bool Client_IsValid(int clientbool checkConnected=true)
{
    if (
client 4096) {
        
client EntRefToEntIndex(client);
    }

    if (
client || client MaxClients) {
        return 
false;
    }

    if (
checkConnected && !IsClientConnected(client)) {
        return 
false;
    }
    
    return 
true;
}

/***********************************************************/
/******************** IS CLIENT IN GAME ********************/
/***********************************************************/
stock bool Client_IsIngame(int client)
{
    if (!
Client_IsValid(clientfalse)) {
        return 
false;
    }

    return 
IsClientInGame(client);

If you want to get the correct ammo and clip you should use: https://forums.alliedmods.net/showthread.php?t=263717
Otherwise I tried to get the ammo for weapon and it always return 0;
For example this function:
PHP Code:
stock GetReserveAmmo(clientweapon)
{
    new 
ammotype GetEntProp(weaponProp_Send"m_iPrimaryAmmoType");
    if(
ammotype == -1) return -1;
    
    return 
GetEntProp(clientProp_Send"m_iAmmo"_ammotype);

I have some bugs with the machines guns and two snipers aug and sg556 as I remember... for other weapons the stattrak works well.
Also you will need to check if the weapon is silencer or use the m_iItemDefinitionIndex cause weapon_hkp2000 equal weapon_usp_silencer for the CT team same when you equip a weapon_m4a1_silencer it will return weapon_m4a1....

Credits to Neuro Toxin who made the first Weapon Skins: Always Weapon Skins

Last edited by Dr. Api; 06-12-2015 at 18:12.
Dr. Api 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 19:58.


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