AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   remove task with get_gametime (https://forums.alliedmods.net/showthread.php?t=216726)

MiloSx7 05-24-2013 20:03

remove task with get_gametime
 
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! :3

Emp` 05-24-2013 20:12

Re: remove task with get_gametime
 
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)

MiloSx7 05-25-2013 06:49

Re: remove task with get_gametime
 
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 :) :) :3

ConnorMcLeod 05-25-2013 07:48

Re: remove task with get_gametime
 
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);
    }



MiloSx7 05-25-2013 07:59

Re: remove task with get_gametime
 
Ok thank you i will try it and answer back when i get back home :)

MiloSx7 05-25-2013 13:33

Re: remove task with get_gametime
 
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


All times are GMT -4. The time now is 16:19.

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