View Single Post
iskenderkebab33
Senior Member
Join Date: Jun 2018
Old 07-14-2018 , 18:40   Re: CS:GO Give Player P250 after Killing 5 Enemy with Knife
Reply With Quote #5

Quote:
Originally Posted by micapat View Post
I'm not sure that it detects all the deaths with a knife:

PHP Code:
#include <sourcemod>
#include <sdkhooks>
#include <sdktools>

int gl_iPlayerKill[MAXPLAYERS 1];

public 
OnPluginStart() 
{
    
HookEvent("player_death"OnPlayerDeathPost);
}

public 
void OnClientConnected(int iClient)
{
    
gl_iPlayerKill[iClient] = 0;
}

public 
void OnClientPutInServer(int iClient)
{
    
SDKHook(iClientSDKHook_SpawnPostOnPlayerSpawnPost);
}

public 
void OnClientDisconnect(int iClient)
{
    
gl_iPlayerKill[iClient] = 0;
}

public 
void OnPlayerSpawnPost(int iPlayer)
{
    if (
IsPlayerAlive(iPlayer))
    {
        
gl_iPlayerKill[iPlayer] = 0;
    }
}

public 
void OnPlayerDeathPost(Event hEvent, const char[] szNamebool bDontBroadcast)
{
    
char szWeapon[32];
    
    
// Get the weapon name
    
hEvent.GetString("weapon"szWeaponsizeof(szWeapon));
    
    
// Check if the weapon is a knife
    
if (StrEqual(szWeapon"knife") || StrEqual(szWeapon"bayonet"))
    {
        
// Get the attacker
        
int iAttacker hEvent.GetInt("attacker");
        
        
// Check if it's a valid player
        
if ((<= iAttacker <= MaxClients) && IsClientInGame(iAttacker) && IsPlayerAlive(iAttacker))
        {
            
gl_iPlayerKill[iAttacker]++;
            
            if (
gl_iPlayerKill[iAttacker] == 5)
            {
                
GivePlayerItem(iAttacker"weapon_p250");
            }
        }
    }

thanks, gona test it now.
iskenderkebab33 is offline