Raised This Month: $32 Target: $400
 8% 

CountDown...


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kramesa
Veteran Member
Join Date: Feb 2011
Location: Brazil
Old 05-04-2012 , 17:41   CountDown...
Reply With Quote #1

Hi all, I make this CountDown:

Code:
#include <amxmodx> #include <amxmisc> new Time = 15; new DefaultValue; public plugin_init()     register_clcmd("say /count", "CountDown"); public CountDown() {     if(Time == 0) {         Time = DefaultValue;         DefaultValue = 0;         return;     }         Time--;     DefaultValue++;     client_print(0, print_chat, "CountDown: %d", Time);     set_task(1.0, "CountDown"); }

It works perfectly, but, have other way to make this? More optimized?
__________________

Last edited by kramesa; 05-04-2012 at 17:48.
kramesa is offline
Backstabnoob
Veteran Member
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 05-04-2012 , 18:27   Re: CountDown...
Reply With Quote #2

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

new Time 15;
new 
DefaultValue;

public 
plugin_init()
    
register_clcmd("say /count""CountDown");

public 
CountDown() 
{
    
    
Time 15
    set_task
1.0"_t_Countdown"999__"a"15 )
}

public 
_t_Countdowntaskid )
{
    
DefaultValue++
    
Time--
    
    if( 
Time == 
    {
        
Time DefaultValue
        DefaultValue 
0
        
        
return
    }
    
    
client_print(0print_chat"CountDown: %d"Time)

A little more optimized.
No clue what DefaultValue does do though.
__________________
Currently busy working on a very large scale anime database project.

Last edited by Backstabnoob; 05-04-2012 at 18:29.
Backstabnoob is offline
Bilal Pro
Senior Member
Join Date: Mar 2012
Location: Holland
Old 05-04-2012 , 19:21   Re: CountDown...
Reply With Quote #3

I hope this helps you.

PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>

#define PLUGIN "Count down timer"
#define VERSION "1.0"
#define AUTHOR "Bilal"

#define TASKID 1996

new Timer

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say /cd""CmdMenu")
}

public 
CmdMenu(id)
{
    new 
menu menu_create("\rCountdown Menu!""MainMenuHandler"0)
    
    
menu_additem(menu"Timer \d#5""1")
    
menu_additem(menu"Timer \d#10""2")
    
menu_additem(menu"Timer \d#15""3")
    
menu_additem(menu"Timer \d#60""4")
    
    
menu_setprop(menuMPROP_EXITMEXIT_ALL)
    
menu_display(idmenu0)
}

public 
MainMenuHandler(idmenuitem)
{
    if (
item == MENU_EXIT)
    {
        
menu_destroy(menu)
        return 
PLUGIN_HANDLED
    
}
    
    new 
data[6], name[64], accescallback
    menu_item_getinfo
(menuitemaccesdatacharsmax(data), namecharsmax(name), callback)
    new 
key str_to_num(data)
    
    switch (
key)
    {
        case 
1Timer 5
            
case 2Timer 10
            
case 3Timer 15
            
case 4Timer 60
        
}
    
Countdown(id)
    return 
PLUGIN_HANDLED
}

public 
Countdown(id)
{
    if(
task_exists(TASKID))
        
remove_task(TASKID)

    
set_task(1.0"Countdown2"TASKID__"a"Timer)
}

public 
Countdown2(id
{
    if (
Timer == 1
    {
        
set_hudmessage(02550, -1.00.4001.01.00.11.02)
        
show_hudmessage(0"Time is up!"
    }
    else 
    {
        
set_hudmessage(02550, -1.00.3001.01.00.11.01)
        
show_hudmessage(0"Timer: %i"Timer--)
    }
    return 
PLUGIN_CONTINUE

__________________
  • Point System with rank titles for sale [X] [100% private]
  • VIP Menu for sale [X] [100% private]
  • HnS shop more features for sale [X] [100% private]
Contact: Bilalzaandam1234, on steam if you are interested.
Bilal Pro is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 05-04-2012 , 19:46   Re: CountDown...
Reply With Quote #4

Usage example for a 15 seconds countdown :

MakeCountDown(15.0)

PHP Code:
#include <engine>
#include <fakemeta>

new g_entCountDownFloat:g_flFreqFloat:g_flTimeleft

MakeCountDown
Float;flTimeleft Float:flFrequency 1.0 )
{
    if( !
g_entCountDown )
    {
        
g_entCountDown create_entity("info_target")
        new const 
szClass[] = "countdown"
        
register_think(szClass"CountDown")
        
set_pev(g_entCountDownpev_classnameszClass)
    }
    
g_flTimeLeft flTimeleft
    g_flFreq 
flFrequency
    set_pev
(g_entCountDownpev_nextthinkget_gametime())
    
call_think(g_entCountDown)
}

public 
CountDowniEntity )
{
    if( 
iEntity != g_entCountDown )
    {
        return
    }

    
// Do stuff here

    // client_print(0, print_center, "Time Left Before Awesome Thing is %.0f sec", g_flTimeleft)
    

    // end of stuff, update timers
    
set_pev(g_entCountDownpev_nextthinkget_gametime() - g_flFreq)
    
g_flTimeleft -= g_flFreq

__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 05-04-2012 at 19:50.
ConnorMcLeod is offline
kramesa
Veteran Member
Join Date: Feb 2011
Location: Brazil
Old 05-04-2012 , 21:57   Re: CountDown...
Reply With Quote #5

Quote:
Originally Posted by ConnorMcLeod View Post
Usage example for a 15 seconds countdown :

MakeCountDown(15.0)

PHP Code:
#include <engine>
#include <fakemeta>

new g_entCountDownFloat:g_flFreqFloat:g_flTimeleft

MakeCountDown
Float;flTimeleft Float:flFrequency 1.0 )
{
    if( !
g_entCountDown )
    {
        
g_entCountDown create_entity("info_target")
        new const 
szClass[] = "countdown"
        
register_think(szClass"CountDown")
        
set_pev(g_entCountDownpev_classnameszClass)
    }
    
g_flTimeLeft flTimeleft
    g_flFreq 
flFrequency
    set_pev
(g_entCountDownpev_nextthinkget_gametime())
    
call_think(g_entCountDown)
}

public 
CountDowniEntity )
{
    if( 
iEntity != g_entCountDown )
    {
        return
    }

    
// Do stuff here

    // client_print(0, print_center, "Time Left Before Awesome Thing is %.0f sec", g_flTimeleft)
    

    // end of stuff, update timers
    
set_pev(g_entCountDownpev_nextthinkget_gametime() - g_flFreq)
    
g_flTimeleft -= g_flFreq

Ok, thank you.
__________________

Last edited by kramesa; 05-04-2012 at 21:58.
kramesa is offline
Backstabnoob
Veteran Member
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 05-05-2012 , 04:47   Re: CountDown...
Reply With Quote #6

Shouldn't you remove the entity when the task is done or create one and use it all the time?
__________________
Currently busy working on a very large scale anime database project.
Backstabnoob is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 05-05-2012 , 09:50   Re: CountDown...
Reply With Quote #7

That is what is done :

Use the same entity all the time, it just creates it at the first time it is needed.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Backstabnoob
Veteran Member
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 05-05-2012 , 10:56   Re: CountDown...
Reply With Quote #8

Oh I see, missed the check for g_entCountDown. My bad :X
__________________
Currently busy working on a very large scale anime database project.
Backstabnoob is offline
Reply



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 09:33.


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