This was working fine before the Smissmas update, not sure what all changed to make it not work. Basically, when a player is jailed and respawns/changes class, they get respawned in the jail position. Right now, they respawn in their normal spawn for some reason which should not be the case.
The positions used are part of the map I run on my server, "trade_masscc_c4_1", it puts players into a jail cell that is part of the map. There's two cells on the map so I separated RED and BLU into their own cells.
This is a private plugin that I didn't intend on releasing because of the hardcoded teleport position, but now that it's out there, you guys may as well use it and modify the positions. I used a co-ordinate finding position to get the co-ords.
PHP Code:
#include <sourcemod>
#include <sdktools>
#include <tf2>
#include <morecolors>
#pragma semicolon 1
public Plugin:myinfo =
{
name = "[TF2] Jail Player",
author = "404: User Not Found",
description = "Jails a player",
version = "0.2",
url = "www.unfgaming.net"
};
new bool:g_bIsJailed[MAXPLAYERS + 1] = false;
new Float:g_pos[3];
public OnPluginStart()
{
HookEvent("player_spawn", Event_PlayerChanged);
HookEvent("player_changeclass", Event_PlayerChanged);
RegAdminCmd("sm_jail", Command_Jail, ADMFLAG_GENERIC, "Usage: sm_jail <player>");
RegAdminCmd("sm_unjail", Command_UnJail, ADMFLAG_GENERIC, "Usage: sm_unjail <player>");
}
public OnClientDisconnect(client)
{
for(new i=1; i <= MaxClients; i++)
{
g_bIsJailed[i] = false;
}
}
public OnClientPutInServer(client)
{
for(new i=1; i <= MaxClients; i++)
{
g_bIsJailed[i] = false;
}
}
public Action:Command_Jail(client, args)
{
decl String:target[32];
decl String:target_name[MAX_NAME_LENGTH];
decl target_list[MAXPLAYERS];
decl target_count;
decl bool:tn_is_ml;
//validate args
if (args < 1)
{
CReplyToCommand(client, "{community}[ADMIN]{default} Usage: sm_jail <#userid|name>.");
return Plugin_Handled;
}
//get argument
GetCmdArg(1, target, sizeof(target));
//get target(s)
if ((target_count = ProcessTargetString(
target,
client,
target_list,
MAXPLAYERS,
COMMAND_FILTER_ALIVE,
target_name,
sizeof(target_name),
tn_is_ml)) <= 0)
{
ReplyToTargetError(client, target_count);
return Plugin_Handled;
}
for (new i = 0; i < target_count; i++)
{
// PerformBring(client, target_list[i], g_pos);
g_bIsJailed[target_list[i]] = true;
if(IsPlayerAlive(target_list[i]))
{
JailPlayer(target_list[i], g_pos);
CReplyToCommand(target_list[i], "{green}[SM]{default} You have been jailed!");
}
}
CReplyToCommand(client, "{community}[ADMIN]{default} Jailed %s.", target_name);
return Plugin_Handled;
}
public Action:Command_UnJail(client, args)
{
decl String:target[32];
decl String:target_name[MAX_NAME_LENGTH];
decl target_list[MAXPLAYERS];
decl target_count;
decl bool:tn_is_ml;
//validate args
if (args < 1)
{
CReplyToCommand(client, "{community}[ADMIN]{default} Usage: sm_jail <#userid|name>.");
return Plugin_Handled;
}
//get argument
GetCmdArg(1, target, sizeof(target));
//get target(s)
if ((target_count = ProcessTargetString(
target,
client,
target_list,
MAXPLAYERS,
COMMAND_FILTER_ALIVE,
target_name,
sizeof(target_name),
tn_is_ml)) <= 0)
{
ReplyToTargetError(client, target_count);
return Plugin_Handled;
}
for (new i = 0; i < target_count; i++)
{
// PerformBring(client, target_list[i], g_pos);
g_bIsJailed[target_list[i]] = false;
if(IsPlayerAlive(target_list[i]))
{
TF2_RespawnPlayer(target_list[i]);
CReplyToCommand(target_list[i], "{green}[SM]{default} You have been un-jailed!");
}
}
CReplyToCommand(client, "{community}[ADMIN]{default} Un-jailed %s.", target_name);
return Plugin_Handled;
}
public Action:Event_PlayerChanged(Handle:event, const String:name[], bool:dontbroadcast)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
if(g_bIsJailed[client] == true)
{
JailPlayer(client, g_pos);
}
return Plugin_Continue;
}
JailPlayer(target, Float:pos[3])
{
if (GetClientTeam(target) == _:TFTeam_Red)
{
pos[0] = -67.792053;
pos[1] = -6020.118652;
pos[2] = -797.968750;
}
if (GetClientTeam(target) == _:TFTeam_Blue)
{
pos[0] = -40.162773;
pos[1] = -5780.982910;
pos[2] = -797.968750;
}
TeleportEntity(target, pos, NULL_VECTOR, NULL_VECTOR);
}