Thread: For help
View Single Post
alferd
Veteran Member
Join Date: Dec 2019
Location: Iran is Always Eternal
Old 04-03-2020 , 12:13   Re: For help
Reply With Quote #3

PHP Code:
#include <amxmodx>
#include <hamsandwich>

#define PLUGIN "Autorespawn/Auto-respawn"
#define AUTHOR "HubertTM"
#define VERSION "1.0"

new TimeSpawn[33] = 0;
new 
bool:Timer[33] = false;
new 
cTimeSpawnpTimeSpawncInfoSpawnpInfoSpawncTeamSpawnpTeamSpawncSayRespawnpSayRespawncTeamAutopTeamAutocPlayerspPlayerscColorpColor

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR);
    
    
RegisterHam(Ham_Killed"player""ham_killed"1);
    
RegisterHam(Ham_Spawn"player""ham_spawn"1);
    
    
register_clcmd("say /respawn""SayRespawn");
    
register_clcmd("say_team /respawn""SayRespawn");
    
register_clcmd("say respawn""SayRespawn");
    
    
cTimeSpawn register_cvar("spawn_time""10");
    
cInfoSpawn register_cvar("spawn_infotimer""1");
    
cTeamSpawn register_cvar("spawn_team""0");
    
cSayRespawn register_cvar("spawn_say""1");
    
cTeamAuto register_cvar("spawn_auto""1");
    
cPlayers register_cvar("spawn_minplayers""2");
    
cColor register_cvar("spawn_colorhud""0");
}


public 
client_putinserver(id){
    
Timer[id] = false
    TimeSpawn
[id] = 0;
    
set_task(5.0"CheckTeam"id+291,_,_,"b");
}

public 
client_disconnect(id){
    
Timer[id] = false
    TimeSpawn
[id] = 0;
    
remove_task(id+291);
}


public 
ham_killed(id)
{
    
pTimeSpawn get_pcvar_num(cTimeSpawn);
    
pInfoSpawn get_pcvar_num(cInfoSpawn);
    
pTeamSpawn get_pcvar_num(cTeamSpawn);
    
pSayRespawn get_pcvar_num(cSayRespawn);
    
pTeamAuto get_pcvar_num(cTeamAuto);
    
pPlayers get_pcvar_num(cPlayers);
    
pColor get_pcvar_num(cColor);

    if(!
is_user_connected(id) || get_user_team(id) == || get_user_team(id) == || is_user_alive(id))
    return 
HAM_IGNORED;

    if(
pTeamSpawn && get_user_team(id) != pTeamSpawn)
    return 
HAM_IGNORED;
    
    if(
pPlayers && get_playersnum() < pPlayers)
    return 
HAM_IGNORED;
    
    
TimeSpawn[id] = pTimeSpawn;
    
    
UtworzHUD(id);
    
    
remove_task(id+492);
    
set_task(1.0"TimerSpawn"id+492);
    
Timer[id] = true;
    
    
    return 
HAM_IGNORED;
}


public 
SpawnPlayer(id)
{
    if(!
is_user_connected(id) || get_user_team(id) == || get_user_team(id) == || is_user_alive(id))
    return 
PLUGIN_CONTINUE;
    
    if(
pTeamSpawn && get_user_team(id) != pTeamSpawn)
    return 
PLUGIN_CONTINUE;
    
    if(
get_playersnum() < pPlayers)
    return 
PLUGIN_CONTINUE;
    
    
    
    
TimeSpawn[id] = pTimeSpawn;
    
    
UtworzHUD(id);
    
    
remove_task(id+492);
    
set_task(1.0"TimerSpawn"id+492);
    
Timer[id] = true;
    
    
    return 
PLUGIN_CONTINUE;
}

public 
UtworzHUD(id){

    if(
pInfoSpawn){
        switch(
pColor)
        {
        case 
0set_hudmessage(25500, -1.00.401.53.0);
        case 
1set_hudmessage(02550, -1.00.401.53.0);
        case 
2set_hudmessage(0102255, -1.00.401.53.0);
        case 
3set_hudmessage(255255255, -1.00.401.53.0);
        }
        switch(
TimeSpawn[id]){
        case 
0show_hudmessage(id"Regeneration...");
        case 
1show_hudmessage(id"You will be reborn: %d Second"TimeSpawn[id]);
        case 
.. 4show_hudmessage(id"You will be reborn: %d Second"TimeSpawn[id]);
        default: 
show_hudmessage(id"You will be reborn: %d Second"TimeSpawn[id]);
        }
    }
    
}

public 
TimerSpawn(id){
    
id-=492
    
    
if(!is_user_connected(id) || is_user_alive(id) || get_user_team(id) == || get_user_team(id) == 0){
    
Timer[id] = false;
    return 
PLUGIN_CONTINUE;
    }
    
    if(
TimeSpawn[id] > 1)
    {
        
TimeSpawn[id]--;
        
Timer[id] = true;
        
UtworzHUD(id);
        
set_task(1.0"TimerSpawn"id+492);
    }
    else
    {
        
PlayerSpawn(id);
        
Timer[id] = false;
    }
    
    return 
PLUGIN_CONTINUE;
}

public 
PlayerSpawn(id)
{
    if(!
is_user_connected(id) || is_user_alive(id) || get_user_team(id) == || get_user_team(id) == 0)
    return 
PLUGIN_CONTINUE;
    
    
ExecuteHamB(Ham_CS_RoundRespawnid);
    
Timer[id] = false;
    
    return 
PLUGIN_CONTINUE;
}

public 
ham_spawn(id){
    if(
task_exists(id+492))
    
remove_task(id+492);
    
    
Timer[id] = false;
    
TimeSpawn[id] = pTimeSpawn
}

public 
SayRespawn(id)
{
    
    if(!
pSayRespawn || !is_user_connected(id) || is_user_alive(id) || get_user_team(id) == || get_user_team(id) == || Timer[id])
    {
        if(
pSayRespawn && is_user_alive(id))
        
client_print(idprint_chat"[Respawn] Jestes zywy!");
        else
        if(
pSayRespawn && (get_user_team(id) == || get_user_team(id) == 3))
        
client_print(idprint_chat"[Respawn] Jestes spectatorem!");
        else
        if(
pSayRespawn && Timer[id] && is_user_connected(id) && !is_user_alive(id) && (get_user_team(id) == || get_user_team(id) == 2)){
        new 
menu menu_create("Trwa odrodzenie jednak odrodzic?""SayRespawnH");
        
menu_additem(menu"Tak, odrodz mnie");
        
menu_additem(menu"Nie chce.");
        
menu_display(idmenu);
        }
        
        return 
PLUGIN_CONTINUE;
    }

    
SpawnPlayer(id);
    
    return 
PLUGIN_CONTINUE;
}
public 
SayRespawnH(idmenu item){
    if(
item != 0){
    
menu_destroy(menu);
    return 
PLUGIN_HANDLED;
    }
    
    
SpawnPlayer(id);
    
Timer[id] = false;
    
    return 
PLUGIN_CONTINUE;
}



public 
CheckTeam(id){
    
id-=291
    
    
if(!is_user_connected(id))
    return 
PLUGIN_CONTINUE;
    
    if(
is_user_alive(id)){
    
Timer[id] = false;
    return 
PLUGIN_CONTINUE;
    }
    
    if(!
pTeamAuto)
    return 
PLUGIN_CONTINUE;
    
    if(
Timer[id])
    return 
PLUGIN_CONTINUE;
    
    if(
get_user_team(id) == || get_user_team(id) == 2)
    
SpawnPlayer(id);
    
    return 
PLUGIN_CONTINUE;

alferd is offline