Syntax: Select all
#include <sourcemod>
#include <sdktools>
#include <cstrike>
#pragma semicolon 1
new String:gS_Knives[][] =
{
"weapon_bayonet",
"weapon_knife_gut",
"weapon_knife_flip",
"weapon_knife_m9_bayonet",
"weapon_knife_karambit"
};
public Plugin:myinfo =
{
name = "CS:GO knives example",
author = "shavit",
version = "1.0"
}
public OnPluginStart()
{
HookEvent("item_pickup", Item_Pickup);
}
public Action:Item_Pickup(Handle:event, const String:name[], bool:dB)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
if(!IsValidClient(client))
{
return Plugin_Continue;
}
new String:weapon[32];
GetEventString(event, "item", weapon, 32);
if(StrContains(weapon, "knife", false) != -1)
{
new currentknife = GetPlayerWeaponSlot(client, 2);
if(currentknife != INVALID_ENT_REFERENCE)
{
RemovePlayerItem(client, currentknife);
}
new knife = GivePlayerItem(client, gS_Knives[GetRandomInt(0, sizeof(gS_Knives))]);
EquipPlayerWeapon(client, knife);
}
return Plugin_Continue;
}
// Stocks
stock bool:IsValidClient(client, bool:alive = false)
{
return (client >= 1 && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client) && (alive == false || IsPlayerAlive(client)));
}
I'm trying to give different knives in csgo, it wont work to remove knife and and spawn another.
This method should work. I wonder how to do it in SP?