Raised This Month: $ Target: $400
 0% 

remove task with get_gametime


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
MiloSx7
Member
Join Date: Oct 2011
Location: Serbia, Nish
Old 05-24-2013 , 20:03   remove task with get_gametime
Reply With Quote #1

Ok, i really don't want to make another task that will remove another task and so on.

So here is the code
PHP Code:
public MinorPot(id)
{
    
id -= 15031
    
    set_user_health
(idget_user_health(id) + 1)
    
    
set_task(0.2"MinorPot"id 15031)
    
    if(
get_gametime() >= 20)
    {
        
remove_task(id 15031)
        
client_print(idprint_chat"[Mod] Healing done. Just a test msg to know :)")
    }

Its actually a health pot I've been making for some shop menu, but since this check i did kinda checks if the 20 seconds passed since the server / map started, it doesn't really work...

This pot should actually heal for the first 20 seconds after buying (100hp if you done the math), and then stop healing, and message should pop out, which i only put for testing...

So how do i use get_gametime() correctly, and any advices about get_gametime() ??

I really appreciate your help, Thank You!
__________________
MiloS
MiloSx7 is offline
Send a message via MSN to MiloSx7
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 05-24-2013 , 20:12   Re: remove task with get_gametime
Reply With Quote #2

You need to save the game time when the potion is bought for each player, then compare that with the current game time. Also, instead of removing the task, you should have a check if it has not been 20 seconds, and set the task there. (if -> set_task) instead of (set_task, if -> remove_task)
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
MiloSx7
Member
Join Date: Oct 2011
Location: Serbia, Nish
Old 05-25-2013 , 06:49   Re: remove task with get_gametime
Reply With Quote #3

I'm struggling and i can't seem to make it. I've been trying something like this:

PHP Code:
new Float:gametime[33]

gametime[id] = get_gametime() //When a player buys a potion 
and then I've checked like millions of combinations, but nothing seems to work...
PHP Code:
if(get_gametime() > gametime 20.0)
if(
get_gametime() < gametime 20.0)
if(
gametime get_gametime() + 20.0)
//And so on... 
Either the potion never stops working, or it just stops the same second as i buy it...

And when i to do the check as you told me
PHP Code:
public MinorPot(id)
{
    
id -= 15031
    
    
if(gametime[id] - 20.0 get_gametime())
    {
        
set_user_health(idget_user_health(id) + 1)
        
set_task(0.2"MinorPot"id 15031)
    }

This also never stops working. But I've done the math well. If gametime[id] was 2:40 and - 20.0 will make it 2:20, so basically its going to check and should stop for 20 seconds, when gametime[id] and get_gametime is 2:20, and stops working completely after get_gametime goes under 2:20. But the problem is its going to work forever, even after the round ends, until the map is changed...

I'm going to keep trying various combinations until someone answers back with a solution, or when i actually make it by myself

Thanks guys
__________________
MiloS

Last edited by MiloSx7; 05-25-2013 at 07:24.
MiloSx7 is offline
Send a message via MSN to MiloSx7
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 05-25-2013 , 07:48   Re: remove task with get_gametime
Reply With Quote #4

Just use flag "a" (repeat) and set repeat time to 100 (or 99, i always forget which one) :

PHP Code:
const TASK_PLAYER_HEAL 15031;

HealPlayerid )
{
    
set_task(0.2"MinorPot"id TASK_PLAYER_HEAL__"a"100);
}

public 
MinorPotid )
{
    
id -= TASK_PLAYER_HEAL;
    if( 
is_user_alive(id) )
    {
        
set_user_health(idget_user_health(id) + 1);
    }

__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
MiloSx7
Member
Join Date: Oct 2011
Location: Serbia, Nish
Old 05-25-2013 , 07:59   Re: remove task with get_gametime
Reply With Quote #5

Ok thank you i will try it and answer back when i get back home
__________________
MiloS
MiloSx7 is offline
Send a message via MSN to MiloSx7
MiloSx7
Member
Join Date: Oct 2011
Location: Serbia, Nish
Old 05-25-2013 , 13:33   Re: remove task with get_gametime
Reply With Quote #6

Yep it works. But i will try to check if user is alive, if not i wont even open a menu so i won't have to check every time that in tasks.

And its 100, by the way

Thank you Connor, have a nice day

If i have any more questions about this mod I'm working on (which purpose is learning) I'll post here
__________________
MiloS
MiloSx7 is offline
Send a message via MSN to MiloSx7
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 16:19.


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