AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Mana System (https://forums.alliedmods.net/showthread.php?t=194866)

vitorrossi 09-01-2012 02:59

Mana System
 
Hey guys, I'm trying to build a plugin that gives Ts a certain amount of Mana which they can use by sending the command impulse 100. I am having a problem with set_task and remove_task

This is a function that I have to be activated every new round:

Code:

    public fwHamPlayerSpawnPost( iPlayer )
    {
        if (is_user_alive(iPlayer))
        {   
            if( cs_get_user_team( iPlayer ) == CS_TEAM_T )
            {       
                iMana[ iPlayer ] = get_pcvar_num( iManaMax );
               
                set_task( get_pcvar_float( TimeIncreaseMana ),"Mana", iPlayer, "", 0, "a", RoundTime )
               
                set_task( 1.0, "sMana", iPlayer, "", 0, "a", RoundTime );
            }
        }
       
        else
        {           
            return PLUGIN_HANDLED;
        }
    }

Then with these two commands I am trying to call another function to remove these tasks if the player dies or if the round is restarted

Code:

        register_event("DeathMsg", "removetask", "a")
       
        register_event("HLTV", "removetask", "a", "1=0", "2=0")

Code:

    public removetask( id )
    {           
        remove_task( id );
    }

This is not working though, so everytime round restarts or player dies the task starts being played over the other, making it twice as fast. How can I fix this? Thank you to anyone that helps

Backstabnoob 09-01-2012 05:54

Re: Mana System
 
DeathMsg and HLTV don't have any params. Put the remove_task in Ham_Spawn and Ham_Killed.

vitorrossi 09-01-2012 15:51

Re: Mana System
 
That worked perfectly, thank you. So the reason it wasn't working before was that register_event wasn't sending the player's id to the function?

Backstabnoob 09-01-2012 17:02

Re: Mana System
 
Yes. In DeathMsg, both the victim and killer ID's are accessible through the read_data function; in HLTV, you need to loop through all players.

vitorrossi 09-01-2012 17:20

Re: Mana System
 
Thanks a lot for the help, I really appreciate it!


All times are GMT -4. The time now is 08:21.

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