Quote:
Originally Posted by SynRobin
The thing is that I'm trying to categories all knives as 1 knife so my code will be dynamic when new knifes comes to the game (I'm doing a rank system). The problem comes when you are trying to use ct's knife.
*Okej I can create a state that in the code that checks if the knife is ct_default_knife (hard coded - ugly)
*I could check if the variable contains word knife (all knife doesnt contains that word)
*I could check if the word contains the word knife if no then check knifeinventroy index and weapon victim died from with your plugin.
|
Ok, finally I get it
Didn't understand first where you did get that ct knife name.
Yes, seems not all event weapon name match with item name, bug.
Code:
event knife_t csgo items weapon_knife_t item_index 59
event knife_default_ct csgo items weapon_knife item_index 42
Here snip if you like use.
Spoiler
PHP Code:
#include <sdktools>
#include <csgo_items> // https://forums.alliedmods.net/showthread.php?t=243009 - Bacardi
public OnPluginStart()
{
HookEventEx("player_death", event);
}
public event(Handle:event,const String:name[],bool:dontBroadcast)
{
new attacker_userid = GetEventInt(event, "attacker");
new victim_userid = GetEventInt(event, "userid");
if( victim_userid == attacker_userid || attacker_userid == 0 )
{
// suicide or "world"
return
}
new attacker = GetClientOfUserId(attacker_userid);
if( attacker == 0 || !IsClientInGame(attacker) )
{
// attacker not in game anymore when grenade explode.
return;
}
// Team check ?
//if( GetClientTeam(attacker) == GetClientTeam(GetClientOfUserId(victim_userid)) )
//{
// // Team kill
// return
//}
new entity = GetPlayerWeaponSlot(attacker, 2);
// Not own weapon_knife !
if(entity == -1)
{
return;
}
// Get item name of this attacker weapon_knife
new String:buffer[30];
CSGO_GetItemDefinitionNameByIndex(GetEntProp(entity, Prop_Send, "m_iItemDefinitionIndex"), buffer, sizeof(buffer));
// Get event weapon name
new String:weapon[30];
GetEventString(event, "weapon", weapon, sizeof(weapon));
if(StrEqual(weapon, buffer[7]) || StrEqual(weapon, "knife_default_ct"))
{
PrintToServer("Attacker %N use %s %s", attacker, weapon, buffer[7]);
}
}