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

Hook an event to trigger a command


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Teamkiller324
Senior Member
Join Date: Feb 2014
Location: Earth
Old 07-06-2020 , 19:28   Hook an event to trigger a command
Reply With Quote #1

Is there a way to hook an event to trigger a command on a player?

And is there a way to get the client of the user who triggered the hook? such as a player touching a control point, they trigger hook controlpoint_starttouch and it should fire a command to slay the user who touched it
__________________

Last edited by Teamkiller324; 07-06-2020 at 19:39.
Teamkiller324 is offline
CowGod
Senior Member
Join Date: Feb 2015
Old 07-06-2020 , 20:08   Re: Hook an event to trigger a command
Reply With Quote #2

Yes, and you can use GetClientOfUserId
CowGod is offline
Send a message via Skype™ to CowGod
Teamkiller324
Senior Member
Join Date: Feb 2014
Location: Earth
Old 07-07-2020 , 13:14   Re: Hook an event to trigger a command
Reply With Quote #3

Found a way to force client to execute a command, thanks for the information!
__________________
Teamkiller324 is offline
Teamkiller324
Senior Member
Join Date: Feb 2014
Location: Earth
Old 07-07-2020 , 13:16   Re: Hook an event to trigger a command
Reply With Quote #4

If anyone wanna know i found the way, the code example i use for testing is:

Code:
#pragma semicolon 1

#include <sourcemod>

public OnPluginStart()
{
	HookEvent("player_hurt", test);
}

public Action:test(Handle:event, const String:name[], bool dontBroadcast)
{
	new client = GetClientOfUserId(GetEventInt(event, "userid"));
	CreateTimer(0.0, lmao, client);
}

public Action:lmao(Handle:timer, any:client)
{
	if (client == 0)
	{
		return Plugin_Continue;
	}
	if (IsPlayerAlive(client))
	{
		FakeClientCommandEx(client, "kill");
	}
	return Plugin_Handled;
}
keep in mind this may spew out some invalid client index errors at some points
__________________
Teamkiller324 is offline
Reply



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 17:00.


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