Raised This Month: $ Target: $400
 0% 

Solved [TF2] Convert Source Python plugins into a Sourcemod plugin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Lazyneer
Junior Member
Join Date: Sep 2016
Old 09-30-2016 , 13:08   Re: [TF2] Convert Source Python plugins into a Sourcemod plugin
Reply With Quote #1

The team switcher plugin works fine, but the auto restart doesnt work right. It ends the round as soon someone dies, connects or disconnects, whether team RED is empty or not.
Lazyneer is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 09-30-2016 , 14:34   Re: [TF2] Convert Source Python plugins into a Sourcemod plugin
Reply With Quote #2

Quote:
Originally Posted by Lazyneer View Post
[...] the auto restart doesnt work right. It ends the round as soon someone dies, connects or disconnects, whether team RED is empty or not.
Copied the code after the edits? It earlier had an incorrect test that checks that the team size was greater than zero instead of equal to it, which would explain why the round ends prematurely. Oops.

If that's not it, it sounds like some weird SourcePython-specific quirk (I know some Python, but I have no idea how SourcePython handles things), or maybe the events aren't being handled in the correct order. The hooked player_team event in the Python code suggests the round would end if any player joins any non-RED team including spectate.

Could check if the round is running (see EmptyRed function below); no idea if that'd help any though.

Code:
#include <sourcemod>
#include <tf2_stocks>

#pragma semicolon 1
#pragma newdecls required

public Plugin myinfo = {
    name        = "Omniwolf's Auto Restart Zombies",
    author      = "Omniwolf",
    description = "Auto Restarts when RED is empty",
    version     = "1.0",
    url         = ""
};

public void OnPluginStart() {
    HookEvent("player_death", OnPlayerDeath, EventHookMode_PostNoCopy);
    HookEvent("player_team", OnPlayerTeam, EventHookMode_PostNoCopy);
}

public void OnPlayerDeath(Event event, const char[] name, bool dontBroadcast) {
    EmptyRed();
}

public void OnPlayerTeam(Event event, const char[] name, bool dontBroadcast) {
    EmptyRed();
}

void EmptyRed() {
    if (GameRules_GetRoundState() == RoundState_RoundRunning && GetTeamClientCount(view_as<int>(TFTeam_Red)) == 0) {
        CreateTimer(1.0, OnRedEmpty, _, TIMER_FLAG_NO_MAPCHANGE);
    }
}

public Action OnRedEmpty(Handle timer, any data) {
    ServerCommand("sm_settime 1; sm_hsay Round Over");
    return Plugin_Handled;
}
I'll revisit this a bit later in the day if it remains unfulfilled.
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)
nosoop is offline
Lazyneer
Junior Member
Join Date: Sep 2016
Old 09-30-2016 , 15:08   Re: [TF2] Convert Source Python plugins into a Sourcemod plugin
Reply With Quote #3

The edited version works like I wanted. Thank you.
Lazyneer 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 20:55.


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