Raised This Month: $ Target: $400
 0% 

help | in menus


Post New Thread Reply   
 
Thread Tools Display Modes
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 08-09-2012 , 13:56   Re: help | in menus
Reply With Quote #11

Quote:
Originally Posted by Swisa View Post
I do not understand you can give me an example?
thnx
Just to make sure....users that are counter-terrorists are not allowed to buy weapons or ammo, correct?
__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz is offline
Swisa
Senior Member
Join Date: Nov 2010
Location: Israel
Old 08-09-2012 , 14:12   Re: help | in menus
Reply With Quote #12

If I want him to see it but can not click on it?
Swisa is offline
Send a message via Skype™ to Swisa
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 08-09-2012 , 14:32   Re: help | in menus
Reply With Quote #13

Yup....here you go. This is your function as the callback. Read the tut to figure out how to integrate it into the menu.

PHP Code:
public mhcb_ShopMenu(idmenuitem)
{
    new 
data[8], name[32]
    static 
acscbCsTeams:team 
    
    team 
cs_get_user_team(id)
    
    
menu_item_getinfo(menuitemacsdatacharsmax(data), namecharsmax(name), cb)
    
    
// because cb is useless....why not put it to work?
    
cb str_to_num(data)
    
    if(
cb == || cb == 4)
        return (
team == CS_TEAM_T) ? ITEM_ENABLED ITEM_DISABLED
        
    
return ITEM_ENABLED

Your menu is going to look just like your CT menu. Just without checking if they are CT. The callback does that for you.
__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz is offline
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 08-09-2012 , 15:09   Re: help | in menus
Reply With Quote #14

@Liverwiz: There is no need to check the item/data numbers because you should only add the callback to the items you want checked.

Additionally, you shouldn't use static variables in this situation and some of your variable naming makes me cry.
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 08-09-2012 , 16:16   Re: help | in menus
Reply With Quote #15

Quote:
Originally Posted by Emp` View Post
@Liverwiz: There is no need to check the item/data numbers because you should only add the callback to the items you want checked.

Additionally, you shouldn't use static variables in this situation and some of your variable naming makes me cry.
I never thought of putting it to only things that need it.... -_- *learn by mistake*
Out of curiosity....why no statics? They all get overwritten anyway, dont they?
Tears of joy i hope...
acs = access
cb = call back
They make sense to me, and because they're never really used, i've found no reason to have them make sense.
__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-09-2012 , 16:26   Re: help | in menus
Reply With Quote #16

Quote:
Originally Posted by Liverwiz View Post
Out of curiosity....why no statics? They all get overwritten anyway, dont they?
Statics are used when a section of code is called very often, such as PreThink, and you are using a lot of memory with variables, such as arrays, or maybe just a lot of single-cell variables.
You used statics backwards by making the 1-cell variables static and the array variables non-static.
Menu callbacks will not be called often since menus aren't called that often.
Therefore, "new" is perfect here.

Quote:
Originally Posted by Liverwiz View Post
They make sense to me, [...] i've found no reason to have them make sense.
What? That statement makes no sense.
The variables make sense to you, but since they are barely used, you decided to have them not make sense.
So does that mean you have no sense?
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Swisa
Senior Member
Join Date: Nov 2010
Location: Israel
Old 08-09-2012 , 17:28   Re: help | in menus
Reply With Quote #17

Okay thanks, I arranged the matter now I have another problem.
In shop ...
I put it to the server is down what Block Maker the cube of the NOFALLDAMAGE.
I know because of what it is, I put in a shop you can buy NOFALLDAMAGE and it makes the problem.
Swisa is offline
Send a message via Skype™ to Swisa
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 08-09-2012 , 17:31   Re: help | in menus
Reply With Quote #18

Quote:
Originally Posted by Exolent[jNr] View Post
Statics are used when a section of code is called very often, such as PreThink, and you are using a lot of memory with variables, such as arrays, or maybe just a lot of single-cell variables.
You used statics backwards by making the 1-cell variables static and the array variables non-static.
Menu callbacks will not be called often since menus aren't called that often.
Therefore, "new" is perfect here.



What? That statement makes no sense.
The variables make sense to you, but since they are barely used, you decided to have them not make sense.
So does that mean you have no sense?
first part....fair enough. But does it effect anything? Or some people just don't like it?

As for the no sense nonsense. I'm just nonsensical. But i get the job done. (o:


Quote:
Originally Posted by Swisa View Post
Okay thanks, I arranged the matter now I have another problem.
In shop ...
I put it to the server is down what Block Maker the cube of the NOFALLDAMAGE.
I know because of what it is, I put in a shop you can buy NOFALLDAMAGE and it makes the problem.
what?
__________________
What an elegant solution to a problem that doesn't need solving....

Last edited by Liverwiz; 08-09-2012 at 18:25. Reason: fixed my face
Liverwiz is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-09-2012 , 17:40   Re: help | in menus
Reply With Quote #19

Quote:
Originally Posted by Liverwiz View Post
first part....fair enough. But does it effect anything? Or some people just don't like it?
If affects performance when a block of code is called frequently with a lot of memory being allocated.
In this situation, it is actually worse to make those static since you are taking up that memory space for as long as the plugin is running which is unnecessary since the frequency of the function doesn't require statics.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 08-09-2012 , 17:56   Re: help | in menus
Reply With Quote #20

Quote:
Originally Posted by Exolent[jNr] View Post
If affects performance when a block of code is called frequently with a lot of memory being allocated.
In this situation, it is actually worse to make those static since you are taking up that memory space for as long as the plugin is running which is unnecessary since the frequency of the function doesn't require statics.
Oh! Ok.


EDIT: while we're on the subject of menus and saving memory. Which is better? Making a menu once by calling a function from plugin_init and storing it globally in memory. Or creating it every time its called? Necessity of context aside. My view is that CPU is more precious than memory (especially when HL1 servers are concerned) and that it'd be better to just create a menu globally and calling it when needed.
__________________
What an elegant solution to a problem that doesn't need solving....

Last edited by Liverwiz; 08-09-2012 at 18:23.
Liverwiz 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 05:45.


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