开发知识点:
代码赏析:
public void OnPluginStart()
{
HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy); //Hook每回合开始事件
HookEvent("player_spawn",Event_Spawn); //Hook玩家重生事件
}
public void Event_RoundStart(Event event, const char[] name, bool dontBroadcast)
{
for (int i = 1; i < MAXPLAYERS; i++) {
if (IsClientInGame(i) && IsPlayerAlive(i)) {
StripWeapons(i);//删除武器
}
}
}
public void Event_Spawn(Event event, const char[] name, bool dontBroadcast)
{
RequestFrame(RequestFrame_Callback, event.GetInt("userid"));
}
public void RequestFrame_Callback(int client)
{
if(!(client = GetClientOfUserId(client))) return;
switch(GetClientTeam(client))
{
case Team_T:
{
StripWeapons(client); //如果玩家属于T阵营,那么删除玩家当前的武器
GivePlayerItem(client, "weapon_knife");//给玩家装备上匕首
return;
}
}
//移除武器
stock void StripWeapons(int client)
{
RemoveWeaponBySlot(client, Slot_Primary); //移除主武器
RemoveWeaponBySlot(client, Slot_Secondary); //移除服务器
RemoveWeaponBySlot(client, Slot_Knife); //移除匕首
while(RemoveWeaponBySlot(client)) {}
}
stock bool RemoveWeaponBySlot(int client, int slot = Slot_Grenade)
{
int ent = GetPlayerWeaponSlot(client, slot);
return ent > MaxClients && RemovePlayerItem(client, ent) && AcceptEntityInput(ent, "Kill");
}
参考: