Raised This Month: $ Target: $400
 0% 

Noclip Expire


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
wEight
BANNED
Join Date: Jan 2015
Old 05-30-2015 , 11:05   Noclip Expire
Reply With Quote #1

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <fun>

#define PLUGIN "nctest"
#define VERSION "1.0"
#define AUTHOR "wEight"

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say /nc""cmd_nc")
}

public 
cmd_nc(id)
{
    if(
is_user_alive(id))
    {
        if(
get_user_noclip(id) == 0)
        {
            
set_user_noclip(id1)
            
client_print(idprint_chat"Noclip On")
            
set_task(5.0"expire_nc")
        }
        else
        {
            
client_print(idprint_chat"Already have noclip")
        }
    }
    return 
PLUGIN_HANDLED
}

public 
expire_nc(id)
{
    if(
is_user_alive(id))
    {
        
set_user_noclip(id0)
        
client_print(idprint_chat"Noclip Expired")
    }
    return 
PLUGIN_HANDLED

expire_nc(id) wont work, when use set_user_noclip and client_print only without if(is_user_alive(id)) it gives me an error for set_user_noclip.

Translation: When i get noclip, it passes 5 seconds and i still have noclip, It's supposed to expire.
wEight is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-30-2015 , 11:20   Re: Noclip Expire
Reply With Quote #2

When you call set_task(), you are not passing the players id so expire_nc() does not know which player to remove noclip from. You also need to remove the task if a player disconnects within the 5 seconds after set_task() is called for that player.
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <fun>

#define PLUGIN "nctest"
#define VERSION "1.0"
#define AUTHOR "wEight"

const TASK_NC 32143;

public 
plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say /nc""cmd_nc")
}

public 
client_disconnectid )
{
    
remove_taskid TASK_NC );
}

public 
cmd_nc(id)
{
    if(
is_user_alive(id))
    {
        if(
get_user_noclip(id) == 0)
        {
            
set_user_noclip(id1)
            
client_print(idprint_chat"Noclip On")
            
set_task(5.0"expire_nc" TASK_NC id )
        }
        else
        {
            
client_print(idprint_chat"Already have noclip")
        }
    }
    return 
PLUGIN_HANDLED
}

public 
expire_nc(id)
{
    
id -= TASK_NC;
    
    if(
is_user_alive(id))
    {
        
set_user_noclip(id0)
        
client_print(idprint_chat"Noclip Expired")
    }
    return 
PLUGIN_HANDLED

__________________
Bugsy is offline
wEight
BANNED
Join Date: Jan 2015
Old 05-30-2015 , 11:50   Re: Noclip Expire
Reply With Quote #3

Thanks, i might understand this code now, but
PHP Code:
const TASK_NC 32143
Is it supposed to be exactly 32143 or can it be any number?
wEight is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-30-2015 , 11:56   Re: Noclip Expire
Reply With Quote #4

Quote:
Originally Posted by wEight View Post
Thanks, i might understand this code now, but
PHP Code:
const TASK_NC 32143
Is it supposed to be exactly 32143 or can it be any number?
32143 is just a random number.
__________________

Last edited by Bugsy; 05-30-2015 at 11:57.
Bugsy 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 20:25.


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