AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   menu item time limit (https://forums.alliedmods.net/showthread.php?t=174450)

Juk0 12-20-2011 08:51

menu item time limit
 
Hey!

Im not good at scripting yet so i need help with menu item time limit code, so if someone picks like "noclip" from menu once, and tries to do it again in 90 seconds, menu says "You can pick noclip after 90 seconds".

Thanks already :)

fysiks 12-20-2011 15:47

Re: menu item time limit
 
Have a variable that contains the timestamp at which they can use it again. Then, everytime they call the menu (or whatever) you check to see if their stored time is less than get_systime(). If yes, then let them choose, if no, show your message. Each time they choose, add the 90 to get_systime() and store that as the new timestamp.

Juk0 12-20-2011 17:02

Re: menu item time limit
 
Thanks for reply fysik, but could you post me the full code? Im not enought good at scripting yet, im doing my first plugin at this moment. Sorry aboat my poor english.

fysiks 12-20-2011 17:24

Re: menu item time limit
 
Quote:

Originally Posted by Juk0 (Post 1616727)
Thanks for reply fysik, but could you post me the full code? Im not enought good at scripting yet, im doing my first plugin at this moment. Sorry aboat my poor english.

If I post code it will be exactly what I said in words. If you want me to add it in for you then you need to post your full code.

Juk0 12-21-2011 09:49

Re: menu item time limit
 
Here is the full code:
PHP Code:

#include <amxmodx>
#include <fun>
#include <colorchat>
#include <stripweapons>
#include <amxmisc>

#define PLUGIN "VIP Menu"
#define VERSION "1.0"
#define AUTHOR "Extract"

#define VIP_FLAG ADMIN_LEVEL_E

enum
{
    
SCOREATTRIB_ARG_PLAYERID 1,
    
SCOREATTRIB_ARG_FLAGS
};

enum ( <<= )
{
    
SCOREATTRIB_FLAG_NONE 0,
    
SCOREATTRIB_FLAG_DEAD 1,
    
SCOREATTRIB_FLAG_BOMB,
    
SCOREATTRIB_FLAG_VIP
};

 new 
pCvar_AdminVIP;

 new 
bool:NoclipUsed[33];

 new 
szName[33]
 
 public 
plugin_init()
 {

    
register_clcmd"say /vipmenu","VIPMenu");
    
register_plugin(PLUGINVERSIONAUTHOR);
    
    
register_messageget_user_msgid"ScoreAttrib" ), "MessageScoreAttrib" );
    
pCvar_AdminVIP register_cvar"amx_adminvip""1" );
    
 }
 
public 
MessageScoreAttribiMsgIdiDestiReceiver )
{
    if( 
get_pcvar_numpCvar_AdminVIP ) )
    {
        new 
iPlayer get_msg_arg_intSCOREATTRIB_ARG_PLAYERID );
        
        if( 
accessiPlayerVIP_FLAG ) )
        {
            
set_msg_arg_intSCOREATTRIB_ARG_FLAGSARG_BYTESCOREATTRIB_FLAG_VIP );
        }
    }
}  
 
 public 
VIPMenu(id)
 {
     
    new 
menu menu_create("\rJailBreak VIP menu""menu_handler");

    
menu_additem(menu"\yGive \wAWP""1"ADMIN_LEVEL_E);
    
menu_additem(menu"\wNoclip (10s)""2"ADMIN_LEVEL_E);

    
menu_setprop(menuMPROP_EXITMEXIT_ALL);

    
menu_display(idmenu0);

 }

 public 
menu_handler(idmenuitem)
 {
    if( 
item == MENU_EXIT )
    {
        
menu_destroy(menu);
        return 
PLUGIN_HANDLED;
    }
    
    new 
data[6], szName[64];
    new 
accesscallback;
    
menu_item_getinfo(menuitemaccessdata,charsmax(data), szName,charsmax(szName), callback);

    new 
key str_to_num(data);

    switch(
key)
    {
        case 
1Givesniper(id)

        case 
2Noclip(id)
       
    }
    
menu_destroy(menu);
    return 
PLUGIN_HANDLED;
    
 }
 public 
Noclip(id) {
    
    if(!
is_user_alive(id))
    {
        
ColorChat(idGREY"You need to be alive to use this!")
        return 
PLUGIN_HANDLED
    
}
    
    if(
NoclipUsed[id] == true)
    {
        
ColorChat(idGREY"You have allready used your Noclip!")
        return 
PLUGIN_HANDLED
    
}
    
    
get_user_name(idszName32)

    
set_task(10.0"RemoveNoclip"id)
    
ColorChat(0GREY"^4%s^3 now has noclip for 10 seconds!"szName)
    
set_user_noclip(id1)
    
NoclipUsed[id] = true
    
return PLUGIN_CONTINUE
    
}

public 
RemoveNoclip(id)
{
    
set_user_noclip(id0)
    
ColorChat(0GREY"^4%s ^3returned to normal clipping"szName)
    
NoclipUsed[id] = false
    
return PLUGIN_HANDLED
    
}

public 
Givesniper(id)
{
    
    if(!
is_user_alive(id))
    {
        
ColorChat(idGREY"You need to be alive to use this!")
        return 
PLUGIN_HANDLED
    
}
    
StripWeapons(idPrimary);
    
give_item(id,"weapon_awp")
    
give_item(id,"ammo_338magnum")
    
give_item(id,"ammo_338magnum")
    
give_item(id,"ammo_338magnum")
    
get_user_name(idszName32)
    
ColorChat(idGREY"^4%s ^3gave himself AWP"szName)
    return 
PLUGIN_HANDLED



fysiks 12-21-2011 16:10

Re: menu item time limit
 
Ok, here ya go. You can study the code that I added and change if needed. But, if you want to add it to other options or change what options it handled then you should do it on your own since you have all you need now.

PHP Code:

#include <amxmodx>
#include <fun>
#include <colorchat>
#include <stripweapons>
#include <amxmisc>

#define PLUGIN "VIP Menu"
#define VERSION "1.0"
#define AUTHOR "Extract"

#define VIP_FLAG ADMIN_LEVEL_E

enum
{
    
SCOREATTRIB_ARG_PLAYERID 1,
    
SCOREATTRIB_ARG_FLAGS
};

enum ( <<= )
{
    
SCOREATTRIB_FLAG_NONE 0,
    
SCOREATTRIB_FLAG_DEAD 1,
    
SCOREATTRIB_FLAG_BOMB,
    
SCOREATTRIB_FLAG_VIP
};

new 
pCvar_AdminVIP;

new 
bool:NoclipUsed[33];
new 
g_iNoClipNextUse[33];

new 
szName[33]

public 
plugin_init()
{
    
register_clcmd"say /vipmenu","VIPMenu");
    
register_plugin(PLUGINVERSIONAUTHOR);

    
register_messageget_user_msgid"ScoreAttrib" ), "MessageScoreAttrib" );
    
pCvar_AdminVIP register_cvar"amx_adminvip""1" );

}

public 
MessageScoreAttribiMsgIdiDestiReceiver )
{
    if( 
get_pcvar_numpCvar_AdminVIP ) )
    {
        new 
iPlayer get_msg_arg_intSCOREATTRIB_ARG_PLAYERID );

        if( 
accessiPlayerVIP_FLAG ) )
        {
            
set_msg_arg_intSCOREATTRIB_ARG_FLAGSARG_BYTESCOREATTRIB_FLAG_VIP );
        }
    }
}

public 
VIPMenu(id)
{

    new 
menu menu_create("\rJailBreak VIP menu""menu_handler");

    
menu_additem(menu"\yGive \wAWP""1"ADMIN_LEVEL_E);
    
menu_additem(menu"\wNoclip (10s)""2"ADMIN_LEVEL_E);

    
menu_setprop(menuMPROP_EXITMEXIT_ALL);

    
menu_display(idmenu0);

}

public 
menu_handler(idmenuitem)
{
    if( 
item == MENU_EXIT )
    {
        
menu_destroy(menu);
        return 
PLUGIN_HANDLED;
    }

    new 
data[6], szName[64];
    new 
accesscallback;
    
menu_item_getinfo(menuitemaccessdata,charsmax(data), szName,charsmax(szName), callback);

    new 
key str_to_num(data);

    switch(
key)
    {
        case 
1Givesniper(id)
        case 
2:
        {
            new 
iTimestamp get_systime()
            if( 
g_iNoClipNextUse[id] < iTimestamp )
            {
                
Noclip(id)
                
g_iNoClipNextUse[id] = iTimestamp 90
            
}
            else
            {
                
client_print(idprint_chat"You must wait %d seconds to use NoClip again"g_iNoClipNextUse[id] - iTimestamp);
            }
        }
    }
    
menu_destroy(menu);
    return 
PLUGIN_HANDLED;

}
public 
Noclip(id)
{
    if(!
is_user_alive(id))
    {
        
ColorChat(idGREY"You need to be alive to use this!")
        return 
PLUGIN_HANDLED
    
}

    if(
NoclipUsed[id] == true)
    {
        
ColorChat(idGREY"You have allready used your Noclip!")
        return 
PLUGIN_HANDLED
    
}

    
get_user_name(idszName32)

    
set_task(10.0"RemoveNoclip"id)
    
ColorChat(0GREY"^4%s^3 now has noclip for 10 seconds!"szName)
    
set_user_noclip(id1)
    
NoclipUsed[id] = true
    
return PLUGIN_CONTINUE

}

public 
RemoveNoclip(id)
{
    
set_user_noclip(id0)
    
ColorChat(0GREY"^4%s ^3returned to normal clipping"szName)
    
NoclipUsed[id] = false
    
return PLUGIN_HANDLED

}

public 
Givesniper(id)
{
    if(!
is_user_alive(id))
    {
        
ColorChat(idGREY"You need to be alive to use this!")
        return 
PLUGIN_HANDLED
    
}
    
StripWeapons(idPrimary);
    
give_item(id,"weapon_awp")
    
give_item(id,"ammo_338magnum")
    
give_item(id,"ammo_338magnum")
    
give_item(id,"ammo_338magnum")
    
get_user_name(idszName32)
    
ColorChat(idGREY"^4%s ^3gave himself AWP"szName)
    return 
PLUGIN_HANDLED



Juk0 12-22-2011 01:25

Re: menu item time limit
 
Quote:

Originally Posted by fysiks (Post 1617322)
PHP Code:

#include <amxmodx>
#include <fun>
#include <colorchat>
#include <stripweapons>
#include <amxmisc>

#define PLUGIN "VIP Menu"
#define VERSION "1.0"
#define AUTHOR "Extract"

#define VIP_FLAG ADMIN_LEVEL_E

enum
{
    
SCOREATTRIB_ARG_PLAYERID 1,
    
SCOREATTRIB_ARG_FLAGS
};

enum ( <<= )
{
    
SCOREATTRIB_FLAG_NONE 0,
    
SCOREATTRIB_FLAG_DEAD 1,
    
SCOREATTRIB_FLAG_BOMB,
    
SCOREATTRIB_FLAG_VIP
};

new 
pCvar_AdminVIP;

new 
bool:NoclipUsed[33];
new 
g_iNoClipNextUse[33];

new 
szName[33]

public 
plugin_init()
{
    
register_clcmd"say /vipmenu","VIPMenu");
    
register_plugin(PLUGINVERSIONAUTHOR);

    
register_messageget_user_msgid"ScoreAttrib" ), "MessageScoreAttrib" );
    
pCvar_AdminVIP register_cvar"amx_adminvip""1" );

}

public 
MessageScoreAttribiMsgIdiDestiReceiver )
{
    if( 
get_pcvar_numpCvar_AdminVIP ) )
    {
        new 
iPlayer get_msg_arg_intSCOREATTRIB_ARG_PLAYERID );

        if( 
accessiPlayerVIP_FLAG ) )
        {
            
set_msg_arg_intSCOREATTRIB_ARG_FLAGSARG_BYTESCOREATTRIB_FLAG_VIP );
        }
    }
}

public 
VIPMenu(id)
{

    new 
menu menu_create("\rJailBreak VIP menu""menu_handler");

    
menu_additem(menu"\yGive \wAWP""1"ADMIN_LEVEL_E);
    
menu_additem(menu"\wNoclip (10s)""2"ADMIN_LEVEL_E);

    
menu_setprop(menuMPROP_EXITMEXIT_ALL);

    
menu_display(idmenu0);

}

public 
menu_handler(idmenuitem)
{
    if( 
item == MENU_EXIT )
    {
        
menu_destroy(menu);
        return 
PLUGIN_HANDLED;
    }

    new 
data[6], szName[64];
    new 
accesscallback;
    
menu_item_getinfo(menuitemaccessdata,charsmax(data), szName,charsmax(szName), callback);

    new 
key str_to_num(data);

    switch(
key)
    {
        case 
1Givesniper(id)
        case 
2:
        {
            new 
iTimestamp get_systime()
            if( 
g_iNoClipNextUse[id] < iTimestamp )
            {
                
Noclip(id)
                
g_iNoClipNextUse[id] = iTimestamp
            
}
            else
            {
                
client_print(idprint_chat"You must wait %d seconds to use NoClip again"g_iNoClipNextUse[id] - iTimestamp);
            }
        }
    }
    
menu_destroy(menu);
    return 
PLUGIN_HANDLED;

}
public 
Noclip(id)
{
    if(!
is_user_alive(id))
    {
        
ColorChat(idGREY"You need to be alive to use this!")
        return 
PLUGIN_HANDLED
    
}

    if(
NoclipUsed[id] == true)
    {
        
ColorChat(idGREY"You have allready used your Noclip!")
        return 
PLUGIN_HANDLED
    
}

    
get_user_name(idszName32)

    
set_task(10.0"RemoveNoclip"id)
    
ColorChat(0GREY"^4%s^3 now has noclip for 10 seconds!"szName)
    
set_user_noclip(id1)
    
NoclipUsed[id] = true
    
return PLUGIN_CONTINUE

}

public 
RemoveNoclip(id)
{
    
set_user_noclip(id0)
    
ColorChat(0GREY"^4%s ^3returned to normal clipping"szName)
    
NoclipUsed[id] = false
    
return PLUGIN_HANDLED

}

public 
Givesniper(id)
{
    if(!
is_user_alive(id))
    {
        
ColorChat(idGREY"You need to be alive to use this!")
        return 
PLUGIN_HANDLED
    
}
    
StripWeapons(idPrimary);
    
give_item(id,"weapon_awp")
    
give_item(id,"ammo_338magnum")
    
give_item(id,"ammo_338magnum")
    
give_item(id,"ammo_338magnum")
    
get_user_name(idszName32)
    
ColorChat(idGREY"^4%s ^3gave himself AWP"szName)
    return 
PLUGIN_HANDLED



That isnt working. You can use noclip again every time it returns back to normal clipping as before. You didnt set the 90s time in the script?

fysiks 12-22-2011 03:01

Re: menu item time limit
 
Quote:

Originally Posted by Juk0 (Post 1617517)
That isnt working. You can use noclip again every time it returns back to normal clipping as before. You didnt set the 90s time in the script?

Oops, looks like I forgot to add 90 to the timestamp.

PHP Code:

g_iNoClipNextUse[id] = iTimestamp 90 


Juk0 12-22-2011 04:04

Re: menu item time limit
 
Thanks alot man, i knew you guys are friendly on these forums :):)

fysiks 12-22-2011 13:36

Re: menu item time limit
 
Quote:

Originally Posted by Juk0 (Post 1617560)
Thanks alot man, i knew you guys are friendly on these forums :):)

As long as people follow the rules (like you did) we are nice :wink:.


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

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