Raised This Month: $51 Target: $400
 12% 

Solved Help coding Godmode for 5secs


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
husam124
BANNED
Join Date: Jul 2017
Location: Usa
Old 01-08-2021 , 10:57   Help coding Godmode for 5secs
Reply With Quote #1

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.

Last edited by husam124; 01-08-2021 at 11:09. Reason: solved
husam124 is offline
Send a message via ICQ to husam124 Send a message via AIM to husam124 Send a message via Yahoo to husam124 Send a message via Skype™ to husam124
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 01-08-2021 , 11:03   Re: Help coding Godmode for 5secs
Reply With Quote #2

Simply use the set_task() function.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
husam124
BANNED
Join Date: Jul 2017
Location: Usa
Old 01-08-2021 , 11:04   Re: Help coding Godmode for 5secs
Reply With Quote #3

well i would'nt be asking if i knew how to use it
husam124 is offline
Send a message via ICQ to husam124 Send a message via AIM to husam124 Send a message via Yahoo to husam124 Send a message via Skype™ to husam124
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 01-08-2021 , 13:49   Re: Help coding Godmode for 5secs
Reply With Quote #4

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.
__________________

Last edited by OciXCrom; 01-08-2021 at 13:50.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Old 01-08-2021, 14:12
iceeedr
This message has been deleted by iceeedr. Reason: nvm
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-08-2021 , 22:35   Re: Help coding Godmode for 5secs
Reply With Quote #5

Quote:
Originally Posted by husam124 View Post
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.
__________________
fysiks is offline
loiraolhosazul
Member
Join Date: May 2020
Old 01-08-2021 , 23:14   Re: Help coding Godmode for 5secs
Reply With Quote #6

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.
loiraolhosazul is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-08-2021 , 23:19   Re: Help coding Godmode for 5secs
Reply With Quote #7

Quote:
Originally Posted by loiraolhosazul View Post
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.
__________________
fysiks is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-08-2021 , 23:22   Re: Help coding Godmode for 5secs
Reply With Quote #8

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

__________________

Last edited by Bugsy; 01-09-2021 at 00:03.
Bugsy is offline
loiraolhosazul
Member
Join Date: May 2020
Old 01-08-2021 , 23:32   Re: Help coding Godmode for 5secs
Reply With Quote #9

Quote:
Originally Posted by Bugsy View Post
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
loiraolhosazul is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-08-2021 , 23:44   Re: Help coding Godmode for 5secs
Reply With Quote #10

Quote:
Originally Posted by Bugsy View Post
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 View Post
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).
__________________
fysiks 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 10:28.


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