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

Limit for buying weapon


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
leonardo_
Member
Join Date: Nov 2012
Location: Moscow, right now in Vic
Old 02-09-2013 , 01:54   Limit for buying weapon
Reply With Quote #1

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

#include <amxmodx>
#include <amxmisc>
#include <fun>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "Alexander"


public plugin_init() {
    
register_plugin("Weapon Menu""0.1""Alex");
    
register_clcmd"say /menu","AwesomeMenu");
}


 public 
AwesomeMenu(id)
 {
    
//first we need to make a variable that will hold the menu
    
new menu menu_create("\rChoose your gun!:""menu_handler");
    
//Note - menu_create
    //The first parameter  is what the menu will be titled (what is at the very top)
    //The second parameter is the function that will deal/handle with the menu (which key was pressed, and what to do)

    //Now lets add some things to select from the menu
    
menu_additem(menu"\wGet Deagle""1"ADMIN_LEVEL_G);
    
//menu_additem(menu, "\wI'm Selection #2", "2", 0);
    //menu_additem(menu, "\wI'm Secret Selection #3", "3", ADMIN_LEVEL_G);
    //Note - menu_additem
    //The first parameter is which menu we will be adding this item/selection to
    //The second parameter is what text will appear on the menu (Note that it is preceeded with a number of which item it is)
    //The third parameter is data that we want to send with this item
    //The fourth parameter is which admin flag we want to be able to access this item (Refer to the admin flags from the amxconst.inc)
    //The fifth parameter is the callback for enabling/disabling items, by default we will omit this and use no callback (default value of -1) Refer to the Menu Items with Callbacks section for more information.

    //Set a property on the menu
    
menu_setprop(menuMPROP_EXITMEXIT_ALL);
    
//Note - menu_setprop
    //The first parameter is the menu to modify
    //The second parameter is what to modify (found in amxconst.inc)
    //The third parameter is what to modify it to (in this case, we are adding a option to the menu that will exit the menu. setting it to MEXIT_NEVER will disable this option)

    //Lets display the menu
    
menu_display(idmenu0);
    
//Note - menu_display
    //The first parameter is which index to show it to (you cannot show this to everyone at once)
    //The second parameter is which menu to show them (in this case, the one we just made)
    //The third parameter is which page to start them on
 
}
 
//okay, we showed them the menu, now lets handle it (looking back at menu_create, we are going to use that function)
 
public menu_handler(idmenuitem)
 {
    
//we don't want to deal with them if they exited a menu
    
if( item == MENU_EXIT )
    {
        
menu_destroy(menu);
        
//Note that you will want to destroy the menu after they do something
        
return PLUGIN_HANDLED;
    }

    
//now lets create some variables that will give us information about the menu and the item that was pressed/chosen
    
new data[6], szName[64];
    new 
accesscallback;
    
//heres the function that will give us that information (since it doesnt magicaly appear)
    
menu_item_getinfo(menuitemaccessdata,charsmax(data), szName,charsmax(szName), callback);

    
//Note - that you can do this next step how you want, this is just the way I prefer

    //looking back to menu_additem, we sent data with every item we added, this is where it gets a little fishy for us (where you can do your own method)
    
new key str_to_num(data);
    
//note that all my datas were numbers (you can do it with whatever type of string you want)

    //now lets find which item was pressed
    
switch(key)
    {
        case 
1:
        {
    
    
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")
            
client_print(idprint_chat"You got a nice deagle for yourself!");
            
//note that if we dont want to continue through the function, we can't just end with a return. We want to kill the menu first
            
menu_destroy(menu);
            return 
PLUGIN_HANDLED;
        }
        case 
2:
        {
            
client_print(idprint_chat"OH NO! You selected the Awesome 2nd Selection! BEWARE!");
        }
        case 
3//again i don't have experience with the admin limitations, so i don't know if you need to have a check before this (im assuming you don't though ^_^)
        
{
            
client_print(idprint_chat"You have selected the Awesome Admin Selection! Hail Teh Bail!");
        }
    }

    
//lets finish up this function with a menu_destroy, and a return
    
menu_destroy(menu);
    return 
PLUGIN_HANDLED;
 } 
This is the code that I used from here - https://forums.alliedmods.net/showthread.php?t=46364

And I changed it a little bit to my version... I have a command like when you type "/menu" in chat you have a menu that gives you permission to get free deagle... I want it to make it like that: you can buy deagle only once per round and after you got a deagle you cannot use menu anymore...

and when for example here:
PHP Code:
menu_additem(menu"\wGet Deagle""1"ADMIN_LEVEL_G); 
player with flag G only can reach that option, can you help me to make it like when player that doesn't have that flag trying to choose it - chat_print start working and says "you do not have permission to use that option".

How can I do that?
Please describe more about it, because I am only a beginner and don't really know much about programming

Can you help me to make please?

Last edited by leonardo_; 02-09-2013 at 02:00.
leonardo_ is offline
Send a message via ICQ to leonardo_ Send a message via Skype™ to leonardo_
Unkolix
Veteran Member
Join Date: Sep 2012
Old 02-09-2013 , 02:00   Re: Limit for buying weapon
Reply With Quote #2

Check this one:
PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <fun>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "Alexander"
#define MAXPLAYERS 32 + 1

new bool:gbUsed[MAXPLAYERS]; //Made gbUsed as if player has used

public plugin_init() 
{
    
register_plugin("Weapon Menu""0.1""Alex");
    
register_clcmd"say /menu","AwesomeMenu");
    
register_logevent"eventRoundEnd"2"1=Round_End" //Registered round end event, so I could make gbUsed to false
}

public 
eventRoundEnd() //That's the event
{
    
arraysetgbUsedfalseMAXPLAYERS //On round end made gbUsed to false so player on new round can get the menu
}

public 
client_disconnect(id//Checks if player disconnects
{
    
gbUsed[id] = false//If he disconnects gbUsed is set to false, so when he connects he can use the menu again
}

public 
AwesomeMenu(id)
{
    if(!
gbUsed[id]) //Checks if gbUsed is false, so it lets use the menu, if gbUsed is true stops players getting the menu
    
{
        
//first we need to make a variable that will hold the menu
        
new menu menu_create("\rChoose your gun!:""menu_handler");
        
//Note - menu_create
        //The first parameter  is what the menu will be titled (what is at the very top)
        //The second parameter is the function that will deal/handle with the menu (which key was pressed, and what to do)
        
        //Now lets add some things to select from the menu
        
menu_additem(menu"\wGet Deagle""1"ADMIN_LEVEL_G);
        
//menu_additem(menu, "\wI'm Selection #2", "2", 0);
        //menu_additem(menu, "\wI'm Secret Selection #3", "3", ADMIN_LEVEL_G);
        //Note - menu_additem
        //The first parameter is which menu we will be adding this item/selection to
        //The second parameter is what text will appear on the menu (Note that it is preceeded with a number of which item it is)
        //The third parameter is data that we want to send with this item
        //The fourth parameter is which admin flag we want to be able to access this item (Refer to the admin flags from the amxconst.inc)
        //The fifth parameter is the callback for enabling/disabling items, by default we will omit this and use no callback (default value of -1) Refer to the Menu Items with Callbacks section for more information.
        
        //Set a property on the menu
        
menu_setprop(menuMPROP_EXITMEXIT_ALL);
        
//Note - menu_setprop
        //The first parameter is the menu to modify
        //The second parameter is what to modify (found in amxconst.inc)
        //The third parameter is what to modify it to (in this case, we are adding a option to the menu that will exit the menu. setting it to MEXIT_NEVER will disable this option)
        
        //Lets display the menu
        
menu_display(idmenu0);
        
//Note - menu_display
        //The first parameter is which index to show it to (you cannot show this to everyone at once)
        //The second parameter is which menu to show them (in this case, the one we just made)
        //The third parameter is which page to start them on
    
}
}
//okay, we showed them the menu, now lets handle it (looking back at menu_create, we are going to use that function)
public menu_handler(idmenuitem)
{
    
//we don't want to deal with them if they exited a menu
    
if( item == MENU_EXIT )
    {
        
menu_destroy(menu);
        
//Note that you will want to destroy the menu after they do something
        
return PLUGIN_HANDLED;
    }
    
    
//now lets create some variables that will give us information about the menu and the item that was pressed/chosen
    
new data[6], szName[64];
    new 
accesscallback;
    
//heres the function that will give us that information (since it doesnt magicaly appear)
    
menu_item_getinfo(menuitemaccessdata,charsmax(data), szName,charsmax(szName), callback);
    
    
//Note - that you can do this next step how you want, this is just the way I prefer
    
    //looking back to menu_additem, we sent data with every item we added, this is where it gets a little fishy for us (where you can do your own method)
    
new key str_to_num(data);
    
//note that all my datas were numbers (you can do it with whatever type of string you want)
    
    //now lets find which item was pressed
    
switch(key)
    {
        case 
1:
        {
            
            
give_item(id"weapon_deagle"//Give deagle
            
give_item(id,"ammo_50ae"//Gives ammo
            
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")
            
client_print(idprint_chat"You got a nice deagle for yourself!");
            
gbUsed[id] = true//Set gbUsed to true becouse player has got the deagle, so he can't get another one in this round
            //note that if we dont want to continue through the function, we can't just end with a return. We want to kill the menu first
            
menu_destroy(menu);
            return 
PLUGIN_HANDLED;
        }
        case 
2:
        {
            
client_print(idprint_chat"OH NO! You selected the Awesome 2nd Selection! BEWARE!");
        }
        case 
3//again i don't have experience with the admin limitations, so i don't know if you need to have a check before this (im assuming you don't though ^_^)
        
{
            
client_print(idprint_chat"You have selected the Awesome Admin Selection! Hail Teh Bail!");
        }
    }
    
    
//lets finish up this function with a menu_destroy, and a return
    
menu_destroy(menu);
    return 
PLUGIN_HANDLED;


Last edited by Unkolix; 02-09-2013 at 02:15.
Unkolix is offline
leonardo_
Member
Join Date: Nov 2012
Location: Moscow, right now in Vic
Old 02-09-2013 , 02:05   Re: Limit for buying weapon
Reply With Quote #3

Quote:
Originally Posted by Unkolix View Post
Check this one:
PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <fun>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "Alexander"
#define MAXPLAYERS 32 + 1

new bool:gbUsed[MAXPLAYERS];

public 
plugin_init() 
{
    
register_plugin("Weapon Menu""0.1""Alex");
    
register_clcmd"say /menu","AwesomeMenu");
    
register_logevent"eventRoundEnd"2"1=Round_End" )
}

public 
eventRoundEnd()
{
    
arraysetgbUsedfalseMAXPLAYERS )
}

public 
client_disconnect(id)
{
    
gbUsed[id] = false;
}

public 
AwesomeMenu(id)
{
    if(!
gbUsed[id])
    {
        
//first we need to make a variable that will hold the menu
        
new menu menu_create("\rChoose your gun!:""menu_handler");
        
//Note - menu_create
        //The first parameter  is what the menu will be titled (what is at the very top)
        //The second parameter is the function that will deal/handle with the menu (which key was pressed, and what to do)
        
        //Now lets add some things to select from the menu
        
menu_additem(menu"\wGet Deagle""1"ADMIN_LEVEL_G);
        
//menu_additem(menu, "\wI'm Selection #2", "2", 0);
        //menu_additem(menu, "\wI'm Secret Selection #3", "3", ADMIN_LEVEL_G);
        //Note - menu_additem
        //The first parameter is which menu we will be adding this item/selection to
        //The second parameter is what text will appear on the menu (Note that it is preceeded with a number of which item it is)
        //The third parameter is data that we want to send with this item
        //The fourth parameter is which admin flag we want to be able to access this item (Refer to the admin flags from the amxconst.inc)
        //The fifth parameter is the callback for enabling/disabling items, by default we will omit this and use no callback (default value of -1) Refer to the Menu Items with Callbacks section for more information.
        
        //Set a property on the menu
        
menu_setprop(menuMPROP_EXITMEXIT_ALL);
        
//Note - menu_setprop
        //The first parameter is the menu to modify
        //The second parameter is what to modify (found in amxconst.inc)
        //The third parameter is what to modify it to (in this case, we are adding a option to the menu that will exit the menu. setting it to MEXIT_NEVER will disable this option)
        
        //Lets display the menu
        
menu_display(idmenu0);
        
//Note - menu_display
        //The first parameter is which index to show it to (you cannot show this to everyone at once)
        //The second parameter is which menu to show them (in this case, the one we just made)
        //The third parameter is which page to start them on
    
}
}
//okay, we showed them the menu, now lets handle it (looking back at menu_create, we are going to use that function)
public menu_handler(idmenuitem)
{
    
//we don't want to deal with them if they exited a menu
    
if( item == MENU_EXIT )
    {
        
menu_destroy(menu);
        
//Note that you will want to destroy the menu after they do something
        
return PLUGIN_HANDLED;
    }
    
    
//now lets create some variables that will give us information about the menu and the item that was pressed/chosen
    
new data[6], szName[64];
    new 
accesscallback;
    
//heres the function that will give us that information (since it doesnt magicaly appear)
    
menu_item_getinfo(menuitemaccessdata,charsmax(data), szName,charsmax(szName), callback);
    
    
//Note - that you can do this next step how you want, this is just the way I prefer
    
    //looking back to menu_additem, we sent data with every item we added, this is where it gets a little fishy for us (where you can do your own method)
    
new key str_to_num(data);
    
//note that all my datas were numbers (you can do it with whatever type of string you want)
    
    //now lets find which item was pressed
    
switch(key)
    {
        case 
1:
        {
            
            
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")
            
client_print(idprint_chat"You got a nice deagle for yourself!");
            
gbUsed[id] = true;
            
//note that if we dont want to continue through the function, we can't just end with a return. We want to kill the menu first
            
menu_destroy(menu);
            return 
PLUGIN_HANDLED;
        }
        case 
2:
        {
            
client_print(idprint_chat"OH NO! You selected the Awesome 2nd Selection! BEWARE!");
        }
        case 
3//again i don't have experience with the admin limitations, so i don't know if you need to have a check before this (im assuming you don't though ^_^)
        
{
            
client_print(idprint_chat"You have selected the Awesome Admin Selection! Hail Teh Bail!");
        }
    }
    
    
//lets finish up this function with a menu_destroy, and a return
    
menu_destroy(menu);
    return 
PLUGIN_HANDLED;

Sorry for asking so many questions, but can u tell me what you exactly changed? Please?

And yes, it worked!

I got to go to bed, too tired right now... Tomorrow I'll check your answers! Thank you so much!

and that problem was not solved:
Quote:
player with flag G only can reach that option, can you help me to make it like when player that doesn't have that flag trying to choose it - chat_print start working and says "you do not have permission to use that option".

Last edited by leonardo_; 02-09-2013 at 02:08.
leonardo_ is offline
Send a message via ICQ to leonardo_ Send a message via Skype™ to leonardo_
Unkolix
Veteran Member
Join Date: Sep 2012
Old 02-09-2013 , 02:15   Re: Limit for buying weapon
Reply With Quote #4

I commented the lines in my post above.
Unkolix is offline
LudaGe
Senior Member
Join Date: May 2010
Location: World so cold
Old 02-09-2013 , 03:20   Re: Limit for buying weapon
Reply With Quote #5

if you adds the another 2 options of menu ("Selection" and "Secret Selection")
it should be...
PHP Code:
switch(key)
    {
        case 
1:
        {
         
//blahblah deagle selection
        
}
        case 
2:
        {
            
//blahblah 2nd selection
        
}
        case 
3:
        {
            
//blahblah 3rd selection
        
}
        
gbUsed[id] = true;
    } 
LudaGe is offline
Unkolix
Veteran Member
Join Date: Sep 2012
Old 02-09-2013 , 03:39   Re: Limit for buying weapon
Reply With Quote #6

Quote:
Originally Posted by LudaGe View Post
if you adds the another 2 options of menu ("Selection" and "Secret Selection")
it should be...
PHP Code:
switch(key)
    {
        case 
1:
        {
         
//blahblah deagle selection
        
}
        case 
2:
        {
            
//blahblah 2nd selection
        
}
        case 
3:
        {
            
//blahblah 3rd selection
        
}
        
gbUsed[id] = true;
    } 
This is correct if you want to block player getting the menu only if he used case one (chose deagle) and if he chose case 2 or 3, he can use the menu more then once until he chose case 1.
Unkolix is offline
LudaGe
Senior Member
Join Date: May 2010
Location: World so cold
Old 02-09-2013 , 04:11   Re: Limit for buying weapon
Reply With Quote #7

Quote:
Originally Posted by Unkolix View Post
This is correct if you want to block player getting the menu only if he used case one (chose deagle) and if he chose case 2 or 3, he can use the menu more then once until he chose case 1.
yes sorry, I thought that the deagle was an example...
but if he want add another weapon can use it..
LudaGe is offline
leonardo_
Member
Join Date: Nov 2012
Location: Moscow, right now in Vic
Old 02-09-2013 , 14:41   Re: Limit for buying weapon
Reply With Quote #8

Quote:
Originally Posted by Unkolix View Post
This is correct if you want to block player getting the menu only if he used case one (chose deagle) and if he chose case 2 or 3, he can use the menu more then once until he chose case 1.

ok, I also wanted to ask you about rounds... How can I check if there first round of second one. For exaple:

I want to write menu that gives you he, smoke, flash grenades automatically at the beginning of the first round, and after 2-nd round shows you a menu like:

Quote:
1. Get M4A1
2. Get AK47
Can you show me that please?

Or better be like that: How can I count how round and make for example: in 5th round menu for a player...

I think I need to use for(), CurrentRound and that kind of stuff but I don't know how... Please teach me someone....

and please don't show me full code, just give an idea of how to do that! Thank you!

Last edited by leonardo_; 02-09-2013 at 14:46.
leonardo_ is offline
Send a message via ICQ to leonardo_ Send a message via Skype™ to leonardo_
wickedd
Veteran Member
Join Date: Nov 2009
Old 02-09-2013 , 14:48   Re: Limit for buying weapon
Reply With Quote #9

Quote:
player with flag G only can reach that option, can you help me to make it like when player that doesn't have that flag trying to choose it - chat_print start working and says "you do not have permission to use that option".
PHP Code:
switch( key )
    {
        case 
1:
        {
            if( 
get_user_flagsid ) & ADMIN_KICK )
            {
                
give_itemid"weapon_deagle" )
                
client_printidprint_chat"You got a Deagle" 
            }
           else
            {
                
client_printidprint_chat"Only Admins can receive a free Deagle" )
            }
        } 
__________________
Just buy the fucking game!!!!
I hate No-Steamers and lazy ass people.
wickedd is offline
Unkolix
Veteran Member
Join Date: Sep 2012
Old 02-09-2013 , 14:52   Re: Limit for buying weapon
Reply With Quote #10

PHP Code:
new CurrentRound
<...>
//in plugin init
register_logevent("LogEvent_RoundStart"2"1=Round_Start" )
<...>
public 
LogEvent_RoundStart(id)
{
    
CurrentRound++;

Then when you want to check
PHP Code:
if(CurrentRound == 1)
{
    
//your code goes here

You can replace the "==" with >=, <=, >, <

And if you want to check if round isn't for example first
PHP Code:
if(CurrentRound != 1)
{
    
//your code goes here


Last edited by Unkolix; 02-09-2013 at 15:47.
Unkolix 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 13:52.


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