[TF2] Switch Team on death (For red only)

A place for requesting new Source.Python plugins to be made for your server.

Please request only one plugin per thread.
User avatar
Omniwolf
Junior Member
Posts: 10
Joined: Tue Aug 09, 2016 9:45 pm

[TF2] Switch Team on death (For red only)

Postby Omniwolf » Tue Aug 09, 2016 10:03 pm

Hi there, I'm currently looking for a plugin content creator to help me with an issue.


Intro -
My friend, who I will link his Steam below, owns a popular (ish) TF2 Zombies server, in which a team of RED Engineer 'survivors' must fend of BLU medic 'zombies'. The Engineers cannot build sentries, and the Medics are melee only. The problem we face currently though, is that after a RED engineer dies, he must swap to BLU, as the RED engineers cannot respawn, but the BLU medics can. And yes, we can just ask them to switch, but people refuse, and spy on other 'Survivor' spots, allowing them to switch and instantly know where to go.

What I'm looking for is a plugin, that can be activated post-setup, and will remain active till it is turned off (round end), that instantly switches any dead RED engineer to BLU. I assume this may be hard, and I have good experience with Python, but not Python.source. Also, commands to activate the auto-switching and deactivate it would be handy, if not necessary, as we have a script that runs on setup start that could easily house the activate command.


Lazyneer (Server Owner)
User avatar
quartata
Member
Posts: 77
Joined: Wed Jun 22, 2016 11:49 pm

Re: [TF2] Switch Team on death (For red only)

Postby quartata » Tue Aug 09, 2016 10:48 pm

Should be as simple as:

Syntax: Select all

from commands.typed import TypedServerCommand
from events import Event
from events.manager import event_manager
from players.entity import Player

@TypedServerCommand("switch_death_on")
def switch_enable(command_info):
try:
event_manager.register_for_event("player_death", player_death)
except ValueError:
print("Already on.")

@TypedServerCommand("switch_death_off")
def switch_disable(command_info):
try:
event_manager.unregister_for_event("player_death", player_death)
except ValueError:
print("Already off.")

def player_death(event):
player = Player.from_userid(event["userid"])
if player.get_team() == 2:
player.set_team(3)

@Event("teamplay_round_active")
def round_start(event):
try:
event_manager.register_for_event("player_death", player_death)
except ValueError:
pass

@Event("teamplay_round_win")
def round_end(event):
try:
event_manager.unregister_for_event("player_death", player_death)
except ValueError:
pass
Last edited by quartata on Tue Aug 09, 2016 10:52 pm, edited 1 time in total.
User avatar
quartata
Member
Posts: 77
Joined: Wed Jun 22, 2016 11:49 pm

Re: [TF2] Switch Team on death (For red only)

Postby quartata » Tue Aug 09, 2016 10:52 pm

Woops, noticed that you wanted it to start when setup ends not when the round begins. Should do that now.
User avatar
Omniwolf
Junior Member
Posts: 10
Joined: Tue Aug 09, 2016 9:45 pm

Re: [TF2] Switch Team on death (For red only)

Postby Omniwolf » Tue Aug 09, 2016 11:00 pm

Is cool man, thanks for the help!
User avatar
Omniwolf
Junior Member
Posts: 10
Joined: Tue Aug 09, 2016 9:45 pm

Re: [TF2] Switch Team on death (For red only)

Postby Omniwolf » Wed Aug 10, 2016 10:42 am

Loaded on server, errors.



Anyone can fix it?
User avatar
Mahi
Senior Member
Posts: 236
Joined: Wed Aug 29, 2012 8:39 pm
Location: Finland

Re: [TF2] Switch Team on death (For red only)

Postby Mahi » Wed Aug 10, 2016 10:52 am

It says line 9 in your stack trace:

Code: Select all

  File '../addons/source-python/plugins/REDSWITCH/REDSWITCH.py', line 9
    from commands.typed import TypedServerCommand

This is line 1 in quartata's code, what did you add before the line 9?
Last edited by Mahi on Wed Aug 10, 2016 10:53 am, edited 1 time in total.
User avatar
Omniwolf
Junior Member
Posts: 10
Joined: Tue Aug 09, 2016 9:45 pm

Re: [TF2] Switch Team on death (For red only)

Postby Omniwolf » Wed Aug 10, 2016 10:53 am

Ah, thats where I put myinfo and import sourcemod, should i lower those down?
User avatar
Mahi
Senior Member
Posts: 236
Joined: Wed Aug 29, 2012 8:39 pm
Location: Finland

Re: [TF2] Switch Team on death (For red only)

Postby Mahi » Wed Aug 10, 2016 10:54 am

I'm pretty sure there's an error in those lines, may we see them?

Also, what do you mean import sourcemod? I don't think Source.Python can import SM..
User avatar
Omniwolf
Junior Member
Posts: 10
Joined: Tue Aug 09, 2016 9:45 pm

Re: [TF2] Switch Team on death (For red only)

Postby Omniwolf » Wed Aug 10, 2016 11:03 am

This is it currently - The bottom 2 sections for activating on round start and deactivating on round end were unnecessary, so cleaned up - Also, the plugin info was placeholder, as we were going to test first before fully fleshing out credits.

User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: [TF2] Switch Team on death (For red only)

Postby L'In20Cible » Wed Aug 10, 2016 11:17 am

Missing closing bracket.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: [TF2] Switch Team on death (For red only)

Postby satoon101 » Wed Aug 10, 2016 11:18 am

I am not sure why you would be trying to import sourcemod, but you should certainly remove that. Once you fix the SyntaxError (which is because you are missing the closing } for your myinfo variable), you will get an ImportError, unless you have some sort of sourcemod plugin for Source.Python installed that isn't used in the above plugin. Just an fyi, but Source.Python has absolutely nothing to do with SourceMod.
Image
User avatar
Omniwolf
Junior Member
Posts: 10
Joined: Tue Aug 09, 2016 9:45 pm

Re: [TF2] Switch Team on death (For red only)

Postby Omniwolf » Wed Aug 10, 2016 11:24 am

wow, really just a bracket? welp, thanks guys
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: [TF2] Switch Team on death (For red only)

Postby satoon101 » Wed Aug 10, 2016 11:25 am

Also, for adding info for the plugin, see:
http://wiki.sourcepython.com/developing ... PluginInfo
Image

Return to “Plugin Requests”

Who is online

Users browsing this forum: No registered users and 8 guests