Raised This Month: $32 Target: $400
 8% 

How to print in chat when a player is killed by a bot


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
nikitos1ck
New Member
Join Date: Feb 2021
Old 11-21-2022 , 18:16   How to print in chat when a player is killed by a bot
Reply With Quote #1

Hello, I've just started learning SourcePawn.
I'm currently trying to make a plugin that prints in chat when a player is killed by a bot and I'm struggling with it.
I believe it somehow should work with player_death event and IsFakeClient but I don't know how to make it work.
Can you please give me advice?
'
nikitos1ck is offline
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 11-21-2022 , 23:24   Re: How to print in chat when a player is killed by a bot
Reply With Quote #2

PRO TIP: When posting, always specify the game you are referring to since SourceMod is used in over a dozen games.

Since you didn't specify a game, we'll work on a solution that should work with most Source Games. To do that, we'll need to find the right event to hook. We'll look here and will select 'Generic Source Events': https://wiki.alliedmods.net/Game_Events_(Source)

If we look at player_death under generic events we see that the game reports the userid of the player killed and the userid of the attacker who killed him.

So... we can 'hook' the death event, get the userids of the killer and the victim. We can then check to see if the player is human and the attacker is a Bot. If so, we can print their names to chat.

The code would look like this:
PHP Code:
#pragma semicolon 1
#pragma newdecls required

#define PLUGIN_VERSION "1.0"

public Plugin myinfo =
{
    
name "Killed by Bot",
    
author "nikitos1ck",
    
description "Sends message to chat when a human player is killed by a Bot",
    
version PLUGIN_VERSION,
    
url "www.sourcemod.com"
}

public 
void OnPluginStart()
{
    
HookEvent("player_death"Event_DeathEventHookMode_Post);
}

public 
void Event_Death(Handle event, const char[] namebool dontBroadcast
{
    
int client GetClientOfUserId(GetEventInt(event"userid"));
    
int attacker GetClientOfUserId(GetEventInt(event"attacker"));
    if (!
IsFakeClient(client) && IsFakeClient(attacker))
    {
        
PrintToChatAll("Human player %N was killed by Bot named %N"clientattacker);
    }

Translated, it says that when a player dies, and if the dead person isn't a Bot, and the killer is a bot, type a sentence containing their names in chat.

Let us know if you have any questions. Happy to help.
Attached Files
File Type: sp Get Plugin or Get Source (killedbybot.sp - 34 views - 761 Bytes)
PC Gamer is offline
Reply


Thread Tools
Display Modes

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:46.


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