Raised This Month: $ Target: $400
 0% 

set_task to repeat


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
emaya93
Member
Join Date: Jun 2012
Old 08-29-2012 , 19:06   set_task to repeat
Reply With Quote #1

Hi,
I'm trying to make this plugin work corectly, and I dont know how to set the "set_task", to repeat every round that function. So I want, to countdown the time remaing in that cvar, in every new round begins. But I don't know how!.. This is the code

Code:
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
#include <cstrike>

#define TIMER_TASK 123456

new g_counter  

new g_SyncRestartTimer 

new Float:RoundStartTime

new g_Time_Interval;
const MAX_PLAYERS = 32;

new g_iRespawn[MAX_PLAYERS+1], g_TeamInfoCounter[MAX_PLAYERS+1], CsTeams:g_iPlayerTeam[MAX_PLAYERS+1];
new g_pCvarRespawnTime, g_pCvarRespawnDelay, g_pCvarMaxHealth;

public plugin_init()
{
    register_plugin("Dr.Respawn", "1.0", "Vicious Vixen"); 
    RegisterHam(Ham_Killed, "player", "fwdPlayerKilledPost", 1);
    RegisterHam(Ham_Spawn, "player", "fwdPlayerSpawnPost", 1);
    register_event("TeamInfo", "eTeamInfo", "a");
    register_logevent( "LogEventRoundStart", 2, "1=Round_Start" )
    g_pCvarRespawnTime = register_cvar("amx_respawn_tickets", "0"); //Set to 0 for unlimited respawns
    g_pCvarRespawnDelay = register_cvar("amx_respawn_delay", "1");
    g_pCvarMaxHealth = register_cvar("amx_max_health", "100");
    g_Time_Interval = register_cvar("amx_max_time", "30");
    set_msg_block( get_user_msgid( "ClCorpse" ), BLOCK_SET );  
    g_SyncRestartTimer = CreateHudSyncObj()
    set_task(1.0,"TimeCounter",TIMER_TASK,_,_,"a", get_pcvar_num(g_Time_Interval))
}

public LogEventRoundStart()
{
    RoundStartTime = get_gametime()
    
    new iPlayers[32]
    new iNum

    get_players( iPlayers, iNum )
    
    for( new i = 0; i < iNum; i++ )
    {
        g_iRespawn[iPlayers[i]] = true
    }
}

public TimeCounter() 
{
    g_counter++
    
    new Float:iRestartTime = get_pcvar_float(g_Time_Interval) - g_counter
    new Float:fSec
    fSec = iRestartTime 
    
    set_hudmessage( 0, 255, 255, -1.0, 0.25, 0, 0.0, 1.0, 0.0, 0.0, -1)
    ShowSyncHudMsg( 0, g_SyncRestartTimer, "Remained %d seconds to respawn", floatround(fSec))
    
    if( get_pcvar_num(g_Time_Interval) - g_counter < 11 )
    {
        static szNum[32]
        num_to_word(get_pcvar_num(g_Time_Interval) - g_counter, szNum, 31)
        client_cmd(0,"speak ^"vox/%s^"", szNum)
    }

}

public fwdPlayerKilledPost(iVictim, iKiller, iShoudlGib)
{
    if(g_iRespawn[iVictim]++ < get_pcvar_num(g_pCvarRespawnTime) || get_pcvar_num(g_pCvarRespawnTime) == 0)
    {
        set_task(get_pcvar_float(g_pCvarRespawnDelay), "taskRespawnPlayer", iVictim);
    }
    return HAM_IGNORED;
}

public fwdPlayerSpawnPost(iClient)
{
    if(is_user_alive(iClient))
    {
        set_pev(iClient, pev_health, get_pcvar_float(g_pCvarMaxHealth));
    }
}

public taskRespawnPlayer(id)
{
    if(is_user_connected(id) && RoundStartTime + get_pcvar_num(g_Time_Interval) >= get_gametime() && g_iRespawn[id] && !is_user_alive(id) && cs_get_user_team(id) != CS_TEAM_SPECTATOR) {
        ExecuteHamB(Ham_CS_RoundRespawn, id)
        g_iRespawn[id] = false
        return PLUGIN_HANDLED;
    }
    return PLUGIN_HANDLED;
}  

public eTeamInfo() 
{ 
    new iClient = read_data(1);
    new szTeam[2];
    read_data(2, szTeam, charsmax(szTeam));
    switch(szTeam[0])
    {
        case 'T': 
        {
            if(g_TeamInfoCounter[iClient] == 2 || g_iPlayerTeam[iClient] == CS_TEAM_SPECTATOR)
            {
                set_task(get_pcvar_float(g_pCvarRespawnDelay), "taskRespawnPlayer",  iClient);
            }
            g_iPlayerTeam[iClient] = CS_TEAM_T;
        }
        case 'C': 
        {
            if(g_TeamInfoCounter[iClient] == 2 || g_iPlayerTeam[iClient] == CS_TEAM_SPECTATOR)
            {
                set_task(get_pcvar_float(g_pCvarRespawnDelay), "taskRespawnPlayer",  iClient);
            }
            g_iPlayerTeam[iClient] = CS_TEAM_CT;
        }
        case 'S':
        {
            remove_task(iClient);
            g_iPlayerTeam[iClient] = CS_TEAM_SPECTATOR;
        }
    }
}  
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{ rtf1 ansi ansicpg1252 deff0 deflang1033{ fonttbl{ f0 fnil Tahoma;}}n viewkind4 uc1 pard f0 fs16 n par }
*/
emaya93 is offline
 



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 05:53.


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