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

[REQ] Case every 5 rounds


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
alferd
Veteran Member
Join Date: Dec 2019
Location: Iran is Always Eternal
Old 04-16-2020 , 02:07   [REQ] Case every 5 rounds
Reply With Quote #1

I have a menu and I want to use the items once every 5 rounds
Like the example below:

Code:
 Free Weapon

1. Deagle [ Every 1 rounds once ]
2. Ak47   [ Every 5 rounds once ]
my plugin:
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <fun>
#include <hamsandwich>
#include <cromchat>

#define PLUGIN "Weapon_Player"
#define VERSION "2.0"
#define AUTHOR "AlferD"

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_concmd("say /freewpn","showmenu");
}

public 
showmenu(id)
{
    new 
menu menu_create("Free Weapon""Pressedrod");
    
menu_additemmenu"Deagle [ Every 1 rounds once ]""0");
         
menu_additemmenu"AK47 [ Every 5 rounds once ]""1");
     
     
menu_setpropmenuMPROP_EXITMEXIT_ALL );   
     
     
menu_displayidmenu);  
     
     return 
PLUGIN_HANDLED;
}

public 
Pressedrod(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);
    
    if(!
is_user_alive(id))
        return 
PLUGIN_HANDLED
        
    
switch(key) {
        case 
0: { 
        
strip_user_weapons (id)
        
give_item(id,"weapon_deagle")
        
give_item(id,"ammo_50ae")
        
give_item(id,"ammo_50ae")
        
give_item(id,"ammo_50ae")
        
give_item(id,"ammo_50ae")
        
give_item(id,"ammo_50ae")
        
give_item(id,"ammo_50ae")
        
give_item(id,"ammo_50ae")
        
give_item(id,"weapon_knife")    
        }
        
        case 
1: { 
        
strip_user_weapons (id)
        
give_item(id,"weapon_ak47")
        
give_item(id,"ammo_762nato")
        
give_item(id,"ammo_762nato")
        
give_item(id,"ammo_762nato")
        
give_item(id,"weapon_knife")    
        }
    }
    return 
PLUGIN_CONTINUE

I'm sorry I didn't choose a good title

Last edited by alferd; 06-02-2020 at 15:55.
alferd is offline
ZaX
Senior Member
Join Date: Jan 2015
Old 04-16-2020 , 02:57   Re: [REQ] Case every 5 rounds
Reply With Quote #2

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <fun>
#include <hamsandwich>
#include <cromchat>

#define PLUGIN "Weapon_Player"
#define VERSION "2.0"
#define AUTHOR "AlferD"

new g_Limit[33][2]
new 
RoundCounter
new pCvarRounds

public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_concmd("say /freewpn","showmenu");
    
register_event("HLTV""event_new_round""a""1=0""2=0")
    
pCvarRounds register_cvar("rounds_required""5")
}

public 
event_new_round()
{
    
RoundCounter++

    for(new 
1get_maxplayers(); i++)
    {
        
g_Limit[i][0] = 0

        
if(RoundCounter == get_pcvar_num(pCvarRounds))
        {
            
g_Limit[i][1] = 0
            RoundCounter 
0;
        }
    }
}

public 
showmenu(id)
{
    new 
menu menu_create("Free Weapon""Pressedrod");
    
menu_additemmenu"Deagle [ Every 1 rounds once ]""0");
    
menu_additemmenu"AK47 [ Every 5 rounds once ]""1");
    
menu_setpropmenuMPROP_EXITMEXIT_ALL );   
     
    
menu_displayidmenu);  
     
    return 
PLUGIN_HANDLED;
}

public 
Pressedrod(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);
    
    if(!
is_user_alive(id))
        return 
PLUGIN_HANDLED
        
    
switch(key
    {
        case 
0
        {
            if(
g_Limit[id][0] >= 1)
            {
                
client_print(idprint_chat"Limit reached for this round.")
                return 
PLUGIN_HANDLED
            
}
            
strip_user_weapons (id)
            
give_item(id,"weapon_deagle")
            
cs_set_user_bpammo(idCSW_DEAGLE30)
            
give_item(id,"weapon_knife")
            
g_Limit[id][0]++   
        }
        
        case 
1
        {
            if(
g_Limit[id][1] >= 1)
            {
                
client_print(idprint_chat"You must wait %i more rounds."get_pcvar_num(pCvarRounds) - RoundCounter)
                return 
PLUGIN_HANDLED
            
}
            
strip_user_weapons(id)
            
give_item(id"weapon_ak47")
            
cs_set_user_bpammo(idCSW_AK4790)
            
give_item(id,"weapon_knife"
            
g_Limit[id][1]++
        }
    }
    return 
PLUGIN_CONTINUE

ZaX is offline
alferd
Veteran Member
Join Date: Dec 2019
Location: Iran is Always Eternal
Old 04-16-2020 , 03:43   Re: [REQ] Case every 5 rounds
Reply With Quote #3

Quote:
Originally Posted by ZaX View Post
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <fun>
#include <hamsandwich>
#include <cromchat>

#define PLUGIN "Weapon_Player"
#define VERSION "2.0"
#define AUTHOR "AlferD"

new g_Limit[33][2]
new 
RoundCounter
new pCvarRounds

public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_concmd("say /freewpn","showmenu");
    
register_event("HLTV""event_new_round""a""1=0""2=0")
    
pCvarRounds register_cvar("rounds_required""5")
}

public 
event_new_round()
{
    
RoundCounter++

    for(new 
1get_maxplayers(); i++)
    {
        
g_Limit[i][0] = 0

        
if(RoundCounter == get_pcvar_num(pCvarRounds))
        {
            
g_Limit[i][1] = 0
            RoundCounter 
0;
        }
    }
}

public 
showmenu(id)
{
    new 
menu menu_create("Free Weapon""Pressedrod");
    
menu_additemmenu"Deagle [ Every 1 rounds once ]""0");
    
menu_additemmenu"AK47 [ Every 5 rounds once ]""1");
    
menu_setpropmenuMPROP_EXITMEXIT_ALL );   
     
    
menu_displayidmenu);  
     
    return 
PLUGIN_HANDLED;
}

public 
Pressedrod(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);
    
    if(!
is_user_alive(id))
        return 
PLUGIN_HANDLED
        
    
switch(key
    {
        case 
0
        {
            if(
g_Limit[id][0] >= 1)
            {
                
client_print(idprint_chat"Limit reached for this round.")
                return 
PLUGIN_HANDLED
            
}
            
strip_user_weapons (id)
            
give_item(id,"weapon_deagle")
            
cs_set_user_bpammo(idCSW_DEAGLE30)
            
give_item(id,"weapon_knife")
            
g_Limit[id][0]++   
        }
        
        case 
1
        {
            if(
g_Limit[id][1] >= 1)
            {
                
client_print(idprint_chat"You must wait %i more rounds."get_pcvar_num(pCvarRounds) - RoundCounter)
                return 
PLUGIN_HANDLED
            
}
            
strip_user_weapons(id)
            
give_item(id"weapon_ak47")
            
cs_set_user_bpammo(idCSW_AK4790)
            
give_item(id,"weapon_knife"
            
g_Limit[id][1]++
        }
    }
    return 
PLUGIN_CONTINUE

Tnx
alferd is offline
alferd
Veteran Member
Join Date: Dec 2019
Location: Iran is Always Eternal
Old 04-21-2020 , 10:40   Re: [REQ] Case every 5 rounds
Reply With Quote #4

Quote:
Originally Posted by ZaX View Post
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <fun>
#include <hamsandwich>
#include <cromchat>

#define PLUGIN "Weapon_Player"
#define VERSION "2.0"
#define AUTHOR "AlferD"

new g_Limit[33][2]
new 
RoundCounter
new pCvarRounds

public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_concmd("say /freewpn","showmenu");
    
register_event("HLTV""event_new_round""a""1=0""2=0")
    
pCvarRounds register_cvar("rounds_required""5")
}

public 
event_new_round()
{
    
RoundCounter++

    for(new 
1get_maxplayers(); i++)
    {
        
g_Limit[i][0] = 0

        
if(RoundCounter == get_pcvar_num(pCvarRounds))
        {
            
g_Limit[i][1] = 0
            RoundCounter 
0;
        }
    }
}

public 
showmenu(id)
{
    new 
menu menu_create("Free Weapon""Pressedrod");
    
menu_additemmenu"Deagle [ Every 1 rounds once ]""0");
    
menu_additemmenu"AK47 [ Every 5 rounds once ]""1");
    
menu_setpropmenuMPROP_EXITMEXIT_ALL );   
     
    
menu_displayidmenu);  
     
    return 
PLUGIN_HANDLED;
}

public 
Pressedrod(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);
    
    if(!
is_user_alive(id))
        return 
PLUGIN_HANDLED
        
    
switch(key
    {
        case 
0
        {
            if(
g_Limit[id][0] >= 1)
            {
                
client_print(idprint_chat"Limit reached for this round.")
                return 
PLUGIN_HANDLED
            
}
            
strip_user_weapons (id)
            
give_item(id,"weapon_deagle")
            
cs_set_user_bpammo(idCSW_DEAGLE30)
            
give_item(id,"weapon_knife")
            
g_Limit[id][0]++   
        }
        
        case 
1
        {
            if(
g_Limit[id][1] >= 1)
            {
                
client_print(idprint_chat"You must wait %i more rounds."get_pcvar_num(pCvarRounds) - RoundCounter)
                return 
PLUGIN_HANDLED
            
}
            
strip_user_weapons(id)
            
give_item(id"weapon_ak47")
            
cs_set_user_bpammo(idCSW_AK4790)
            
give_item(id,"weapon_knife"
            
g_Limit[id][1]++
        }
    }
    return 
PLUGIN_CONTINUE

I tested but it didn't work

Can't anyone else help?
alferd is offline
Fuck For Fun
Veteran Member
Join Date: Nov 2013
Old 04-21-2020 , 13:13   Re: [REQ] Case every 5 rounds
Reply With Quote #5

Quote:
Originally Posted by alferd View Post
I tested but it didn't work

Can't anyone else help?
What exactly doesn't work?
Fuck For Fun is offline
Send a message via Skype™ to Fuck For Fun
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-21-2020 , 19:25   Re: [REQ] Case every 5 rounds
Reply With Quote #6

PHP Code:

#include <amxmodx>
#include <cstrike>
#include <fun>

new const Version[] = "0.1";

new 
g_RoundCountMAX_PLAYERS ];
new 
g_BoughtDeagle g_BoughtAK47;
new 
g_pResetRounds;

public 
plugin_init() 
{
    
register_plugin"Free Weapons" Version "bugsy" );
    
    
register_concmd"say /freewpn" "ShowMenu" );
    
    
register_event"HLTV" "NewRound" "a" "1=0" "2=0" );
    
    
g_pResetRounds register_cvar"freeweapon_rounds" "5" );
}

public 
client_connectid )
{
    
g_RoundCountid ] = 0;
    
g_BoughtDeagle &= ~( << ( id 31 ) );
    
g_BoughtAK47 &= ~( << ( id 31 ) );
}

public 
NewRound()
{
    new 
iPlayers32 ] , iNum iPlayer;
    new 
iResetRounds get_pcvar_numg_pResetRounds );
    
    
g_BoughtDeagle 0;
    
    
get_playersiPlayers iNum "ch" );
    
    for ( new 
iNum i++ )
    {
        
iPlayer iPlayers];
        
        
g_RoundCountiPlayer ]++;
        
        if ( !( 
g_RoundCountiPlayer ] % iResetRounds ) )
            
g_BoughtAK47 &= ~( << ( iPlayer 31 ) );
    }
}

public 
ShowMenuid )
{
    new 
iMenu menu_create"Free Weapon" "MenuHandler" );  
    new 
iCallBack menu_makecallback"MenuCallBack" );
    new 
szAKMenu40 ] , szRoundsLeft10 ];
    new 
iResetRounds get_pcvar_numg_pResetRounds );
    
    if ( 
g_BoughtAK47 & ( << ( id 31 ) ) )
        
formatexszRoundsLeft charsmaxszRoundsLeft ) , " - %d left" iResetRounds - ( g_RoundCountid ] % iResetRounds ) );
        
    
formatexszAKMenu charsmaxszAKMenu ) , "AK47 [ 1 every %d round%s ]%s" iResetRounds , ( iResetRounds == ) ? "" "s" szRoundsLeft );
    
menu_additemiMenu "Deagle [ 1 every round ]" , .callback iCallBack );
    
menu_additemiMenu szAKMenu , .callback iCallBack );
    
menu_setpropiMenuMPROP_EXITMEXIT_ALL ); 
    
    
menu_displayid iMenu ); 
    
    return 
PLUGIN_HANDLED;
}

public 
MenuCallBackid iMenu iItem )
{    
    new 
iRetVal;
    
    switch ( 
iItem )
    {
        case 
0iRetVal = ( user_has_weaponid CSW_DEAGLE ) || ( g_BoughtDeagle & ( << ( id 31 ) ) ) ) ? ITEM_DISABLED ITEM_ENABLED
        case 
1iRetVal = ( user_has_weaponid CSW_AK47 ) || ( g_BoughtAK47 & ( << ( id 31 ) ) ) ) ? ITEM_DISABLED ITEM_ENABLED
    }    
    
    return 
iRetVal;
}

public 
MenuHandlerid menu item )
{
    if ( 
item == MENU_EXIT 
    { 
        
menu_destroymenu );
        return 
PLUGIN_HANDLED
    } 
    
    if ( !
is_user_aliveid ) )
        return 
PLUGIN_HANDLED;
    
    
strip_user_weaponsid );
    
give_itemid "weapon_knife" );

    switch( 
item 
    {
        case 
0
        {
            
give_itemid "weapon_deagle" );
            
cs_set_user_bpammoid CSW_DEAGLE 30 );
            
            
g_BoughtDeagle |= ( << ( id 31 ) );
        }
        case 
1
        {
            
give_itemid "weapon_ak47" );
            
cs_set_user_bpammoid CSW_AK47 90 );
            
            
g_BoughtAK47 |= ( << ( id 31 ) );
        }
    }
    
    return 
PLUGIN_CONTINUE;

__________________

Last edited by Bugsy; 04-22-2020 at 23:53.
Bugsy is offline
alferd
Veteran Member
Join Date: Dec 2019
Location: Iran is Always Eternal
Old 05-09-2020 , 03:24   Re: [REQ] Case every 5 rounds
Reply With Quote #7

Quote:
Originally Posted by Bugsy View Post
PHP Code:

#include <amxmodx>
#include <cstrike>
#include <fun>

new const Version[] = "0.1";

new 
g_RoundCountMAX_PLAYERS ];
new 
g_BoughtDeagle g_BoughtAK47;
new 
g_pResetRounds;

public 
plugin_init() 
{
    
register_plugin"Free Weapons" Version "bugsy" );
    
    
register_concmd"say /freewpn" "ShowMenu" );
    
    
register_event"HLTV" "NewRound" "a" "1=0" "2=0" );
    
    
g_pResetRounds register_cvar"freeweapon_rounds" "5" );
}

public 
client_connectid )
{
    
g_RoundCountid ] = 0;
    
g_BoughtDeagle &= ~( << ( id 31 ) );
    
g_BoughtAK47 &= ~( << ( id 31 ) );
}

public 
NewRound()
{
    new 
iPlayers32 ] , iNum iPlayer;
    new 
iResetRounds get_pcvar_numg_pResetRounds );
    
    
g_BoughtDeagle 0;
    
    
get_playersiPlayers iNum "ch" );
    
    for ( new 
iNum i++ )
    {
        
iPlayer iPlayers];
        
        
g_RoundCountiPlayer ]++;
        
        if ( !( 
g_RoundCountiPlayer ] % iResetRounds ) )
            
g_BoughtAK47 &= ~( << ( iPlayer 31 ) );
    }
}

public 
ShowMenuid )
{
    new 
iMenu menu_create"Free Weapon" "MenuHandler" );  
    new 
iCallBack menu_makecallback"MenuCallBack" );
    new 
szAKMenu40 ] , szRoundsLeft10 ];
    new 
iResetRounds get_pcvar_numg_pResetRounds );
    
    if ( 
g_BoughtAK47 & ( << ( id 31 ) ) )
        
formatexszRoundsLeft charsmaxszRoundsLeft ) , " - %d left" iResetRounds - ( g_RoundCountid ] % iResetRounds ) );
        
    
formatexszAKMenu charsmaxszAKMenu ) , "AK47 [ 1 every %d round%s ]%s" iResetRounds , ( iResetRounds == ) ? "" "s" szRoundsLeft );
    
menu_additemiMenu "Deagle [ 1 every round ]" , .callback iCallBack );
    
menu_additemiMenu szAKMenu , .callback iCallBack );
    
menu_setpropiMenuMPROP_EXITMEXIT_ALL ); 
    
    
menu_displayid iMenu ); 
    
    return 
PLUGIN_HANDLED;
}

public 
MenuCallBackid iMenu iItem )
{    
    new 
iRetVal;
    
    switch ( 
iItem )
    {
        case 
0iRetVal = ( user_has_weaponid CSW_DEAGLE ) || ( g_BoughtDeagle & ( << ( id 31 ) ) ) ) ? ITEM_DISABLED ITEM_ENABLED
        case 
1iRetVal = ( user_has_weaponid CSW_AK47 ) || ( g_BoughtAK47 & ( << ( id 31 ) ) ) ) ? ITEM_DISABLED ITEM_ENABLED
    }    
    
    return 
iRetVal;
}

public 
MenuHandlerid menu item )
{
    if ( 
item == MENU_EXIT 
    { 
        
menu_destroymenu );
        return 
PLUGIN_HANDLED
    } 
    
    if ( !
is_user_aliveid ) )
        return 
PLUGIN_HANDLED;
    
    
strip_user_weaponsid );
    
give_itemid "weapon_knife" );

    switch( 
item 
    {
        case 
0
        {
            
give_itemid "weapon_deagle" );
            
cs_set_user_bpammoid CSW_DEAGLE 30 );
            
            
g_BoughtDeagle |= ( << ( id 31 ) );
        }
        case 
1
        {
            
give_itemid "weapon_ak47" );
            
cs_set_user_bpammoid CSW_AK47 90 );
            
            
g_BoughtAK47 |= ( << ( id 31 ) );
        }
    }
    
    return 
PLUGIN_CONTINUE;

PHP Code:
#define MAX_PLAYERS 32 

Last edited by alferd; 05-09-2020 at 03:25.
alferd is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 05-09-2020 , 14:53   Re: [REQ] Case every 5 rounds
Reply With Quote #8

Code:
#if !defined MAX_PLAYERS const MAX_PLAYERS = 32 #endif
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-09-2020 , 15:47   Re: [REQ] Case every 5 rounds
Reply With Quote #9

Using#define is easier/cleaner IMO, no need for conditional pre-processor directives. Yeah, it may consume a few more bytes of memory versus having a variable store the value using const, but it's negligible.
__________________

Last edited by Bugsy; 05-09-2020 at 15:53.
Bugsy is offline
alferd
Veteran Member
Join Date: Dec 2019
Location: Iran is Always Eternal
Old 05-10-2020 , 03:06   Re: [REQ] Case every 5 rounds
Reply With Quote #10

Quote:
Originally Posted by alferd View Post
PHP Code:
#define MAX_PLAYERS 32 

Quote:
Originally Posted by OciXCrom View Post
Code:
#if !defined MAX_PLAYERS const MAX_PLAYERS = 32 #endif

What is the difference between these two commands?
alferd 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 12:06.


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