AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Help coding Godmode for 5secs (https://forums.alliedmods.net/showthread.php?t=329790)

husam124 01-08-2021 10:57

Help coding Godmode for 5secs
 
im coding a function that works on key E , when someone press e it gives him god mode for 5 secs but i need help in how to make a timer that when the 5secs pass the god mode function goes off.

OciXCrom 01-08-2021 11:03

Re: Help coding Godmode for 5secs
 
Simply use the set_task() function.

husam124 01-08-2021 11:04

Re: Help coding Godmode for 5secs
 
well i would'nt be asking if i knew how to use it

OciXCrom 01-08-2021 13:49

Re: Help coding Godmode for 5secs
 
Well, mr. "best plugin maker", I doubt you managed to hook the E button but can't create a single task. Show your code, try using it and show the results.

fysiks 01-08-2021 22:35

Re: Help coding Godmode for 5secs
 
Quote:

Originally Posted by husam124 (Post 2731796)
well i would'nt be asking if i knew how to use it

He answered your question giving you the next step. Simply learn how to use set_task() and things should become obvious. If you have issues after implementing set_task(), post your code and we can help you resolve your further issues.

loiraolhosazul 01-08-2021 23:14

Re: Help coding Godmode for 5secs
 
HTML Code:

#include <amxmodx>
#include <fakemeta>
#include <fun>

new iGodMode[33]

public plugin_init()
{
        register_plugin("PLUGIN", "VERSION", "AUTHOR")

        register_forward(FM_CmdStart, "FwCmdStart")
}

public FwCmdStart(id, uc_handle, randseed)
{
        if(!is_user_connected(id) || !is_user_alive(id))
                return FMRES_IGNORED

        static button; button = get_uc(uc_handle , UC_Buttons)
        static oldbutton; oldbutton = pev(id, pev_oldbuttons)

        if(button & IN_USE && !(oldbutton & IN_USE) && !iGodMode[id])
        {
                iGodMode[id] = true
                set_user_godmode(id, true)

                set_task(5.0, "RemoveGodMode", id)

                client_print(id, print_chat, "GodMode ON!")
        }

        return FMRES_IGNORED
}

public RemoveGodMode(id)
{
        if(!is_user_connected(id))
        {
                if(task_exists(id))
                        remove_task(id)
               
                return PLUGIN_HANDLED
        }

        iGodMode[id] = false
        set_user_godmode(id, false)
        client_print(id, print_chat, "GodMode Off!")

        return PLUGIN_HANDLED
}

it's a quick thing guys, it doesn't hurt to help.

fysiks 01-08-2021 23:19

Re: Help coding Godmode for 5secs
 
Quote:

Originally Posted by loiraolhosazul (Post 2731871)
it's a quick thing guys, it doesn't hurt to help.

People don't learn by just getting everything given to them. This is the Scripting Help section where people come to learn how to write their own plugins, not ask for fully complete plugins. If you want to request a completed plugin, there is a forum for that here.

Bugsy 01-08-2021 23:22

Re: Help coding Godmode for 5secs
 
I don't think you need to check if connected/alive in cmd start...and you never need to do both as alive has a connected check built in so you'd only ever need to check alive. I'd remove the entire if statement.

You do not need to check if the task exists, just call remove_task().

I'd do this
PHP Code:

public RemoveGodMode(id)
{
    
iGodMode[id] = false

    
if ( is_user_aliveid ) )
    {
        
set_user_godmode(idfalse)
        
client_print(idprint_chat"GodMode Off!")
    }

    return 
PLUGIN_HANDLED



loiraolhosazul 01-08-2021 23:32

Re: Help coding Godmode for 5secs
 
Quote:

Originally Posted by Bugsy (Post 2731874)
I don't think you need to check if connected/alive in cmd start...and you never need to do both as alive has a connected check built in so you'd only ever need to check alive. I'd remove the entire if statement.

You do not need to check if the task exists, just call remove_task().

I'd do this
PHP Code:

public RemoveGodMode(id)
{
    
iGodMode[id] = false

    
if(!is_user_connected(id))
    {
        
remove_task(id)
    }
    else
    {
        
set_user_godmode(idfalse)
        
client_print(idprint_chat"GodMode Off!")
    }

    return 
PLUGIN_HANDLED



whatever, both work

fysiks 01-08-2021 23:44

Re: Help coding Godmode for 5secs
 
Quote:

Originally Posted by Bugsy (Post 2731874)
I don't think you need to check if connected/alive in cmd start...and you never need to do both as alive has a connected check built in so you'd only ever need to check alive. I'd remove the entire if statement.

You do not need to check if the task exists, just call remove_task().

When RemoveGodMode() is getting called, the task has already completed so there's no task to remove. However, the task should be removed in client_disconnect() for the case where a player disconnects within the 5 seconds and potentially another connects in the same slot.

Quote:

Originally Posted by loiraolhosazul (Post 2731876)
whatever, both work

Wow, ungrateful much? He's just trying to give advice on how to write better code. Like I said before, this is the type of help that should be given in Scripting Help (generally).


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

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