Raised This Month: $ Target: $400
 0% 

Countdown


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
GhostMan
Senior Member
Join Date: Jun 2012
Old 07-15-2012 , 14:02   Countdown
Reply With Quote #1

PHP Code:
new time
time 
30
set_task
1.0"something"TASK_SOMETHING__"a"time )

public 
something()
{
    
time--
    
    if(
time >= 0)
    {
        
set_hudmessage(02550, -1.00.200.01.00.10.14)
        
show_hudmessage(0"Seconds left: %i"time)
    }
    
    else
    {
        
set_hudmessage(02550, -1.00.200.05.00.10.14)
        
show_hudmessage(0"TIME IS OUT!")
        
        if(
task_exists(TASK_SOMETHING))
            
remove_task(TASK_SOMETHING)
    }

After
PHP Code:
time >= 
is false is variable "time" still getting lower and lower values?

Last edited by GhostMan; 07-15-2012 at 14:03.
GhostMan is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 07-15-2012 , 14:17   Re: Countdown
Reply With Quote #2

no. remove_task will cut out that task and delete its hook from execution. From what i see....it should do what you wish it to.
__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz is offline
GhostMan
Senior Member
Join Date: Jun 2012
Old 07-15-2012 , 14:41   Re: Countdown
Reply With Quote #3

No no, this part works perfectly, i'm just curious about "time" values.

I'm willing to stop the damage when one of tasks like this is active using
PHP Code:
RegisterHam(Ham_TakeDamage"player""hook_TakeDamage"
Now it looks something like that

PHP Code:
public hook_TakeDamage(victimattackeruselessFloat:damagedamagebits) {
 
    switch(
something)
    {

        case 
1:
        {
            if(
task_exists(TASK_1))
                return 
HAM_SUPERCEDE
        
}
        
        case 
2:
        {
            if(
task_exists(TASK_2))
                return 
HAM_SUPERCEDE
        
}

        case 
3:
        {
            if(
task_exists(TASK_3))
                return 
HAM_SUPERCEDE
        
}
        
    
etc...
    
    return 
HAM_IGNORED

But i thought to get a little bit more optimised i could use code like that

PHP Code:
public hook_TakeDamage(victimattackeruselessFloat:damagedamagebits) {
 
    if(
time 0) {
        return 
HAM_SUPERCEDE
    
}
    return 
HAM_IGNORED

then i would save a lot of lines

As far as you said variable TIME stops @ 0 or -1 ( not sure ) and stays with it for good.

Last edited by GhostMan; 07-15-2012 at 14:49.
GhostMan is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 07-15-2012 , 15:53   Re: Countdown
Reply With Quote #4

The number of lines of code is -usually- irrelevant to the run time of the code. Its HOW the code is run and written. Just FYI

As for your two pieces of code i'd say the second one is better because you don't need to do more than one check (flag, and task_exists) and it checks to make sure you have time left, rather than calling the native to see if the task is alive. Either way....return HAM_SUPERCEED will not stop damage from being delt (i don't think) you should use SetHamParamFloat(3, 0.0) to deal 0 damage.
__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-15-2012 , 20:22   Re: Countdown
Reply With Quote #5

Could do something like this
PHP Code:
enum Tasks
{
    
TASK_1,
    
TASK_2,
    
TASK_3,
    
TASK_4,
    
TASK_5,
    
TASK_6
}
new const 
g_TaskIDTasks ] = 
{
    
500,
    
550,
    
600,
    
650,
    
700,
    
750
}

public 
YourFunction() 
{
    
set_task1.0 "TheFunc" g_TaskIDTASK_1 ] );
    
set_task1.0 "TheFunc" g_TaskIDTASK_2 ] );
    
set_task1.0 "TheFunc" g_TaskIDTASK_3 ] );
}

public 
hook_TakeDamage(victimattackeruselessFloat:damagedamagebits
{
    return 
task_existsg_TaskIDTasks:something ] ) ? HAM_SUPERCEDE HAM_IGNORED;

__________________
Bugsy is offline
Old 07-15-2012, 20:45
Liverwiz
This message has been deleted by Liverwiz. Reason: Make love, not war.
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-15-2012 , 20:47   Re: Countdown
Reply With Quote #6

Quote:
Originally Posted by Liverwiz View Post
You don't really need the TaskID array if you already have the enum of tasks....an enum already contains a unique int identifier. That's what makes it an enum....
But if you're feeling the need you can set the enum's increment

Code:
enum Tasks (+= 50)
{
    TASK_1 = 500, 
    TASK_2,
etc etc etc
Ok genius, then show me how to do this, with using only an enum.
PHP Code:
public hook_TakeDamage(victimattackeruselessFloat:damagedamagebits
{
    return 
task_existsg_TaskIDTasks:something ] ) ? HAM_SUPERCEDE HAM_IGNORED;

__________________
Bugsy is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 07-15-2012 , 21:04   Re: Countdown
Reply With Quote #7

Code:
public hook_TakeDamage(victim, attacker, useless, Float:damage, damagebits)  
    return (time > 0) ? HAM_SUPERCEDE : HAM_IGNORED
The task will be removed after its completion anyway, no need to see if it exists.
__________________
What an elegant solution to a problem that doesn't need solving....

Last edited by Liverwiz; 07-15-2012 at 21:05.
Liverwiz is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-15-2012 , 21:16   Re: Countdown
Reply With Quote #8

Ok, but you didn't respond to my statement above.

And I was just giving him one option, it seemed as if he had the time method already figured out.
__________________

Last edited by Bugsy; 07-15-2012 at 21:17.
Bugsy is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 07-15-2012 , 21:31   Re: Countdown
Reply With Quote #9

If i'm FORCED to use that method...there is no way. I was just saying that the task identifier would be built into the enum.
__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-15-2012 , 21:48   Re: Countdown
Reply With Quote #10

Quote:
Originally Posted by Liverwiz View Post
If i'm FORCED to use that method...there is no way.
Whether or not you're forced to use this method has nothing to do with it, I want you to backup what you say.

Quote:
You don't really need the TaskID array if you already have the enum of tasks....an enum already contains a unique int identifier. That's what makes it an enum....
But if you're feeling the need you can set the enum's increment
PHP Code:
return task_existsg_TaskIDTasks:something ] ) ? HAM_SUPERCEDE HAM_IGNORED
Quote:
Originally Posted by Liverwiz View Post
I was just saying that the task identifier would be built into the enum.
I know what an enum is and how they work. The reason why I used an array is because the method I provided him uses an index that I was passing to the TaskID array to make the code in TakeDamage a simple 1 line return, you can't do this with using only an enum; see method 2 in this post. I was basically taking that method and reducing the code.
__________________

Last edited by Bugsy; 07-15-2012 at 21:53.
Bugsy 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 15:21.


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