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

HELP on timer on plugin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
asdfdsdf
AlliedModders Donor
Join Date: Aug 2010
Location: Belgium
Old 10-21-2012 , 11:27   HELP on timer on plugin
Reply With Quote #1

Hello im making a vipmenu with next to each item name wait x sec or available but i need to now how to fix this is shorter code because now i have to add it on each single item as you see in my code;

PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <colorchat>
#include <hamsandwich>
#include <fun>

#define PLUGIN "Menu"
#define VERSION "1.0"
#define AUTHOR "asdfdsdf"

#define SCOREATTRIB_VIP  ( 1 << 2 )

new const Prefix[] = "[vip]"
new const Quad[] = "/misc/vip/fa/quad.wav" 

new Time[33]
new 
Timer[33]
new 
Timers[33]

new 
boolHasdamage[33]

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say /menu""Cmdmenu")
        
register_message(get_user_msgid("ScoreAttrib"), "Message_ScoreAttrib")
    
    
RegisterHam(Ham_TakeDamage"player""Cmdtakedamage")
}

public 
Message_ScoreAttribiMessageIDiMessageTypeiMessageDest ) {
    static 
iPlayer;
 
    
iPlayer get_msg_arg_int(1)
 
    if(
get_user_flags(iPlayer) & ADMIN_LEVEL_H)
    {
        
set_msg_arg_int(2ARG_BYTESCOREATTRIB_VIP)
    }
}
public 
plugin_precache()
{
    
precache_sound(Quad)
}

public 
Cmdtakedamage(idinflictorattackerFloat:damagedamagebits
{
    if (
Hasdamage[id] && is_user_alive(id))
    {
        
SetHamParamFloat(4damage 4.0)
    }
}

public 
Cmdmenu(id)
{
    new 
szText[555 char]
    new 
menu menu_create("\yVipMenu""Menuhandler")
    
    if (
Time[id] > 0)
    {
        
formatex(szTextcharsmax(szText), "\rNoclip \y(10s) \r[Wait %isec]"Time[id])
        
menu_additem(menuszText"1"0)
    }
    else
    {
        
formatex(szTextcharsmax(szText), "\rNoclip \y(10s) \r[Available]")
        
menu_additem(menuszText"1"0)
    }
    
    if (
Timer[id] > 0)
    {
        
formatex(szTextcharsmax(szText), "\rGodmode \y(10s) \r[Wait %isec]"Timer[id])
        
menu_additem(menuszText"2"0)
    }
    else
    {
        
formatex(szTextcharsmax(szText), "\rGodmode \y(10s) \r[Available]")
        
menu_additem(menuszText"2"0)
    }
    
    if (
Timers[id] > 0)
    {
        
formatex(szTextcharsmax(szText), "\yQuad \rdamage \y(10s) \r[Wait %isec]"Timers[id])
        
menu_additem(menuszText"3"0)
    }
    else
    {
        
formatex(szTextcharsmax(szText), "\yQuad \rDamage \y(10s) \r[Available]")
        
menu_additem(menuszText"3"0)
    }
    
    
menu_setprop(menuMPROP_EXITMEXIT_ALL)
    
menu_display(idmenu0)
}

public 
Menuhandler(idmenuitem)
{
    if (
item == MENU_EXIT)
    {
        
menu_destroy(menu)
        return 
PLUGIN_HANDLED
    
}
    
    new 
data[6], name[64], accescallback
    menu_item_getinfo
(menuitemaccesdatacharsmax(data), namecharsmax(name), callback)
    new 
key str_to_num(data)
    
    switch (
key)
    {
        case 
1:
        {
            if (!(
Time[id] == 0))
            {
                return 
PLUGIN_HANDLED
            
}
            
            
Time[id] = 300
            
            set_user_noclip
(id1)
            
            
set_task(10.0"Resetnoclip"id)
            
            
set_task(1.0"Resettime"id)
            
            
ColorChat(idGREY"%s ^1You have ^4enabled^1 your noclip! ^3(10s)"Prefix)
        }
        case 
2:
        {
            if (!(
Timer[id] == 0))
            {
                return 
PLUGIN_HANDLED
            
}
            
            
Timer[id] = 1500
            
            set_user_godmode
(id1)
            
            
set_task(10.0"Resetgodmode"id)
            
            
set_task(1.0"Resettimer"id)
            
            
ColorChat(idGREY"%s ^1You have ^4enabled^1 your godmode! ^3(10s)"Prefix)
        }
        case 
3:
        {
            if (!(
Timers[id] == 0))
            {
                return 
PLUGIN_HANDLED
            
}
            if (
Hasdamage[id])
            {
                return 
PLUGIN_HANDLED
            
}
            
            
Timers[id] = 600
            
            Hasdamage
[id] = true
            
            client_cmd
(id"spk %s"Quad)
            
            
set_task(1.0"Resettimers"id)
            
            
ColorChat(idGREY"%s ^1You have ^4enabled^1 your Quad damage! ^3(15s)"Prefix)
        }
        
        
    }
    
    
menu_destroy(menu)
    return 
PLUGIN_HANDLED
}

public 
Resettime(id)
{
    if (
Time[id] > 0)
    {
        
Time[id] --
        
        
set_task(1.0"Resettime"id)
    }
}

public 
Resettimer(id)
{
    if (
Timer[id] > 0)
    {
        
Timer[id] --
        
        
set_task(1.0"Resettimer"id)
    }
}

public 
Resettimers(id)
{
    if (
Timers[id] > 0)
    {
        
Timers[id] --
        
        
set_task(1.0"Resettimers"id)
        
        return 
PLUGIN_CONTINUE
    
}
    
    
Hasdamage[id] = false
    
    
return PLUGIN_HANDLED
}

public 
Resetnoclip(id)
{
    
set_user_noclip(id0)
    
    
ColorChat(idGREY"%s ^1Your noclip has been ^4removed^1!"Prefix)
}

public 
Resetgodmode(id)
{
    
set_user_godmode(id0)
    
    
ColorChat(idGREY"%s ^1Your godmode has been ^4removed^1!"Prefix)

asdfdsdf is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 10-22-2012 , 12:36   Re: HELP on timer on plugin
Reply With Quote #2

Quote:
Originally Posted by asdfdsdf View Post
Hello im making a vipmenu with next to each item name wait x sec or available but i need to now how to fix this is shorter code because now i have to add it on each single item as you see in my code;

PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <colorchat>
#include <hamsandwich>
#include <fun>

#define PLUGIN "Menu"
#define VERSION "1.0"
#define AUTHOR "asdfdsdf"

#define SCOREATTRIB_VIP  ( 1 << 2 )

new const Prefix[] = "[vip]"
new const Quad[] = "/misc/vip/fa/quad.wav" 

new Time[33]
new 
Timer[33]
new 
Timers[33]

new 
boolHasdamage[33]

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say /menu""Cmdmenu")
        
register_message(get_user_msgid("ScoreAttrib"), "Message_ScoreAttrib")
    
    
RegisterHam(Ham_TakeDamage"player""Cmdtakedamage")
}

public 
Message_ScoreAttribiMessageIDiMessageTypeiMessageDest ) {
    static 
iPlayer;
 
    
iPlayer get_msg_arg_int(1)
 
    if(
get_user_flags(iPlayer) & ADMIN_LEVEL_H)
    {
        
set_msg_arg_int(2ARG_BYTESCOREATTRIB_VIP)
    }
}
public 
plugin_precache()
{
    
precache_sound(Quad)
}

public 
Cmdtakedamage(idinflictorattackerFloat:damagedamagebits
{
    if (
Hasdamage[id] && is_user_alive(id))
    {
        
SetHamParamFloat(4damage 4.0)
    }
}

public 
Cmdmenu(id)
{
    new 
szText[555 char]
    new 
menu menu_create("\yVipMenu""Menuhandler")
    
    if (
Time[id] > 0)
    {
        
formatex(szTextcharsmax(szText), "\rNoclip \y(10s) \r[Wait %isec]"Time[id])
        
menu_additem(menuszText"1"0)
    }
    else
    {
        
formatex(szTextcharsmax(szText), "\rNoclip \y(10s) \r[Available]")
        
menu_additem(menuszText"1"0)
    }
    
    if (
Timer[id] > 0)
    {
        
formatex(szTextcharsmax(szText), "\rGodmode \y(10s) \r[Wait %isec]"Timer[id])
        
menu_additem(menuszText"2"0)
    }
    else
    {
        
formatex(szTextcharsmax(szText), "\rGodmode \y(10s) \r[Available]")
        
menu_additem(menuszText"2"0)
    }
    
    if (
Timers[id] > 0)
    {
        
formatex(szTextcharsmax(szText), "\yQuad \rdamage \y(10s) \r[Wait %isec]"Timers[id])
        
menu_additem(menuszText"3"0)
    }
    else
    {
        
formatex(szTextcharsmax(szText), "\yQuad \rDamage \y(10s) \r[Available]")
        
menu_additem(menuszText"3"0)
    }
    
    
menu_setprop(menuMPROP_EXITMEXIT_ALL)
    
menu_display(idmenu0)
}

public 
Menuhandler(idmenuitem)
{
    if (
item == MENU_EXIT)
    {
        
menu_destroy(menu)
        return 
PLUGIN_HANDLED
    
}
    
    new 
data[6], name[64], accescallback
    menu_item_getinfo
(menuitemaccesdatacharsmax(data), namecharsmax(name), callback)
    new 
key str_to_num(data)
    
    switch (
key)
    {
        case 
1:
        {
            if (!(
Time[id] == 0))
            {
                return 
PLUGIN_HANDLED
            
}
            
            
Time[id] = 300
            
            set_user_noclip
(id1)
            
            
set_task(10.0"Resetnoclip"id)
            
            
set_task(1.0"Resettime"id)
            
            
ColorChat(idGREY"%s ^1You have ^4enabled^1 your noclip! ^3(10s)"Prefix)
        }
        case 
2:
        {
            if (!(
Timer[id] == 0))
            {
                return 
PLUGIN_HANDLED
            
}
            
            
Timer[id] = 1500
            
            set_user_godmode
(id1)
            
            
set_task(10.0"Resetgodmode"id)
            
            
set_task(1.0"Resettimer"id)
            
            
ColorChat(idGREY"%s ^1You have ^4enabled^1 your godmode! ^3(10s)"Prefix)
        }
        case 
3:
        {
            if (!(
Timers[id] == 0))
            {
                return 
PLUGIN_HANDLED
            
}
            if (
Hasdamage[id])
            {
                return 
PLUGIN_HANDLED
            
}
            
            
Timers[id] = 600
            
            Hasdamage
[id] = true
            
            client_cmd
(id"spk %s"Quad)
            
            
set_task(1.0"Resettimers"id)
            
            
ColorChat(idGREY"%s ^1You have ^4enabled^1 your Quad damage! ^3(15s)"Prefix)
        }
        
        
    }
    
    
menu_destroy(menu)
    return 
PLUGIN_HANDLED
}

public 
Resettime(id)
{
    if (
Time[id] > 0)
    {
        
Time[id] --
        
        
set_task(1.0"Resettime"id)
    }
}

public 
Resettimer(id)
{
    if (
Timer[id] > 0)
    {
        
Timer[id] --
        
        
set_task(1.0"Resettimer"id)
    }
}

public 
Resettimers(id)
{
    if (
Timers[id] > 0)
    {
        
Timers[id] --
        
        
set_task(1.0"Resettimers"id)
        
        return 
PLUGIN_CONTINUE
    
}
    
    
Hasdamage[id] = false
    
    
return PLUGIN_HANDLED
}

public 
Resetnoclip(id)
{
    
set_user_noclip(id0)
    
    
ColorChat(idGREY"%s ^1Your noclip has been ^4removed^1!"Prefix)
}

public 
Resetgodmode(id)
{
    
set_user_godmode(id0)
    
    
ColorChat(idGREY"%s ^1Your godmode has been ^4removed^1!"Prefix)

use 2dimensional arrays & use switch
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
asdfdsdf
AlliedModders Donor
Join Date: Aug 2010
Location: Belgium
Old 10-22-2012 , 13:58   Re: HELP on timer on plugin
Reply With Quote #3

Can you maybe give me an example
asdfdsdf is offline
Catastrophe
Veteran Member
Join Date: Jul 2012
Location: somewhere between narnia
Old 12-27-2013 , 01:22   Re: HELP on timer on plugin
Reply With Quote #4

I really dont understand what u want to do..... can u take your time and explain in detail... ??
__________________
You will find everything u need :-
Catastrophe is offline
asdfdsdf
AlliedModders Donor
Join Date: Aug 2010
Location: Belgium
Old 12-27-2013 , 11:58   Re: HELP on timer on plugin
Reply With Quote #5

Well im actually looking its not for this code anymore but same purpose i want to get on each item a cooldown so next to each item it should say [wait x sec] lets say item 1 they can use it each 5 min so when they used the item it should say "Item" [wait x sec ] or Item [available]
asdfdsdf is offline
Catastrophe
Veteran Member
Join Date: Jul 2012
Location: somewhere between narnia
Old 12-28-2013 , 00:06   Re: HELP on timer on plugin
Reply With Quote #6

First off :-
change your original checks to this :-

PHP Code:
if (!(Timer[id] <= 0))
            {
                return 
PLUGIN_HANDLED
            

Not that it makes any difference but after this even if smthing goes wrong and the timer runs below zero it will call the time...

Secondly, You will have to edit each single item off hand... thats the only way to it... what u can do is instead of using :-
PHP Code:
new Time[33
new 
Timer[33
new 
Timers[33
just use :-

PHP Code:
new Timer[3][33
and then for the first item use
PHP Code:
Timer[0][id] = 300 
and in reset function also use
PHP Code:
Timer[0][id]-- 
So here the "Timer[3][33]" is a two dimentional array... where the "3" decides its size here when i set 3 it means it declares a total of three variables from 1 array that is "Timer[0][id]", "Timer[1][id]" and "Timer[2][id]"

Where all three of them are different like u use 3 diff variables .... so in the end its like :
PHP Code:
Time[id] = Timer[0][id
Timer[id] = Timer[1][id]  
Timers[id] = Timer[2][id
If u make it "Timer[4][33]" , one more variable will be added i.e. "Timer[3][id]"

so these are 2D arrays...
__________________
You will find everything u need :-
Catastrophe 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 23:48.


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