Raised This Month: $344 Target: $400
 86%   Almost there!

[TF2-specific] How would I write a plugin that runs commands on point capture?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Nightfall_Neko
New Member
Join Date: Mar 2022
Location: NY, USA
Old 03-27-2022 , 15:46   [TF2-specific] How would I write a plugin that runs commands on point capture?
Reply With Quote #1

Hia, first post, just learning the language for these plugins and having some trouble digging into it unguided. I'm trying to be able to run create a script that makes the console run a command only once on capture of a point. Do I need to have it once per point (like an index of each point across cp_dustbowl) with an array or something? Or is there a cleaner way to do it?

As a point of reference, the command I wish to run is sm_addtime 600.
Nightfall_Neko is offline
Nightfall_Neko
New Member
Join Date: Mar 2022
Location: NY, USA
Old 03-27-2022 , 15:47   Re: [TF2-specific] How would I write a plugin that runs commands on point capture?
Reply With Quote #2

Annnd I totally put this in the wrong subforum because I was multitasking too hard across too many screens, mb
Nightfall_Neko is offline
Sreaper
髪を用心
Join Date: Nov 2009
Old 03-27-2022 , 17:25   Re: [TF2-specific] How would I write a plugin that runs commands on point capture?
Reply With Quote #3

For running a command on point capture you can do:

PHP Code:
public OnPluginStart()
{
    
HookEvent("teamplay_point_captured"TeamplayPointCaptured);
}

public 
TeamplayPointCaptured(Handle eventchar[] namebool dontBroadcast)
{    
    
ServerCommand("sm_addtime 600")

As far as limiting the command to only run once per point I'm not sure too sure. Please share if you end up finding the solution.

Last edited by Sreaper; 03-27-2022 at 17:27.
Sreaper is offline
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 03-28-2022 , 05:34   Re: [TF2-specific] How would I write a plugin that runs commands on point capture?
Reply With Quote #4

I use the attached plugin to reward individual TF2 players who capture the control point.

The plugin uses the teamplay_point_captured event mentioned above by Sreaper. It uses code previously posted by the very talented Bacardi to determine which players captured the point by name. I added a bit more code to give each human player who captured a small buff for a five seconds and cash reward. The plugin also posts a notice to the server console showing who captured the point.
Attached Files
File Type: sp Get Plugin or Get Source (whocaptured.sp - 33 views - 2.4 KB)
PC Gamer is offline
Nightfall_Neko
New Member
Join Date: Mar 2022
Location: NY, USA
Old 03-28-2022 , 21:14   Re: [TF2-specific] How would I write a plugin that runs commands on point capture?
Reply With Quote #5

aaaaa I can't compile what I'm made now >.>

PHP Code:
#include <sourcemod>
#include <sdktools>

#pragma semicolon 1

#define PLUGIN_VERSION "1.0"

public Plugin myinfo 
{
    
name "Cap and Command",
    
author "Nightfall",
    
description "Run commands on point capture",
    
version PLUGIN_VERSION,
    
url "notapplicable"
}
public 
OnPluginStart()
{
    
HookEvent("teamplay_point_captured"TeamplayPointCaptured);
}

public 
TeamplayPointCaptured(Handle eventchar[] namebool dontBroadcast);
{    
    
ServerCommand("sm_addtime 600")

With your help on how to hook onto the point being captured, I at least have more done than before. Compiler insists that I need a semicolon on that last line, or did I not need to include pragma?

So dang used to brackets that now that they're useless I feel like I wasted time in college on java courses ;_;


Ah, I answered my own question double checking my work. Now the compiler won't actually spit out the spx though. Complains it has no ability to write to (...sourcemod-1.10.0\compiled\<filename>)

Last edited by Nightfall_Neko; 03-28-2022 at 21:22. Reason: Answered my own question but a new one came up
Nightfall_Neko is offline
Nightfall_Neko
New Member
Join Date: Mar 2022
Location: NY, USA
Old 03-28-2022 , 21:25   Re: [TF2-specific] How would I write a plugin that runs commands on point capture?
Reply With Quote #6

Neeeeevermind, I answered my own question again. I forget that older scripts don't do you the favor of just up and making directories for you when you lack them. Also kind of figured that a shortcut to the compiler would let it run as normal, not from where the sc was made. Not entirely bad, lets me have a compiled folder on the surface.
Nightfall_Neko is offline
Sreaper
髪を用心
Join Date: Nov 2009
Old 03-28-2022 , 23:27   Re: [TF2-specific] How would I write a plugin that runs commands on point capture?
Reply With Quote #7

Quote:
Originally Posted by Nightfall_Neko View Post
Neeeeevermind, I answered my own question again. I forget that older scripts don't do you the favor of just up and making directories for you when you lack them. Also kind of figured that a shortcut to the compiler would let it run as normal, not from where the sc was made. Not entirely bad, lets me have a compiled folder on the surface.
Well for anyone else that wants to know the answer, #pragma semicolon 1, helps you maintain good programming practices but not required to include in your plugins.

The first reason it failed was because ServerCommand("sm_addtime 600"); was expecting semicolon at the end since you required them to be there.

The second one failed because you added a ; to the end of the hook callback definition which isn't allowed. public TeamplayPointCaptured(Handle event, char[] name, bool dontBroadcast);

Last edited by Sreaper; 03-28-2022 at 23:28.
Sreaper is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 03-31-2022 , 05:42   Re: [TF2-specific] How would I write a plugin that runs commands on point capture?
Reply With Quote #8

Quote:
Originally Posted by PC Gamer View Post
...
It uses code previously posted by the very talented Bacardi to determine which players captured the point by name.
...

I'm not that talent.
__________________
Do not Private Message @me
Bacardi 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 22:03.


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