Raised This Month: $12 Target: $400
 3% 

Solved [Help] Simple Countdown error


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Hey
Member
Join Date: Dec 2017
Old 01-02-2018 , 08:47   [Help] Simple Countdown error
Reply With Quote #1

Hi Happy new year everyone,

I need some help with this code which is a simple countdown from 10 to 0 the problem is when i set the countdown variable to 10 at round start it doesn't get set to 10 i suppose because the countdown throws some negative numbers like if the variable number was set to 0 or -1, but when i call the countdown by a clcmd it counts without errors the code is down below, i don't have any idea why so i came here for help here is the code:

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

new g_count;

new const 
countdown_sounds[][] = 
{
    
"BR/one.wav",
    
"BR/two.wav",
    
"BR/three.wav",
    
"BR/four.wav",
    
"BR/five.wav",
    
"BR/six.wav",
    
"BR/seven.wav",
    
"BR/eight.wav",
    
"BR/nine.wav",
    
"BR/ten.wav"
}
public 
plugin_init()
{
    
register_logevent("logevent_start_rnd"2"1=Round_Start");
    
register_clcmd("say /call""count");
}
public 
plugin_precache()
{
    for(new 
0sizeof(countdown_sounds); i++)
    {
        
precache_sound(countdown_sounds[i]);
    }
}
public 
count(id)
{
    
g_count 10;
    
countdown_start(id);
}
public 
logevent_rnd_start()
{
    new 
players[32], idpnum;
    
get_players(playerspnum);
    
    for(new 
0pnumi++)
    {
        
id players[i];
        if(!
is_user_alive(id))
            return 
PLUGIN_HANDLED;
        
        
g_count 10;
        
//strip_user_weapons(id);
        
set_task(5.0"countdown_start"id);
        
//set_task(1.0, "show_info", TASK_SHOW_HUD + id);
    
}
    return 
PLUGIN_HANDLED;
}
public 
countdown_start(id)
{
    
g_count -= 1;
    
client_print(0print_center"%s Battle Starts in %i"TAGg_count);
    
client_cmd(0"spk ^"%s^""countdown_sounds[g_count]);
    
    if(
g_count 0)
    {
        
set_task(1.0"countdown_start"id);
    }
    else
    {
        
set_task(2.0"Battle_start"id);
    }

BTW: there is one error that is index out of bound which happens because of the count returning a negative number and the countdown_sounds variable has no negative number so it throws the error but that does happen in the clcmd /call.

Thanks in advance.

Last edited by Hey; 01-09-2018 at 20:35. Reason: Solved
Hey is offline
 


Thread Tools
Display Modes

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 19:27.


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