If you are using ReAPI, just use this simple code:
PHP Code:
/*
* This plugin will automatically respawn player directly after manual team change
* This plugin require ReAPI (Have no idea how to convert to AMXX)
*
* Code idea from our Zombie Escape Mod
*/
#include <amxmodx>
#include <reapi>
new bool:g_bSwitched[33]
public plugin_init()
{
register_plugin("Respawn After Team Change", "1.0", "Raheem")
RegisterHookChain(RG_HandleMenu_ChooseTeam, "HC_HandleMenu_ChooseTeam_Pre", false)
RegisterHookChain(RG_HandleMenu_ChooseAppearance, "HC_HandleMenu_ChoosedAppearance_Post", true)
RegisterHookChain(RG_RoundEnd, "HC_RoundEnd_Post", true)
}
public HC_HandleMenu_ChooseTeam_Pre(id, MenuChooseTeam:iSlot)
{
if (iSlot == MenuChoose_CT || iSlot == MenuChoose_T)
{
if (is_user_alive(id))
{
g_bSwitched[id] = true
}
}
}
public HC_HandleMenu_ChoosedAppearance_Post(const id, const slot)
{
if (g_bSwitched[id])
{
rg_round_respawn(id)
g_bSwitched[id] = false
}
}
public HC_RoundEnd_Post(WinStatus:status, ScenarioEventEndRound:event, Float:tmDelay)
{
arrayset(g_bSwitched, false, charsmax(g_bSwitched))
}
In ReGameDLL you can control also the time that during the game where player still respawned:
PHP Code:
// Player cannot respawn until next round
// if more than N seconds has elapsed since the beginning round
//
// Default value: "20"
mp_roundrespawn_time 5
So using first plugin will respawn the player directly after switching team. And using mp_roundrespawn_time 5 will allow players join the game if not more than 5 seconds elapsed from the round.