Page 1 of 1

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

Posted: Tue Aug 09, 2016 10:03 pm
by Omniwolf
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)

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

Posted: Tue Aug 09, 2016 10:48 pm
by quartata
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

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

Posted: Tue Aug 09, 2016 10:52 pm
by quartata
Woops, noticed that you wanted it to start when setup ends not when the round begins. Should do that now.

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

Posted: Tue Aug 09, 2016 11:00 pm
by Omniwolf
Is cool man, thanks for the help!

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

Posted: Wed Aug 10, 2016 10:42 am
by Omniwolf
Loaded on server, errors.



Anyone can fix it?

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

Posted: Wed Aug 10, 2016 10:52 am
by Mahi
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?

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

Posted: Wed Aug 10, 2016 10:53 am
by Omniwolf
Ah, thats where I put myinfo and import sourcemod, should i lower those down?

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

Posted: Wed Aug 10, 2016 10:54 am
by Mahi
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..

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

Posted: Wed Aug 10, 2016 11:03 am
by Omniwolf
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.


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

Posted: Wed Aug 10, 2016 11:17 am
by L'In20Cible
Missing closing bracket.

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

Posted: Wed Aug 10, 2016 11:18 am
by satoon101
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.

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

Posted: Wed Aug 10, 2016 11:24 am
by Omniwolf
wow, really just a bracket? welp, thanks guys

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

Posted: Wed Aug 10, 2016 11:25 am
by satoon101
Also, for adding info for the plugin, see:
http://wiki.sourcepython.com/developing ... PluginInfo