AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   [TF2-specific] How would I write a plugin that runs commands on point capture? (https://forums.alliedmods.net/showthread.php?t=337081)

Nightfall_Neko 03-27-2022 15:46

[TF2-specific] How would I write a plugin that runs commands on point capture?
 
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 03-27-2022 15:47

Re: [TF2-specific] How would I write a plugin that runs commands on point capture?
 
Annnd I totally put this in the wrong subforum because I was multitasking too hard across too many screens, mb

Sreaper 03-27-2022 17:25

Re: [TF2-specific] How would I write a plugin that runs commands on point capture?
 
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.

PC Gamer 03-28-2022 05:34

Re: [TF2-specific] How would I write a plugin that runs commands on point capture?
 
1 Attachment(s)
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.

Nightfall_Neko 03-28-2022 21:14

Re: [TF2-specific] How would I write a plugin that runs commands on point capture?
 
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>)

Nightfall_Neko 03-28-2022 21:25

Re: [TF2-specific] How would I write a plugin that runs commands on point capture?
 
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.

Sreaper 03-28-2022 23:27

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

Originally Posted by Nightfall_Neko (Post 2775456)
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);

Bacardi 03-31-2022 05:42

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

Originally Posted by PC Gamer (Post 2775402)
...
It uses code previously posted by the very talented Bacardi to determine which players captured the point by name.
...

:3
I'm not that talent. :bee:


All times are GMT -4. The time now is 01:16.

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