Raised This Month: $ Target: $400
 0% 

countdown timer in hud not appearing


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
sylar02
Member
Join Date: Jun 2011
Old 05-07-2012 , 14:46   countdown timer in hud not appearing
Reply With Quote #1

alright, here is what i am trying to accomplish. i use yap plugin for my pug. link.

under plugins, yap_ready is responsible for handling clients to ready up or not. it also kicks you in 60 seconds if you dont ready up in 60 seconds. kicking part works. after that i tried to add a hud message which would update every second showing a countdown from 60, 59, 58,57, etc till 0 when client will get kicked for not readying up. i would really appreciate if somebody can look at my code and tell me why hud message doesnt pop up and some hint to fix it

PHP Code:
// Rukia: YAP Ready code

//    Ready mode is very intuitive.
//    In reality, we just wait for everyone to ready up, and restore state
//    So, in simplest form, "ready" is a vote that can last an infinitely long time. Very simple.

#include <amxmodx>
#include <amxmisc>

#include <yap_const>
#include <yap_stocks>
#include <yap_natives>
#include <yap_forwards>
#include <yap_modspecific>

new const plugin_author[] = "Twilight Suzuka"
new const plugin_name[] = "YAP-RDY"
new const plugin_version[] = "0.0.1"
new g_msgsync


CREATE_GEN_FORW_ID
(pug_forward_ready);


public 
plugin_init()
{
    
// Rukia: Plugin definition
    
new p_id register_plugin(plugin_name,plugin_version,plugin_author);

    
register_dictionary("yap.txt")
    
register_dictionary("yap_ready.txt")

    
register_pug_clcmd("ready","ready_up",_,"Tells the server player is ready")
    
register_pug_clcmd("notready","ready_down",_,"Tells the server player is not ready")

    
register_pug_admincmd("forceready","cmd_forceready",PUG_CMD_LVL,"<name or #userid> Forces a client to be ready")
    
register_pug_admincmd("forceunready","cmd_forceunready",PUG_CMD_LVL,"<name or #userid> Forces a client to be unready")

    
pug_forward_ready create_gen_forward("pug_all_ready",p_id,get_func_id("pug_ready_handler") )

    
//parse_header("BOE-E",pug_header,5)
    
register_event("ResetHUD","pug_keepup_menu","b")

    
pug_change_display(get_func_id("pug_ready_display_really") , -1)
    
g_msgsync CreateHudSyncObj();
    
}

// Rukia: Ready variables
new pug_players_ready[33]
new 
pug_total_ready 0;


#define TASK_READY 2345
#define READY_TIME 1337
#define HUD_TIME 60
new g_time 59;
// Rukia: make sure we keep up menu as much as possible, so that it updates correctly
public client_connect(idset_task(2.0,"pug_keepup_menu")
public 
client_putinserver(id
{
    
pug_keepup_menu()
    
    if((
GET_PUG_STATUS() != PUG_STATUS_LIVE) && (is_user_hltv(id) == 0))
    {
        new array[
2]
        array[
0]=g_time
        
array[1]=id
        set_task
(60.0"Check_Ready"id+TASK_READY)
        
set_task(1.0"Hud_Ready"id+READY_TIME, array, sizeof(array), "a"1);
    }
}

public 
Check_Ready(id)
{
    if(
GET_PUG_STATUS() == PUG_STATUS_LIVE) return
    
    
id-=TASK_READY
    
    
if(!pug_players_ready[id]){
        if(
task_exists(id+READY_TIME))
        {
            
remove_task(id+READY_TIME)
        }
        
server_cmd("kick #%d not type .ready in 60 seconds"get_user_userid(id))
        }
}

public 
Hud_Ready(array[])
{
    new 
timeid
    
new array2[2]
    array[
0]= time
    
array[1]=id
    
if(GET_PUG_STATUS() == PUG_STATUS_LIVE)
    { 
        return
    }
    
    
id-=READY_TIME
    
if(time>0)
    {
        if(
time 30set_hudmessage(01500, -1.00.8001.01.00.010.01, -1);
        else if(
time 10set_hudmessage(1501500, -1.00.8001.01.00.010.01, -1);
        else 
set_hudmessage(15000, -1.00.8001.01.00.010.01, -1);

        
ShowSyncHudMsg(idg_msgsync"You have %d seconds left to ready before getting kicked"g_time);
        
array2[0]=time-1
        array2
[1]=id
        set_task
(1.0"Hud_Ready"id+READY_TIMEarray2sizeof(array2), "a"1)
    }
}

// Rukia: If someone disconnects, we need to take them out of the line up, and make sure that everything is cool
public client_disconnect(id)
{
    if( 
GET_PUG_STAGE() != PUG_STAGE_READY ) return;

    if(
pug_players_ready[id]) 
    {
        
pug_players_ready[id] = 0;
        
pug_total_ready--;
        
        if(
task_exists(id+TASK_READY))
        {
            
remove_task(id+TASK_READY)
        }
        if(
task_exists(id+READY_TIME))
        {
            
remove_task(id+READY_TIME)
        }
    }
    
    
pug_keepup_menu()
}

// Rukia: Make sure to change HUD when people change names
public client_infochanged(idset_task(0.1,"pug_keepup_menu")

// Rukia: Dynamic native code
public plugin_natives()
{
    
register_native("pug_ready_players","native_pug_ready_players")
    
register_native("register_ready_display","native_register_ready_display")
}

public 
native_pug_ready_players(id,params)
{
    new 
p_id get_param(2)
    
pug_ready_players(get_param(1),(p_id == -1) ? id p_id)
}

public 
native_register_ready_display(id,params)
{
    new 
p_id get_param(2)
    
pug_change_display(get_param(1),(p_id == -1) ? id p_id)
}

public 
cmd_forceready(id,level,cid)
{
    if (!
cmd_access(idlevelcid2) ) return PLUGIN_HANDLED;

    static 
victim_arg[32]
    
read_argv(1,victim_arg,31)

    if(
equali(victim_arg,"all")) return cmd_force_all_ready(id);

    new 
target cmd_target(id,victim_arg,1)
    if (!
target) return PLUGIN_HANDLED

    pug_admin_cmd_c
(id,"PugForceReady","PUG_FORCE_READY",target,ready_up(target));
    return 
PLUGIN_HANDLED;
}

public 
cmd_forceunready(id,level,cid)
{
    if (!
cmd_access(idlevelcid2) ) return PLUGIN_HANDLED;

    static 
victim_arg[32]
    
read_argv(1,victim_arg,31)

    if(
equali(victim_arg,"all")) return cmd_force_all_unready(id);

    new 
target cmd_target(id,victim_arg,1)
    if (!
target) return PLUGIN_HANDLED

    pug_admin_cmd_c
(id,"PugForceUnReady","PUG_FORCE_UNREADY",target,ready_down(target));
    return 
PLUGIN_HANDLED;
}

public 
cmd_force_all_ready(id)
{
    static 
Players[32]
    new 
playerCounti
    get_players
(PlayersplayerCount"h")

    for (
i=0i<playerCounti++) ready_up(Players[i])

    
pug_admin_cmd(id,"PugForceAllReady","PUG_FORCE_ALL_READY",1);
    return 
PLUGIN_HANDLED
}

public 
cmd_force_all_unready(id)
{
    static 
Players[32]
    new 
playerCounti
    get_players
(PlayersplayerCount"h")

    for (
i=0i<playerCounti++) ready_down(Players[i])

    
pug_admin_cmd(id,"PugForceAllUnReady","PUG_FORCE_ALL_UNREADY",1);
    return 
PLUGIN_HANDLED
}


// Rukia: Ready code

public pug_ready_funcid;
public 
pug_ready_plugin_id;
public 
pug_ready_prev_stage;

// Rukia: save the handler function
pug_ready_players(f_idp_id = -1)
{
    if(
GET_PUG_STAGE() == PUG_STAGE_READY) return;
    
pug_ready_funcid f_id;
    
pug_ready_plugin_id p_id;

    
pug_start_ready_players()
}

// Rukia: Save state, sub in our own, and start the ready!
public pug_start_ready_players()
{
    if(
GET_PUG_STATUS() != PUG_STATUS_LIVE) return pug_set_pause_call(get_func_id("pug_start_ready_players"));

    
pug_ready_prev_stage GET_PUG_STAGE();
    
SET_PUG_STAGE(PUG_STAGE_READY);
    
SET_PUG_STATUS(PUG_STATUS_WAITING);

    
arrayset(pug_players_ready,0,33)
    
pug_total_ready 0;

    
pug_msg_tmp_empty(0,"PUG_READY_UP")
    
pug_keepup_menu()

    return 
1;
}

public 
ready_up(id)
{
    if((
pug_players_ready[id] == 1
        || 
GET_PUG_STATUS() != PUG_STATUS_WAITING || GET_PUG_STAGE() != PUG_STAGE_READY 
        
|| is_user_hltv(id
    )     
    {
        return 
pug_msg_tmp_empty(id,"PUG_CMD_NOTALLOWED")
    }

    if(
task_exists(id+TASK_READY))
    {
        
remove_task(id+TASK_READY)
    }
    if(
task_exists(id+READY_TIME))
    {
            
remove_task(id+READY_TIME)
    }
    
    
pug_players_ready[id] = 1;
    
pug_total_ready++;

    static 
name[32]
    
get_user_name(id,name,31)
    
client_print(0,print_chat,"%s %L",pug_headerLANG_PLAYER"PUG_PLAYER_READYED",name);

    
pug_check_ready();

    return 
PLUGIN_HANDLED;
}

public 
ready_down(id)
{
    if((
pug_players_ready[id] == 0
        || 
GET_PUG_STATUS() != PUG_STATUS_WAITING || GET_PUG_STAGE() != PUG_STAGE_READY 
        
|| is_user_hltv(id)
    )
    {
        return 
pug_msg_tmp_empty(id,"PUG_CMD_NOTALLOWED")
    }
    
    if(
task_exists(id+TASK_READY))
    {
        
remove_task(id+TASK_READY)
    }
    if(
task_exists(id+READY_TIME))
    {
        
remove_task(id+READY_TIME)
    }
    
    if(
GET_PUG_STATUS() != PUG_STATUS_LIVE)
    {
        
set_task(1.0"Hud_Ready"id+READY_TIME)
        
set_task(60.0"Check_Ready"id+TASK_READY)
        
    }
    
    
pug_players_ready[id] = 0;
    
pug_total_ready--;

    
pug_ready_display(9999.0)

    static 
name[32]
    
get_user_name(id,name,31)
    
client_print(0,print_chat,"%s %L",pug_headerLANG_PLAYER"PUG_PLAYER_UNREADYED",name);

    return 
PLUGIN_HANDLED;
}

public 
pug_keepup_menu()
{
    if(
GET_PUG_STAGE() == PUG_STAGE_READY)
    {
        
pug_ready_display(99999.0)
    }
}
    

public 
pug_check_ready()
{
    if(
pug_total_ready >= GET_CVAR_MINPLAYERS() )
    {
        
pug_ready_display(1.0)
        
pug_ready()
    }
    else 
pug_ready_display(9999.0)
}


public 
pug_ready_display_funcid
public pug_ready_display_plugin_id

public pug_change_display(f_idp_id)
{
    
pug_ready_display_funcid f_id;
    
pug_ready_display_plugin_id p_id;
    
pug_keepup_menu()
}

// Rukia: NOTE TO DO: Allow for subbing in own ready display in other plugins.
public pug_ready_display(Float:hold_time)
{
    
callfunc_begin_i(pug_ready_display_funcid,pug_ready_display_plugin_id)
    
callfunc_push_float(hold_time)
    
callfunc_end()
}

public 
pug_ready_display_really(Float:hold_time)
{
    static 
readys[1056], notreadys[1056], name[32]

    
readys[0] = '^0'
    
notreadys[0] = '^0'

    
static Players[32]
    new 
playerCountiplayer
    get_players
(PlayersplayerCount"ch")
    for (
i=0i<playerCounti++)
    {
        
player Players[i]
        
get_user_name(player,name,31)

        if(
pug_players_ready[player]) format(readys,1054,"%s%s^n",readys,name)
        else 
format(notreadys,1054,"%s%s^n",notreadys,name)
    }

    new 
minplayers GET_CVAR_MINPLAYERS()

    
set_hudmessage(255000.80.0700.0hold_time0.00.03)
    
show_hudmessage(0,"Not Ready (%d of %d) :",pug_get_players() - pug_total_ready,minplayers )

    
set_hudmessage(025500.80.5000.0hold_time0.00.02)
    
show_hudmessage(0,"Ready (%d of %d) :",pug_total_ready,minplayers)

    
set_hudmessage(2552552250.800.5300.0hold_time0.00.01)
    
show_hudmessage(0,readys,1055)

    
set_hudmessage(2552552250.800.1000.0hold_time0.00.04)
    
show_hudmessage(0,notreadys,1055)
}

// Rukia: We are ready to go! Tell everyone!
public pug_ready()
{
    if(
GET_PUG_STAGE() != PUG_STAGE_READY) return 0;
    else if(
GET_PUG_STATUS() != PUG_STATUS_WAITING) return pug_set_pause_call(get_func_id("pug_ready"));

    
execute_gen_forward(pug_forward_ready)
    return 
1;
}

// Rukia: Restore state, tell everyone we are ready, and call the handler function!
public pug_ready_handler()
{
    if(
GET_PUG_STATUS() != PUG_STATUS_WAITING) return pug_set_pause_call(get_func_id("pug_ready_handler"));

    
SET_PUG_STATUS(PUG_STATUS_LIVE);
    
SET_PUG_STAGE(pug_ready_prev_stage);

    
pug_msg_tmp_empty(0,"PUG_IS_READY")

    
callfunc_begin_i(pug_ready_funcid,pug_ready_plugin_id)
    
callfunc_end()

    return 
1;

line 70 is where i call set_task that calls my function hud_ready (line 89) and there are other places where i remove that task if client disconnects or readyies up.

thanks in advance

Last edited by sylar02; 05-07-2012 at 14:49.
sylar02 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 00:29.


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